Repository navigation
Fix/nnx unroll scan axis - #4369
Conversation
b47961f to
f432f83
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ff411f7 to
06f4b2a
Compare
There was a problem hiding this comment.
Do we need handle the scan axis here?
We should promote get_scan_axis from a nested local closure to a general module-level function, and reuse it here.
There was a problem hiding this comment.
We promoted get_scan_axis and fully integrated it into the unrolling logic for both base model parameters ( _possibly_unroll_params_nnx ) and LoRA adapters ( _possibly_unroll_lora_params_nnx ).
bd07a31 to
2702fd9
Compare
2702fd9 to
c6128dd
Compare
|
Hi @xibinliu, here's more details for the LoRA unrolling: • We integrated the |
Description
This PR fixes a critical crash in the
generate_param_only_checkpoint.pyutility when checkpoint unrolling is executed with Flax NNX enabled (enable_nnx=true).The Problem / Root Cause
In Flax NNX, the model state variables are partitioned differently:
nnx.Param) are scanned overconfig.param_scan_axis(typicallyaxis 1).axis 0(as defined innnx_decoders.py).Prior to this fix, the unrolling utility’s slicing helper
slice_ithblindly appliedjnp.take(x, i, axis=config.param_scan_axis)to every node in the PyTree. For rank-1 non-parameter variables, attempting to take alongaxis 1caused theValueError: axis 1 is out of bounds for array of dimension 1crash.The Solution
We updated
slice_ithto dynamically resolve the scan axis for each array in the PyTree:axis 0.config.param_scan_axis(normallyaxis 1).This ensures robust and correct dynamic slicing across both parameters and non-parameters during Flax NNX checkpoint unrolling.
Tests
We reproduced the failure on the
mainbranch and verified the fix across both CPU and TPU platforms (using a physicalv5p-8TPU slice).1. Reproduction on
mainRunning the unrolling command on the
mainbranch withenable_nnx=truereproduced the exact crash from the Airflow DAG logs:logs
2. Verification with Fix Branch
Running the identical unrolling command on this branch successfully unrolled the checkpoint and completed with exit code 0:
logs
Checklist
gemini-reviewlabel.