@@ -94,7 +94,6 @@ def _make_kv_cache_inputs(
9494 prefix : str = "past_key_values" ,
9595 key_head_dim : int | None = None ,
9696 value_head_dim : int | None = None ,
97- cache_specs : list [tuple [int , int , int ]] | None = None ,
9897) -> list [tuple [ir .Value , ir .Value ]]:
9998 """Create KV cache input values for ``num_layers`` layers.
10099
@@ -106,31 +105,23 @@ def _make_kv_cache_inputs(
106105 For MLA attention, this is ``qk_nope_head_dim + qk_rope_head_dim``.
107106 value_head_dim: Head dim for values. Defaults to ``head_dim``.
108107 For MLA attention, this is ``v_head_dim``.
109- cache_specs: Optional per-layer ``(num_heads, key_head_dim,
110- value_head_dim)`` values for models with non-uniform cache layouts.
111108
112109 Returns:
113110 A list of ``(key, value)`` tuples for passing to the module.
114111 """
115- if cache_specs is None :
116- k_dim = key_head_dim if key_head_dim is not None else head_dim
117- v_dim = value_head_dim if value_head_dim is not None else head_dim
118- cache_specs = [(num_kv_heads , k_dim , v_dim )] * num_layers
119- elif len (cache_specs ) != num_layers :
120- raise ValueError (
121- f"cache_specs has { len (cache_specs )} entries for { num_layers } cache layers"
122- )
112+ k_dim = key_head_dim if key_head_dim is not None else head_dim
113+ v_dim = value_head_dim if value_head_dim is not None else head_dim
123114 pairs : list [tuple [ir .Value , ir .Value ]] = []
124- for i , ( layer_num_heads , k_dim , v_dim ) in enumerate ( cache_specs ):
115+ for i in range ( num_layers ):
125116 past_key = builder .input (
126117 f"{ prefix } .{ i } .key" ,
127118 dtype = dtype ,
128- shape = [batch , layer_num_heads , past_seq_len , k_dim ],
119+ shape = [batch , num_kv_heads , past_seq_len , k_dim ],
129120 )
130121 past_value = builder .input (
131122 f"{ prefix } .{ i } .value" ,
132123 dtype = dtype ,
133- shape = [batch , layer_num_heads , past_seq_len , v_dim ],
124+ shape = [batch , num_kv_heads , past_seq_len , v_dim ],
134125 )
135126 pairs .append ((past_key , past_value ))
136127 return pairs
@@ -147,7 +138,6 @@ def _register_kv_cache_outputs(
147138 value_head_dim : int | None = None ,
148139 total_seq_len : ir .SymbolicDim | str | int | None = None ,
149140 dtype : ir .DataType | None = None ,
150- cache_specs : list [tuple [int , int , int ]] | None = None ,
151141) -> None :
152142 """Name and register KV cache outputs on the graph.
153143
@@ -171,9 +161,6 @@ def _register_kv_cache_outputs(
171161 When the parameters are omitted, output shapes/dtypes are left to the
172162 shape inference pass that runs during model optimization.
173163
174- ``cache_specs`` replaces the three uniform head parameters with per-layer
175- ``(num_heads, key_head_dim, value_head_dim)`` values.
176-
177164 The present-shape parameters are all-or-nothing by design: pass every one
178165 to stamp the explicit type, or none to opt out and infer. A *partial* set
179166 is always a wiring slip (a caller wired some dims but dropped others) and is
@@ -189,30 +176,19 @@ def _register_kv_cache_outputs(
189176 "total_seq_len" : total_seq_len ,
190177 "dtype" : dtype ,
191178 }
192- if cache_specs is not None :
193- params .pop ("num_kv_heads" )
194- params .pop ("key_head_dim" )
195- params .pop ("value_head_dim" )
196179 provided = [name for name , value in params .items () if value is not None ]
197180 stamp = len (provided ) == len (params )
198181 if provided and not stamp :
199182 missing = [name for name in params if params [name ] is None ]
200183 raise ValueError (
201184 f"_register_kv_cache_outputs received a partial set of present-shape "
202185 f"parameters (provided { provided } , missing { missing } ); these are "
203- f"all-or-nothing. Pass all required values to stamp explicit present.* types "
186+ f"all-or-nothing. Pass all six to stamp explicit present.* types "
204187 f"(required for correct GroupQueryAttention head_dim), or none to opt "
205188 f"out and infer."
206189 )
207- if cache_specs is not None and len (cache_specs ) != len (present_key_values ):
208- raise ValueError (
209- f"cache_specs has { len (cache_specs )} entries for "
210- f"{ len (present_key_values )} present cache pairs"
211- )
212190 for i , (present_key , present_value ) in enumerate (present_key_values ):
213191 if stamp :
214- if cache_specs is not None :
215- num_kv_heads , key_head_dim , value_head_dim = cache_specs [i ]
216192 present_key .shape = ir .Shape ([batch , num_kv_heads , total_seq_len , key_head_dim ])
217193 present_key .type = ir .TensorType (dtype )
218194 present_value .shape = ir .Shape (
0 commit comments