Commit d948cbc
committed
feat(v4): UnifiedSuperblockV4 real factories — no more pass-through stubs
Replaced 7 pass-through lambdas in BLOCK_BUILDERS with real factories:
- "gdn" → LinearAttentionBlock(LinearAttentionConfig(...))
(FLA-naive GDN; Path B/C/E dispatchable via env)
- "kda" → KimiDeltaAttentionBlock(KimiDeltaAttentionConfig(...))
- "moe" → V4MoE(V4MoEConfig(d_model=...)) wrapped to expose
.output (V4MoE returns MoEOutput dataclass)
- "attention" → standard multi-head self-attention with causal
mask + RMSNorm; o_proj zero-init for identity-at-init.
Also the fallback for "mla" and "mla_absorb" until
we land a full MLA block.
- "lightning_indexer" → LightningIndexerFP8 wrapped as residual no-op
(indexer's natural output is top-k indices, not
a residual — real consumption happens inside CSA+HCA).
Dispatch in UnifiedSuperblockV4.__call__ extended:
- _DOC_ID_KW_KINDS = {"gdn", "kda"} — these accept document_ids as a
keyword argument (their recurrent state needs the doc-reset signal).
- Engram remains positional-token-ids + keyword-doc-ids (special-cased).
Local imports inside each builder avoid circular-import issues at the
unified_superblock_v4 module level.
Tests (18 new in tests/v4/test_unified_superblock_real_factories.py):
- 7 parametrized: each kind is no longer a pass-through lambda.
- gdn / kda / moe / attention(×3 for mla aliases) builds and runs.
- GDN block threads doc_ids → output differs across doc-boundary
configurations (after perturbing o_proj, which is zero-init).
- attention zero-init identity check (out == in via residual).
- lightning_indexer residual identity (out == in by design).
- Full V4 stack end-to-end (engram + gdn + kda + attention + nsa +
csa_hca + moe + mlp) — runs forward and propagates gradients.
scripts/v4_1b_parquet_smoke.py updated: per-kind layer count spread
across all 7 attention-like kinds (gdn, kda, attention, nsa, csa_hca,
moe, mlp) so the smoke now exercises the *whole* V4 cohort, not just
the previously-non-stub subset.
Smoke run (hidden=1024, L=12, T=256, B=1, 3 steps):
loss decreases 11.18 → 11.02 → 10.96 (sanity check)
fwd median 59 ms, total 91 ms, ~2 800 tokens/sec
(was 10 191 tokens/sec on the engram+nsa+csa_hca+mlp-only subset,
drop is expected — we now run 6× more block kinds, including
attention/MoE compute that was being silently skipped before)
v4 suite: 303 passed / 2 skipped.1 parent 40a83ef commit d948cbc
3 files changed
Lines changed: 406 additions & 38 deletions
File tree
- cppmega_v4/models
- scripts
- tests/v4
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
85 | 207 | | |
86 | 208 | | |
87 | 209 | | |
88 | 210 | | |
89 | 211 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
98 | 221 | | |
99 | 222 | | |
100 | 223 | | |
| |||
106 | 229 | | |
107 | 230 | | |
108 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
109 | 236 | | |
110 | 237 | | |
111 | 238 | | |
112 | 239 | | |
113 | 240 | | |
114 | 241 | | |
115 | 242 | | |
116 | | - | |
117 | | - | |
| 243 | + | |
| 244 | + | |
118 | 245 | | |
119 | 246 | | |
120 | 247 | | |
| |||
168 | 295 | | |
169 | 296 | | |
170 | 297 | | |
171 | | - | |
| 298 | + | |
| 299 | + | |
172 | 300 | | |
173 | 301 | | |
174 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
175 | 306 | | |
176 | 307 | | |
177 | 308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
46 | 84 | | |
47 | 85 | | |
48 | 86 | | |
49 | 87 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 88 | + | |
74 | 89 | | |
75 | 90 | | |
76 | 91 | | |
| |||
0 commit comments