Commit 2a7775a
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 78049f9 commit 2a7775a
8 files changed
Lines changed: 907 additions & 161 deletions
File tree
- src/maxtext
- checkpoint_conversion/standalone_scripts
- trainers/pre_train
- utils
- tests/unit
Lines changed: 61 additions & 28 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 | | - | |
96 | | - | |
97 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
98 | 112 | | |
99 | 113 | | |
100 | 114 | | |
| |||
103 | 117 | | |
104 | 118 | | |
105 | 119 | | |
106 | | - | |
107 | 120 | | |
108 | 121 | | |
109 | 122 | | |
| |||
188 | 201 | | |
189 | 202 | | |
190 | 203 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
195 | 219 | | |
196 | 220 | | |
197 | 221 | | |
| |||
203 | 227 | | |
204 | 228 | | |
205 | 229 | | |
206 | | - | |
207 | | - | |
208 | 230 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
219 | 251 | | |
220 | 252 | | |
221 | 253 | | |
| |||
267 | 299 | | |
268 | 300 | | |
269 | 301 | | |
270 | | - | |
271 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
272 | 305 | | |
273 | | - | |
| 306 | + | |
274 | 307 | | |
275 | 308 | | |
276 | 309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
533 | | - | |
534 | 533 | | |
535 | 534 | | |
| 535 | + | |
| 536 | + | |
536 | 537 | | |
537 | | - | |
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
| |||
0 commit comments