@@ -26,6 +26,11 @@ class VLLMContext(threading.local):
2626 by `set_vllm_context` at the start of every forward step.
2727 num_kv_heads: The model's true KV head count (from the model config),
2828 used by the bridge to undo GQA head expansion generically.
29+ per_layer_sliding: Optional per-layer sliding-window sizes, aligned
30+ with `kv_caches` order. Sliding windows can't be expressed
31+ through the attention op's arguments (its mask only covers the
32+ new tokens, not the paged history), so the adapter probes them
33+ once at load time and the bridge applies them by layer index.
2934 active: Boolean indicating if the context is currently active.
3035 """
3136
@@ -42,6 +47,7 @@ def __init__(self) -> None:
4247 self .updated_kv_caches : Optional [list ] = None
4348 self .layer_index : int = 0
4449 self .num_kv_heads : Optional [int ] = None
50+ self .per_layer_sliding : Optional [list ] = None
4551 self .active : bool = False
4652
4753
@@ -57,6 +63,7 @@ def set_vllm_context(
5763 positions : Optional [Any ] = None ,
5864 kv_caches : Optional [list ] = None ,
5965 num_kv_heads : Optional [int ] = None ,
66+ per_layer_sliding : Optional [list ] = None ,
6067) -> None :
6168 """Sets the thread-local vLLM context parameters.
6269
@@ -72,6 +79,7 @@ def set_vllm_context(
7279 kv_caches: Per-layer paged KV caches, in transformer-layer order.
7380 num_kv_heads: The model's true KV head count, for generic GQA
7481 un-expansion in the bridge.
82+ per_layer_sliding: Per-layer sliding-window sizes, in layer order.
7583 """
7684 _vllm_context .block_tables = block_tables
7785 _vllm_context .slot_mapping = slot_mapping
@@ -85,6 +93,7 @@ def set_vllm_context(
8593 )
8694 _vllm_context .layer_index = 0
8795 _vllm_context .num_kv_heads = num_kv_heads
96+ _vllm_context .per_layer_sliding = per_layer_sliding
8897 _vllm_context .active = True
8998
9099
@@ -100,6 +109,7 @@ def clear_vllm_context() -> None:
100109 _vllm_context .updated_kv_caches = None
101110 _vllm_context .layer_index = 0
102111 _vllm_context .num_kv_heads = None
112+ _vllm_context .per_layer_sliding = None
103113 _vllm_context .active = False
104114
105115
0 commit comments