Skip to content

Warn when layerwise export ignores save_modelopt_state - #3041

Merged
yingguo-trt merged 2 commits into
NVIDIA:mainfrom
yingguo-trt:fix/layerwise-export-state-warning
Oct 28, 2026
Merged

yingguo-trt merged 2 commits into
NVIDIA:mainfrom
yingguo-trt:fix/layerwise-export-state-warning

Conversation

@yingguo-trt

@yingguo-trt yingguo-trt commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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=True on the layerwise path now receive a warning that the option is unsupported and ignored. The default False behavior is unchanged.

Testing

  • Extended only the existing test_config_only_export_is_finishable, parametrized with False/True, through the public export_hf_checkpoint() API. The test retains the export-artifact and exporter-cleanup checks and checks for the option warning without matching its full wording.
  • B100, real four-layer tiny Llama with FP8 layerwise calibration, PyTorch 2.13.0a0+9186a08b2c.nv26.07, Transformers 5.18.0:
    • Upstream 0c4bf38e5bf6ffac10e7785e6fed0cd70abb5093 plus the updated test, without the fix: 1 failed, 1 passed. Only the True parameter fails, on the missing option warning.
    • Same source and environment with the fix: 2 passed in 2.19s, no skips.
  • Command: python -m pytest -o addopts='' -q --durations=2 tests/gpu/torch/export/test_layerwise_export.py::test_config_only_export_is_finishable
  • File-scoped pre-commit checks passed except for Windows mypy reporting os.sched_getaffinity in an unchanged module; the same mypy hook version and arguments with --platform linux passed for both changed files.
  • Review follow-up: added only a 0.48.0 changelog entry; file-scoped pre-commit and git diff --check passed. The implementation and test files are byte-identical to the B100-tested revision, so GPU tests were not rerun for this documentation change.
  • Not run: full GPU suite, checkpoint reload/inference or quality evaluation. This is a warning-only fix.

Before your PR is "Ready for review"

  • Is this change backward compatible?: Yes for ordinary callers; export is preserved and the previously ignored option now emits a warning. Callers treating warnings as errors will observe that warning as an error.
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: Extended one existing GPU test, no new test function or matrix.
  • Did you update Changelog?: Yes, under 0.48.0 Bug Fixes, including guidance for callers treating warnings as errors. The affected path is also present in 0.48.0rc1 and release/0.48.0 (source-verified; not GPU-retested with the release wheel).
  • Did you get Claude approval on this PR?: Claude reviewed with comments; no Claude approval yet. The layerwise owner, @Fridah-nv, approved the warning approach.

Additional Information

Targets release/0.48.0 via the cherry-pick-0.48.0 label.

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

  • Bug Fixes
    • Layerwise exports now warn when saving ModelOpt state is enabled, since this option is unsupported and will be ignored.

@yingguo-trt
yingguo-trt requested review from a team as code owners October 27, 2026 02:30
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 839a78c and b3c7aeb.

Files selected for processing: 1
  • CHANGELOG.rst

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

Layerwise HF export now warns when save_modelopt_state=True, stating that the option is unsupported and will be ignored. The updated test checks for the warning with the option enabled and its absence when disabled.

Changes: Layerwise export option warning

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: Normal

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_state through the Diffusers HF export path. Both PRs address this option in HF export.
  • NVIDIA/Model-Optimizer#3030: Removes stale modelopt_state.pth files 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: Passed 6
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: warning when layerwise export ignores save_modelopt_state.
Linked Issues check Passed [#3040] requires an explicit warning when layerwise export ignores save_modelopt_state=True and requires the completed checkpoint export to remain available. export_hf_checkpoint now warns for a t…
Out of Scope Changes check Passed 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 an…
Docstring Coverage Passed 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 survi…
Security Anti-Patterns Passed PASS: The pull request changes only modelopt/torch/export/unified_export_hf.py, tests/gpu/torch/export/test_layerwise_export.py, and CHANGELOG.rst. The only production-code addition is a `warnin…
Full details: Linked Issues check

Explanation

[#3040] requires an explicit warning when layerwise export ignores save_modelopt_state=True and requires the completed checkpoint export to remain available. export_hf_checkpoint now warns for a truthy save_modelopt_state value before the existing exporter.finalize(...) and cleanup path. The test calls the public API for both False and True, 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, and CHANGELOG.rst. The only production-code addition is a warnings.warn(...) call guarded by save_modelopt_state; it adds no torch.load(..., weights_only=False), numpy.load(..., allow_pickle=True), hardcoded trust_remote_code=True, eval, exec, or # nosec. No pyproject.toml or requirements.txt file 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.

@yingguo-trt
yingguo-trt removed the request for review from Edwardf0t1 October 27, 2026 02:31
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.32%. Comparing base (90b8e63) to head (b3c7aeb).
⚠️ Report is 2 commits behind head on main.

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     
Flag Coverage Δ
examples-diffusers 19.95% <0.00%> (-0.01%) ⬇️
examples-gpt-oss 13.44% <0.00%> (-0.01%) ⬇️
examples-hf_ptq 23.41% <0.00%> (-0.02%) ⬇️
examples-llm_distill 13.52% <0.00%> (-0.01%) ⬇️
examples-llm_eval 17.22% <0.00%> (-0.01%) ⬇️
examples-llm_qat 17.40% <0.00%> (-0.04%) ⬇️
examples-llm_sparsity 16.75% <0.00%> (-0.01%) ⬇️
examples-megatron_bridge 26.50% <0.00%> (-0.25%) ⬇️
examples-specdec_bench 13.23% <0.00%> (-0.01%) ⬇️
examples-speculative_decoding 17.47% <0.00%> (-0.07%) ⬇️
examples-torch_onnx 21.25% <0.00%> (-0.03%) ⬇️
examples-torch_trt 15.20% <0.00%> (-0.01%) ⬇️
examples-vllm_serve 17.43% <0.00%> (-0.01%) ⬇️
gpu 59.05% <100.00%> (-1.26%) ⬇️
regression 15.04% <0.00%> (-0.01%) ⬇️
unit 61.38% <50.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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]>
@yingguo-trt
yingguo-trt force-pushed the fix/layerwise-export-state-warning branch from 528a0df to 839a78c Compare October 27, 2026 02:43

@shengliangxu shengliangxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=True in export_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 runs export_hf_checkpoint instead of exporter.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.rst bug-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. warnings is already imported at module scope.
  • The test's recwarn.clear() stops calibration-time warnings from leaking into the assertion. The == save_modelopt_state check covers both directions.

@Fridah-nv Fridah-nv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't fully support fake quant use case for this feature yet, a warning LGTM for now.

@yingguo-trt
yingguo-trt enabled auto-merge (squash) October 27, 2026 03:46
@yingguo-trt

yingguo-trt commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

@shengliangxu, thanks for the review. Following up on the three action items:

  1. Warning contract: @Fridah-nv confirmed that a warning is appropriate for now, since fake-quant use cases are not fully supported for this feature yet.
  2. Existing test: The switch to export_hf_checkpoint() in test_config_only_export_is_finishable was included in the revision Fridah approved. It retains the artifact and exporter-cleanup assertions and covers both flag values; no further test changes were needed.
  3. Changelog: Added a 0.48.0 Bug Fixes entry in b3c7aeb209, including guidance for callers treating warnings as errors, matching the cherry-pick-0.48.0 target.

The PR description now records the owner's confirmation. This follow-up only changes the changelog; applicable pre-commit checks and git diff --check passed. Code and tests are unchanged from the earlier B100 run (2 passed, no skips); GPU tests were not rerun.

@shengliangxu shengliangxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_finishable in tests/gpu/torch/export/test_layerwise_export.py. It now calls export_hf_checkpoint() instead of exporter.finalize() and runs with save_modelopt_state both False and True. 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.0 Bug Fixes entry was added to CHANGELOG.rst. It tells callers who treat warnings as errors to leave the option at False.
  • The warning fires before finalize(), so finalization, the off-index copy and exporter cleanup are unchanged.
  • export_hf_checkpoint is 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.

@yingguo-trt
yingguo-trt merged commit 7092db6 into NVIDIA:main Oct 28, 2026
54 checks passed
@rohansjoshi rohansjoshi added the cherry-pick-done Added by bot once PR is cherry-picked to the release branch label Oct 28, 2026
rohansjoshi added a commit that referenced this pull request Oct 28, 2026
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-0.48.0 cherry-pick-done Added by bot once PR is cherry-picked to the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Layerwise HF export silently ignores save_modelopt_state=True

4 participants