Commit a4b9db9
committed
NNX: QK-Clip on NNX + NNX-format checkpoint utilities
Closes the QK-Clip TODO and migrates the remaining Linen-only
checkpoint utilities to NNX. Linen paths preserved byte-for-byte
(every NNX edit is gated on `config.pure_nnx` or runtime state-shape
detection).
QK-Clip:
- qk_clip_utils.apply_qk_clip_nnx mutates state.model in place via
nnx.split -> pure-dict tree_map -> nnx.replace_by_pure_dict ->
nnx.update. Accepts both the production NNX intermediate shape
(self_attention.attention_op.max_logits) and the synthetic-fixture
shape from the existing Linen tests (self_attention.max_logits).
- train.py train_step dispatches to apply_qk_clip_nnx for NNX,
removing the prior TODO at the QK-Clip call site.
Checkpoint utilities (NNX paths added):
- standalone_checkpointer.checkpoint_loop builds an NNX init_state_fn
under pure_nnx; add_entropy_to_checkpoint dispatches across Linen
TrainState, NNX TrainStateNNX Module, and post-split nnx.State
shapes.
- generate_param_only_checkpoint: NNX init_state_fn under pure_nnx;
_possibly_unroll_params_nnx slices scanned NNX layers via dict-style
state mutation; _save_decode_checkpoint_nnx writes a bf16 pure-dict
tree to orbax. Parallel LoRA decode flow operates on the
single-nested LoRA delta tree from PR8's get_lora_abstract_state_nnx.
- convert_gpt3_ckpt_from_paxml: parallel NNX state_map keystr
translation (.params['params']<rest> -> .model<rest>.value, etc.).
End-to-end paxml -> NNX conversion is wired but not yet validated
on hardware.
Tests:
- qk_clip_test: 7 new NNX cases covering attention-type guard, MLA
wq_b/wkv_b math, both intermediate shapes, no-clip-below-threshold,
missing-stats resilience, Linen<->NNX numeric parity.
- standalone_checkpointer_nnx_test (new): 3 cases for adam mu/nu
overwrite on TrainStateNNX Module shape, no mutation of state.model
params, post-split nnx.State shape from setup_training_state.
- generate_param_only_checkpoint_nnx_test (new): 3 cases for scanned
layer slicing (Llama-style; DeepSeek-style dense+moe split; LoRA
delta unroll on the single-nested NNX shape).
NNX + AQT in MaxEngine and the layerwise_quantization NNX path are
split into the follow-up PR9.5.1 parent c62cbbb commit a4b9db9
8 files changed
Lines changed: 907 additions & 153 deletions
File tree
- src/maxtext
- checkpoint_conversion/standalone_scripts
- trainers/pre_train
- utils
- tests/unit
Lines changed: 61 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| 52 | + | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
56 | 61 | | |
57 | 62 | | |
58 | 63 | | |
| |||
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
96 | 112 | | |
97 | 113 | | |
98 | 114 | | |
| |||
101 | 117 | | |
102 | 118 | | |
103 | 119 | | |
104 | | - | |
105 | 120 | | |
106 | 121 | | |
107 | 122 | | |
| |||
186 | 201 | | |
187 | 202 | | |
188 | 203 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
193 | 219 | | |
194 | 220 | | |
195 | 221 | | |
| |||
201 | 227 | | |
202 | 228 | | |
203 | 229 | | |
204 | | - | |
205 | | - | |
206 | 230 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
217 | 251 | | |
218 | 252 | | |
219 | 253 | | |
| |||
265 | 299 | | |
266 | 300 | | |
267 | 301 | | |
268 | | - | |
269 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
270 | 305 | | |
271 | | - | |
| 306 | + | |
272 | 307 | | |
273 | 308 | | |
274 | 309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
529 | | - | |
530 | 529 | | |
531 | 530 | | |
| 531 | + | |
| 532 | + | |
532 | 533 | | |
533 | | - | |
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
| |||
0 commit comments