Repository navigation
Warn when layerwise export ignores save_modelopt_state - #3041
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Warn when state saving is unsupported modelopt/torch/export/unified_export_hf.py, tests/gpu/torch/export/test_layerwise_export.py, CHANGELOG.rst |
Layerwise export warns when save_modelopt_state=True. The test calls export_hf_checkpoint with both option values and checks that the warning appears only when enabled. The changelog documents the warning and the default option value. |
Priority:
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related PRs
- NVIDIA/Model-Optimizer#3012: Forwards
save_modelopt_statethrough the Diffusers HF export path. Both PRs address this option in HF export. - NVIDIA/Model-Optimizer#3030: Removes stale
modelopt_state.pthfiles when HF saves do not retain ModelOpt state. Both PRs address ModelOpt-state sidecar behavior in HF checkpoint export.
Suggested labels: waiting for feedback
Suggested reviewers: kevalmorabia97
Merge Risk: 
Minimal · up to b3c7a
-
No merge-blocking issue was found in the reviewed change.
Pre-merge checks: 
6
-
Full details: Linked Issues check
-
Explanation
[
#3040] requires an explicit warning when layerwise export ignoressave_modelopt_state=Trueand requires the completed checkpoint export to remain available.export_hf_checkpointnow warns for a truthysave_modelopt_statevalue before the existingexporter.finalize(...)and cleanup path. The test calls the public API for bothFalseandTrue, checks the warning condition, and retains checks for export artifacts and exporter cleanup. The change does not add ModelOpt-state serialization, which the issue does not require.
Full details: Out of Scope Changes check
-
Explanation
The whole-PR diff changes the layerwise export implementation, its focused GPU test, and the changelog. The implementation and test directly support [
#3040]. The changelog documents the new warning and caller guidance. No unrelated behavior, dependency, or serialization changes appear.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)
Full details: Security Anti-Patterns
-
Explanation
PASS: The pull request changes only
modelopt/torch/export/unified_export_hf.py,tests/gpu/torch/export/test_layerwise_export.py, andCHANGELOG.rst. The only production-code addition is awarnings.warn(...)call guarded bysave_modelopt_state; it adds notorch.load(..., weights_only=False),numpy.load(..., allow_pickle=True), hardcodedtrust_remote_code=True,eval,exec, or# nosec. Nopyproject.tomlorrequirements.txtfile changed, so the dependency condition does not apply.
-
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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3041 +/- ##
==========================================
- Coverage 79.95% 79.32% -0.63%
==========================================
Files 661 661
Lines 75164 76006 +842
==========================================
+ Hits 60094 60290 +196
- Misses 15070 15716 +646
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:
|
Fixes NVIDIA#3040. Preserve export behavior and exercise the public API with both flag values in the existing GPU test. Signed-off-by: yingguo-trt <[email protected]>
528a0df to
839a78c
Compare
shengliangxu
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 warning is correct and copies the streaming-offload path, but the author explicitly asks a maintainer whether layerwise export should warn or actually save the ModelOpt state.
Needs action:
- Confirm, as layerwise owner, that warning is the intended contract for
save_modelopt_state=Trueinexport_hf_checkpoint's layerwise branch, or ask for state saving instead (follow-up issue is fine). - Sign off on the edit to
test_config_only_export_is_finishable. It now runsexport_hf_checkpointinstead ofexporter.finalize(), still finalizes, and keeps the artifact and cleanup assertions. The change is justified, and coverage widens to the public API. - Consider adding a
CHANGELOG.rstbug-fix entry, since this is user-visible: callers that treat warnings as errors will now fail.
No action needed:
- The warning fires before
finalize(), so finalization, the off-index copy and exporter cleanup are unchanged.warningsis already imported at module scope. - The test's
recwarn.clear()stops calibration-time warnings from leaking into the assertion. The== save_modelopt_statecheck covers both directions.
Fridah-nv
left a comment
There was a problem hiding this comment.
We don't fully support fake quant use case for this feature yet, a warning LGTM for now.
Signed-off-by: yingguo-trt <[email protected]>
|
@shengliangxu, thanks for the review. Following up on the three action items:
The PR description now records the owner's confirmation. This follow-up only changes the changelog; applicable pre-commit checks and |
shengliangxu
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
LGTM: all three concerns from the last review are resolved, and a human only needs to sign off on the justified edit to an existing test.
Needs action:
- Sign off on the edit to
test_config_only_export_is_finishableintests/gpu/torch/export/test_layerwise_export.py. It now callsexport_hf_checkpoint()instead ofexporter.finalize()and runs withsave_modelopt_statebothFalseandTrue. The artifact and cleanup checks are still there, and coverage gets wider.
No action needed:
- ✔️ Resolved since the last review:
- The layerwise owner (@Fridah-nv) confirmed that a warning is the intended behavior for now.
- The test edit is justified.
- A
0.48.0Bug Fixes entry was added toCHANGELOG.rst. It tells callers who treat warnings as errors to leave the option atFalse.
- The warning fires before
finalize(), so finalization, the off-index copy and exporter cleanup are unchanged. export_hf_checkpointis already imported at the top of the test module.- The author reports the GPU test passing on B100. Since then only the changelog has changed. I read the tests but didn't run them.
## Cherry-picked PRs - #2980 - #3041 - #2798 - #2979 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * INT4 and W4A8 exports now include more accurate quantization metadata. * Layerwise checkpoint loading is safer and provides clearer guidance when a checkpoint cannot be resumed. * **Bug Fixes** * TensorRT inference now handles dynamic and host-based inputs more reliably, validates input shapes and counts, and improves initialization. * Added warnings when fused-expert quantization stages are skipped or ModelOpt state saving is unsupported during layerwise export. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Fridah-nv <[email protected]> Signed-off-by: Rohan Joshi <[email protected]> Signed-off-by: yingguo-trt <[email protected]> Signed-off-by: ajrasane <[email protected]> Co-authored-by: Frida Hou <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]> Co-authored-by: yingguo-trt <[email protected]> Co-authored-by: Ajinkya Rasane <[email protected]>
What does this PR do?
Type of change: Bug fix
Fixes #3040.
Layerwise HF export returns after finalizing its exporter, silently ignoring
save_modelopt_state=True. This PR adds an explicit warning, following the existing streaming-offload precedent. Checkpoint finalization, file copying and exporter cleanup remain unchanged; this does not add layerwise ModelOpt-state serialization.Maintainer confirmation: @Fridah-nv approved the warning approach, explaining that fake-quant use cases are not fully supported for this feature yet. This PR retains that current limitation.
Usage
No new API. Callers requesting
save_modelopt_state=Trueon the layerwise path now receive a warning that the option is unsupported and ignored. The defaultFalsebehavior is unchanged.Testing
test_config_only_export_is_finishable, parametrized withFalse/True, through the publicexport_hf_checkpoint()API. The test retains the export-artifact and exporter-cleanup checks and checks for the option warning without matching its full wording.2.13.0a0+9186a08b2c.nv26.07, Transformers5.18.0:0c4bf38e5bf6ffac10e7785e6fed0cd70abb5093plus the updated test, without the fix: 1 failed, 1 passed. Only theTrueparameter fails, on the missing option warning.python -m pytest -o addopts='' -q --durations=2 tests/gpu/torch/export/test_layerwise_export.py::test_config_only_export_is_finishableos.sched_getaffinityin an unchanged module; the same mypy hook version and arguments with--platform linuxpassed for both changed files.0.48.0changelog entry; file-scoped pre-commit andgit diff --checkpassed. The implementation and test files are byte-identical to the B100-tested revision, so GPU tests were not rerun for this documentation change.Before your PR is "Ready for review"
CONTRIBUTING.md: N/A0.48.0Bug Fixes, including guidance for callers treating warnings as errors. The affected path is also present in0.48.0rc1andrelease/0.48.0(source-verified; not GPU-retested with the release wheel).Additional Information
Targets
release/0.48.0via thecherry-pick-0.48.0label.The layerwise export API integration was introduced in #2303. The regression test validates the current warning behavior and export finalization through the public API; this PR does not add ModelOpt-state serialization.
Summary by CodeRabbit