fix(megatron): tolerate model _extra_state keys absent from the checkpoint (QAD)#1931
fix(megatron): tolerate model _extra_state keys absent from the checkpoint (QAD)#1931ChenhanYu wants to merge 1 commit into
Conversation
…point When restoring a sharded modelopt checkpoint, _load_extra_state_from_sharded_checkpoint builds the extra-state request from the model's sharded_state_dict. If the model declares an _extra_state entry the checkpoint lacks -- e.g. a TransformerEngine version bump adds `decoder.final_layernorm._extra_state` that an older/quantized checkpoint never saved -- the torch_dist DCP planner hard-raises "Missing key in checkpoint state_dict: ..." from create_default_local_load_plan, before Megatron's StrictHandling runs (LOG_UNEXPECTED does not drop ShardedObject extra_state keys). This breaks Megatron QAD/QAT: load a quantized NVFP4 checkpoint, then train with --modelopt-enabled. Restrict the request to _extra_state keys actually present in the checkpoint (via load_sharded_metadata). A genuinely-missing norm extra_state is safe to leave freshly initialized -- it holds fp8/RNG metadata, not learned weights. Also add a launcher QAD example that exercises this path: tools/launcher/examples/meta-llama/Llama-3.2-1B-Instruct/megatron_lm_qad.yaml (PTQ -> QAD/SFT train). Both tasks call the Megatron-LM ModelOpt example scripts (quantize.sh / train.sh) directly -- one shell script on top of the .py, no launcher-side wrapper. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Chenhan Yu <chenhany@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1931 +/- ##
==========================================
- Coverage 77.62% 77.62% -0.01%
==========================================
Files 515 515
Lines 57301 57304 +3
==========================================
Hits 44482 44482
- Misses 12819 12822 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What does this PR do?
Type of change: Bug fix (+ new example)
Fixes a
CheckpointExceptionwhen resuming a sharded ModelOpt checkpoint for Megatron QAD/QAT (load a quantized NVFP4 checkpoint, then train with--modelopt-enabled):Root cause:
_load_extra_state_from_sharded_checkpointbuilds the extra-state request from the model'ssharded_state_dict. When the model declares an_extra_stateentry the checkpoint lacks — e.g. a TransformerEngine version bump addsdecoder.final_layernorm._extra_statethat an older/quantized checkpoint never saved — torch DCP's planner hard-raises before Megatron'sStrictHandlingruns (LOG_UNEXPECTEDdoes not dropShardedObjectextra_state keys).Fix: restrict the request to
_extra_statekeys actually present in the checkpoint (viaload_sharded_metadata). A genuinely-missing norm extra_state is safe to leave freshly initialized — it holds fp8/RNG metadata, not learned weights.Also adds a launcher QAD example (
tools/launcher/examples/meta-llama/Llama-3.2-1B-Instruct/megatron_lm_qad.yaml): PTQ → MMLU gate → QAD/SFT train, each task calling the Megatron-LM ModelOpt example scripts (quantize.sh/mmlu.sh/train.sh) directly.Usage
Testing
slurm.py --yaml ... --dryrunresolves all 3 tasks (EXIT 0)._extra_statefix on the QAD path is pending (needs the quantize→train run in the TRT-LLM container) — flagged as a draft until then.Before your PR is "Ready for review"
# TODO: Add unit tests for this plugin); the fix is exercised by the new QAD example / GPU e2e.Additional Information
Draft — pending GPU e2e validation. Surfaced while triaging the nmm-sandbox Megatron QAD CI test (Llama-3.2-1B-Instruct).