Repository navigation
[NVBug 6982525] Honor save_modelopt_state in Diffusers export - #3012
yingguo-trt merged 2 commits into
Conversation
Signed-off-by: yingguo-trt <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Configure component state saving modelopt/torch/export/unified_export_hf.py, tests/unit/torch/export/test_export_diffusers.py, CHANGELOG.rst |
_export_diffusers_checkpoint accepts save_modelopt_state, defaulting to False. The export path passes the option to quantized and non-quantized component saves. Tests check whether modelopt_state.pth exists for both option values and component cases. The changelog documents the behavior. |
Priority:
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Possibly related PRs
- NVIDIA/Model-Optimizer#2971: Changes Diffusers loading to find the same ModelOpt state file under a component subfolder.
Suggested labels: cherry-pick-0.48.0
Suggested reviewers: kevalmorabia97
Merge Risk: 
Minimal · up to db812
-
The export option is correctly propagated and covered for both Diffusers component paths.
Pre-merge checks: 
5 · 
1
-
Failed checks: 1 warning Passed checks: 5 passed-
Full details: Security Anti-Patterns
-
Explanation
PASS. The PR adds only
save_modelopt_stateforwarding inmodelopt/torch/export/unified_export_hf.pyand a test. No addedtorch.load(..., weights_only=False),numpy.load(..., allow_pickle=True), hardcodedtrust_remote_code=True, external-inputeval/exec, or# nosecbypass appears in the diff.pyproject.tomlandrequirements.txtare unchanged.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
Nudge: the fix looks correct, but it adds no regression test to the repo. The only evidence is a QA test that lives outside the repo and was run by hand.
Needs action:
- Add a regression test to
tests/unit/torch/export/test_export_diffusers.py. It should callmto.enable_huggingface_checkpointing(), export a tiny quantized diffusers component withsave_modelopt_state=Falseand assertmodelopt_state.pthis absent. A second case withTrueshould assert the file is written. Cover both the quantized and non-quantizedsave_pretrainedcalls. - Confirm the behaviour change is intended: Diffusers exports with HF checkpointing enabled used to write the sidecar by default and now don't. If so, add a CHANGELOG entry so users who rely on it can pass
save_modelopt_state=True.
No action needed:
- Passing
save_modelopt_statestraight tosave_pretrainedmatches the transformers path. The patched_new_save_pretrainedpops it, and unpatched diffusers/transformerssave_pretrainedmethods accept extra**kwargs. - No in-repo diffusers example enables HF checkpointing, so the default change has little practical reach.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3012 +/- ##
==========================================
+ Coverage 77.51% 79.14% +1.63%
==========================================
Files 661 661
Lines 74937 74937
==========================================
+ Hits 58086 59310 +1224
+ Misses 16851 15627 -1224
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:
|
Signed-off-by: yingguo-trt <[email protected]>
|
Addressed both items from this review in db812a1.
Validation: all four cases pass on CPU (0.06–0.09s per call). With the same tests on pre-fix source |
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
Approving: both concerns from the last review are fixed in the diff, and the flag forwarding is correct and minimal.
No action needed:
- ✔️ Resolved since the last review: the missing regression test (now a parameterized test over both
save_pretrainedbranches,True/False) and the missing CHANGELOG entry for the default change. - Disabling every quantizer makes
has_quantized_modulesreturn false, so the test really runs the non-quantized branch while ModelOpt state is kept. Theenable_hf_checkpointingfixture already exists intests/conftest.py. - The author ran the test against the pre-fix source: both
Falsecases failed and bothTruecases passed, so it catches the bug.
#2928 #2885 #2908 #2929 #2950 #2972 #2877 #2951 #2816 #3005 #3012 #2971 #3015 #3006 #3026 #2988 #3028 #1860 #3030 #2612 #3033 #2653 #2599 #2655 #2618 #2868 #3032 #3027 #2869 #2984 #2975 #2345 #3020 #2997 (#3072) ## Cherry-picked PRs - #2817 - #2671 - #2892 - #2876 - #2910 - #2911 - #2919 - #2904 - #2937 - #2928 - #2885 - #2908 - #2929 - #2950 - #2972 - #2877 - #2951 - #2816 - #3005 - #3012 - #2971 - #3015 - #3006 - #3026 - #2988 - #3028 - #1860 - #3030 - #2612 - #3033 - #2653 - #2599 - #2655 - #2618 - #2868 - #3032 - #3027 - #2869 - #2984 - #2975 - #2345 - #3020 - #2997 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Diffusion exports now offer more control over attention-quantizer metadata and preserve sparse-attention settings in a format compatible with downstream tooling. * Model loading better handles select bundled model implementations, and Docker guidance now covers writable CUDA-extension cache locations. * **Bug Fixes** * Improved reliability for model export and checkpoint saving, quantization across devices, ONNX processing, and calibration. * Temporary TensorRT and autotuning artifacts now use private directories by default. * **Documentation** * Updated installation guidance, compatibility notes, and links; corrected typos across guides and examples. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Chad Voegele <[email protected]> Signed-off-by: Rohan Joshi <[email protected]> Signed-off-by: LinCanNerd <[email protected]> Signed-off-by: Keval Morabia <[email protected]> Signed-off-by: weimingc <[email protected]> Signed-off-by: Noey Yang <[email protected]> Signed-off-by: Kai Xu <[email protected]> Signed-off-by: Zhehao Hu <[email protected]> Signed-off-by: noeyy-mino <[email protected]> Signed-off-by: joe-nv <[email protected]> Signed-off-by: yingguo-trt <[email protected]> Signed-off-by: Shengliang Xu <[email protected]> Signed-off-by: Chenjie Luo <[email protected]> Signed-off-by: anmaurya001 <[email protected]> Signed-off-by: Connor Baker <[email protected]> Signed-off-by: wiederse <[email protected]> Signed-off-by: Vu Dinh <[email protected]> Signed-off-by: Pratik Gandhi <[email protected]> Signed-off-by: Michael Rusu <[email protected]> Signed-off-by: Michael-Rusu <[email protected]> Signed-off-by: namgyu-youn <[email protected]> Signed-off-by: Sylvester Kaczmarek <[email protected]> Signed-off-by: Javier de Jesus <[email protected]> Signed-off-by: javierdejesusda <[email protected]> Signed-off-by: Zhiyu Cheng <[email protected]> Signed-off-by: Juhi Mittal <[email protected]> Signed-off-by: Dmitry Rantovov <[email protected]> Signed-off-by: h-guo18 <[email protected]> Co-authored-by: Chad Voegele <[email protected]> Co-authored-by: LinCanNerd <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Keval Morabia <[email protected]> Co-authored-by: Wei-Ming Chen <[email protected]> Co-authored-by: noeyy-mino <[email protected]> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: kaix-nv <[email protected]> Co-authored-by: Zhehao Hu <[email protected]> Co-authored-by: joe <[email protected]> Co-authored-by: yingguo-trt <[email protected]> Co-authored-by: Shengliang Xu <[email protected]> Co-authored-by: Chenjie Luo <[email protected]> Co-authored-by: anmaurya001 <[email protected]> Co-authored-by: Connor Baker <[email protected]> Co-authored-by: Jiao Mingyang <[email protected]> Co-authored-by: Vu Dinh <[email protected]> Co-authored-by: Pratik Gandhi <[email protected]> Co-authored-by: Michael R <[email protected]> Co-authored-by: Michael-Rusu <[email protected]> Co-authored-by: namgyu-youn <[email protected]> Co-authored-by: Sylvester Kaczmarek <[email protected]> Co-authored-by: Javier De Jesus <[email protected]> Co-authored-by: Zhiyu <[email protected]> Co-authored-by: Juhi Mittal <[email protected]> Co-authored-by: Dmitry Rantovov <[email protected]> Co-authored-by: h-guo18 <[email protected]>
What does this PR do?
Type of change: Bug fix
With HuggingFace checkpointing enabled,
export_hf_checkpoint(..., save_modelopt_state=False)still writesmodelopt_state.pthfor Diffusers components. The Diffusers dispatch and component saves omit the flag, so the checkpointing hook uses its own default ofTrue.Forward the public flag to both quantized and non-quantized model saves. The effective default intentionally changes: omitting the option now follows the public
Falsedefault. Callers who need the state file can passTrue. The same omitted forwarding is present in the 0.47.0 source, so this change includes a changelog entry.Usage
Testing
Local offline CPU validation: Windows, Python 3.12.10, PyTorch 2.12.0+cpu, Diffusers 0.40.0, Transformers 5.5.4;
OMP_NUM_THREADS=1, matching the unit-test workflow.False/Truewith real FP8 tiny-UNet quantizers enabled or disabled. Disabling the quantizers selects the non-quantized save branch while retaining ModelOpt conversion state. The existingenable_hf_checkpointingfixture enables the save hook.378888145ain an isolated checkout: both False cases fail because the sidecar is written; both True cases pass.Falsefails before and passes afterward. Config and safetensors files are produced in both versions.os.sched_getaffinityerror in unchangedprepare_megatron_data_blend.py:373, also reproduced on the baseline. The same Mypy version and hook arguments with--platform linuxpass for both changed Python files.git diff --checkpassed.This validates the state-file saving contract on CPU, not deployment inference or the saved state file's reloadability.
Before your PR is "Ready for review"
Contributor and security guidance reviewed; both commits are signed and signed off.
save_modelopt_state=Trueto retain it. The API signature is unchanged.CONTRIBUTING.md: N/A — neither.Additional Information
Fixes NVBug 6982525. The change suppresses new sidecar writes; it retains the existing handling of files already present in the export directory.
Summary by CodeRabbit