Commit eb823d1
committed
feat(e7-18): thread pre_norm/post_norm through _build_attention + _build_mlp
Completes Spec-v2 §3.5 requirement that E7-6 left half-done. E7-6
(c1bc6f7) shipped norm_validation rules and the BrickContextPanel UI
dropdown, but the builders themselves hardcoded RMSNorm — a user
picking 'layernorm' or 'none' in the UI had zero effect on the model.
cppmega_v4/models/unified_superblock_v4.py:
- New _make_norm(kind, dim, eps) helper returns nn.RMSNorm /
nn.LayerNorm / None; raises on unknown kind.
- _build_attention now reads params.pre_norm (default 'none' for
legacy compat) and params.post_norm (default 'rmsnorm' for legacy
compat); applies pre_norm to input before Q/K/V proj, post_norm to
output projection result. self.norm alias preserved so existing
checkpoint state-dict keys still load.
- _build_mlp gains the same pre_norm/post_norm wiring (defaults
'none' / 'none' since the legacy MLP had no internal norm wrapper;
callers typically wrap at the block level).
Tests (+15 pytest):
- _make_norm returns the right class for each kind, raises on unknown
- attention with 5 norm combinations (legacy default + 4 mixes)
produces finite forward output
- mlp with 3 norm combos (none+none / rmsnorm+layernorm /
layernorm+rmsnorm) produces finite output
- attention default == legacy (pre=None, post=RMSNorm)
- attention post_norm='layernorm' instantiates nn.LayerNorm
- mlp default has no pre/post norms (legacy)
Regression: pytest 2321 (was 2306; +15) / 2 skip / 15 xfail / 0 fail
(excl. pre-existing path_d).
Closes cppmega-mlx-bb0.18.1 parent 3e82818 commit eb823d1
2 files changed
Lines changed: 141 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
| 87 | + | |
| 88 | + | |
84 | 89 | | |
85 | 90 | | |
| 91 | + | |
| 92 | + | |
86 | 93 | | |
87 | 94 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
96 | 107 | | |
97 | 108 | | |
98 | 109 | | |
| |||
363 | 374 | | |
364 | 375 | | |
365 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
366 | 389 | | |
367 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
368 | 396 | | |
369 | 397 | | |
370 | 398 | | |
| 399 | + | |
| 400 | + | |
371 | 401 | | |
372 | 402 | | |
373 | 403 | | |
| |||
376 | 406 | | |
377 | 407 | | |
378 | 408 | | |
379 | | - | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
380 | 413 | | |
381 | 414 | | |
382 | 415 | | |
383 | 416 | | |
| 417 | + | |
| 418 | + | |
384 | 419 | | |
385 | 420 | | |
386 | 421 | | |
| |||
396 | 431 | | |
397 | 432 | | |
398 | 433 | | |
399 | | - | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
400 | 438 | | |
401 | 439 | | |
402 | 440 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 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 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
0 commit comments