Skip to content

Commit bed2983

Browse files
Copilotjustinchuby
andauthored
Fix GLM-5.2 packed KV-cache layout (#559)
GLM-5.2 declared standard multi-head KV-cache inputs while DSA expected packed single-head caches, causing an invalid `Squeeze` and incomplete output shape inference. - **Cache wiring** - Use the dedicated `GlmMoeDsaTask`. - Declare per-layer packed cache widths for full and shared indexers: ```text key: [B, 1, T, H*(nope+rope) + optional_index_dim] value: [B, 1, T, H*value_dim] ``` - **Regression coverage** - Build co-located GLM tests through the production task. - Assert symmetric past/present cache shapes for both full and shared layers. <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #557 --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: justinchuby <[email protected]>
1 parent d33c33b commit bed2983

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

‎src/mobius/models/glm_moe_dsa_test.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class TestGlmMoeDsaGraphBuild:
243243
def _build(self, **overrides):
244244
config = _glm_config(**overrides)
245245
model = GlmMoeDsaCausalLMModel(config)
246-
package = build_from_module(model, config, task="text-generation")
246+
package = build_from_module(model, config, task="glm-moe-dsa")
247247
return config, package["model"]
248248

249249
def test_dsa_path_emits_one_index_share_per_hidden_layer_and_no_attention(self):
@@ -254,6 +254,26 @@ def test_dsa_path_emits_one_index_share_per_hidden_layer_and_no_attention(self):
254254
assert count_op_type(graph, "GroupQueryAttention") == 0
255255
assert count_op_type(graph, "MultiHeadAttention") == 0
256256

257+
def test_dsa_path_uses_packed_single_head_cache_io(self):
258+
config, onnx_model = self._build()
259+
cache_inputs = {value.name: list(value.shape) for value in onnx_model.graph.inputs[3:]}
260+
cache_outputs = {
261+
value.name: list(value.shape) for value in onnx_model.graph.outputs[1:]
262+
}
263+
for i, indexer_type in enumerate(config.indexer_types):
264+
key_width = config.num_attention_heads * (
265+
config.qk_nope_head_dim + config.qk_rope_head_dim
266+
) + (config.index_head_dim if indexer_type == "full" else 0)
267+
value_width = config.num_attention_heads * config.v_head_dim
268+
past_key_shape = cache_inputs[f"past_key_values.{i}.key"]
269+
past_value_shape = cache_inputs[f"past_key_values.{i}.value"]
270+
present_key_shape = cache_outputs[f"present.{i}.key"]
271+
present_value_shape = cache_outputs[f"present.{i}.value"]
272+
assert [past_key_shape[1], past_key_shape[3]] == [1, key_width]
273+
assert [past_value_shape[1], past_value_shape[3]] == [1, value_width]
274+
assert [present_key_shape[1], present_key_shape[3]] == [1, key_width]
275+
assert [present_value_shape[1], present_value_shape[3]] == [1, value_width]
276+
257277
def test_index_share_inputs_are_float32_under_a_non_float_dtype(self):
258278
"""Regression test for the frozen ``IndexShare`` f32-only schema.
259279

0 commit comments

Comments
 (0)