Skip to content

Commit 3244f7f

Browse files
authored
Reduce duplicated MLA config comment per code review
Move the full MLA kv-heads explanation to a single top-of-file note and reference it concisely from each MLA config entry. Signed-off-by: copilot
1 parent 02b2e56 commit 3244f7f

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

tests/_test_configs.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757

5858
LONGROPE_FACTORS = [1.0] * (int(TINY_HEAD_DIM * 0.5) // 2)
5959

60+
# NOTE (MLA models): Multi-head Latent Attention models (DeepSeek-V2/V3,
61+
# LongCat-Flash, ...) reconstruct full-head K/V from a shared latent, so they do
62+
# not use grouped-query attention. Their tiny configs must set
63+
# num_key_value_heads == num_attention_heads; otherwise HuggingFace's repeat_kv()
64+
# in the SDPA path duplicates the already-full-head K/V tensors, producing a
65+
# head-count mismatch against the query.
66+
6067

6168
def _base_config(config_cls=None, **overrides) -> ArchitectureConfig:
6269
"""Create a tiny ArchitectureConfig for graph-build and parity tests.
@@ -550,8 +557,7 @@ def _base_config(config_cls=None, **overrides) -> ArchitectureConfig:
550557
(
551558
"deepseek_v3",
552559
{
553-
# MLA uses full-head K/V (no GQA); num_key_value_heads must equal
554-
# num_attention_heads or HF's repeat_kv in SDPA inflates the KV heads.
560+
# MLA: kv heads must equal attn heads (see MLA note near top of file).
555561
"num_key_value_heads": TINY_HEADS,
556562
"q_lora_rank": 32,
557563
"kv_lora_rank": 16,
@@ -584,8 +590,7 @@ def _base_config(config_cls=None, **overrides) -> ArchitectureConfig:
584590
(
585591
"deepseek_v2",
586592
{
587-
# MLA uses full-head K/V (no GQA); num_key_value_heads must equal
588-
# num_attention_heads or HF's repeat_kv in SDPA inflates the KV heads.
593+
# MLA: kv heads must equal attn heads (see MLA note near top of file).
589594
"num_key_value_heads": TINY_HEADS,
590595
"q_lora_rank": 32,
591596
"kv_lora_rank": 16,
@@ -610,8 +615,7 @@ def _base_config(config_cls=None, **overrides) -> ArchitectureConfig:
610615
(
611616
"deepseek_v2_moe",
612617
{
613-
# MLA uses full-head K/V (no GQA); num_key_value_heads must equal
614-
# num_attention_heads or HF's repeat_kv in SDPA inflates the KV heads.
618+
# MLA: kv heads must equal attn heads (see MLA note near top of file).
615619
"num_key_value_heads": TINY_HEADS,
616620
"q_lora_rank": 32,
617621
"kv_lora_rank": 16,
@@ -783,8 +787,7 @@ def _base_config(config_cls=None, **overrides) -> ArchitectureConfig:
783787
"longcat_flash",
784788
{
785789
"_config_cls": LongcatFlashConfig,
786-
# MLA uses full-head K/V (no GQA); num_key_value_heads must equal
787-
# num_attention_heads or HF's repeat_kv in SDPA inflates the KV heads.
790+
# MLA: kv heads must equal attn heads (see MLA note near top of file).
788791
"num_key_value_heads": TINY_HEADS,
789792
"q_lora_rank": 16,
790793
"kv_lora_rank": 8,
@@ -1097,8 +1100,7 @@ def _base_config(config_cls=None, **overrides) -> ArchitectureConfig:
10971100
(
10981101
"deepseek_v2",
10991102
{
1100-
# MLA uses full-head K/V (no GQA); num_key_value_heads must equal
1101-
# num_attention_heads or HF's repeat_kv in SDPA inflates the KV heads.
1103+
# MLA: kv heads must equal attn heads (see MLA note near top of file).
11021104
"num_key_value_heads": TINY_HEADS,
11031105
"q_lora_rank": 32,
11041106
"kv_lora_rank": 16,

0 commit comments

Comments
 (0)