Commit 9ddf5d4
committed
NNX: fix MTP eval under pure_nnx (sharding rule + sown-var handling)
Two NNX-only bugs blocked MTP eval (mtp_num_layers>0 + mtp_eval_target_module)
under pure_nnx=True. Both exist on main and surface only on the NNX path (main
defaults to Linen).
1. logical_axis_rules: the MTP projection kernel is tagged with logical axis
'concat_embed' (and the fused gated-MLP wi uses 'num_activations'), but neither
was in logical_axis_rules. get_abstract_model resolves logical->physical via
flax's from_sharding_rules, which returns unmapped names verbatim, so the literal
name reached NamedSharding and was rejected. Linen replicates unmapped axes by
default. Add both as replicated ([]) (base.yml).
2. loss_fn: mtp_losses/mtp_acceptance are nnx.Variable subclasses, not
nnx.Intermediate, so nnx.pop(model, nnx.Intermediate) missed them. They leaked
into the returned train state and broke out_shardings at compile, and were
absent from intermediate_outputs so calculate_mtp_loss read None and the MTP loss
was silently dropped. Pop them into intermediate_outputs under their collection
names and exclude them from the returned state (train.py).
Validated on CPU (gpt3-52k, mtp_num_layers=1 mtp_eval_target_module=1): trains,
mtp_loss is non-zero in the total loss, and mtp_acceptance_rate is reported in eval.1 parent a8505ff commit 9ddf5d4
3 files changed
Lines changed: 38 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
200 | 210 | | |
201 | 211 | | |
202 | 212 | | |
| |||
532 | 542 | | |
533 | 543 | | |
534 | 544 | | |
535 | | - | |
536 | | - | |
537 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
538 | 549 | | |
539 | 550 | | |
540 | 551 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1670 | 1670 | | |
1671 | 1671 | | |
1672 | 1672 | | |
1673 | | - | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
1674 | 1690 | | |
1675 | 1691 | | |
1676 | 1692 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | | - | |
282 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
283 | 287 | | |
284 | 288 | | |
285 | 289 | | |
| |||
0 commit comments