Repository navigation
[6771663] Preserve ONNX API output types when wiring casts - #2451
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 5476e662c68b95839c3cca4b1e35b1308c3a82ae and ad24f7fccb2d2e8ffc970d623fa481fedbdfad2e. 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review. 📝 WalkthroughWalkthroughFP16 conversion now uses preserved API-boundary I/O types when inserting output casts. A regression test verifies that a declared ChangesONNX output type preservation
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The conversion change preserves declared ONNX output types and includes regression coverage for the reported inference scenario. No unresolved merge-blocking issue remains. 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 40.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.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (claude-opus-5) — DM the bot to share feedback.
Approving: a small, correctly scoped fix that sources original_network_io from the boundary metadata instead of the post-inference working declaration, with a regression test and changelog entry.
No action needed.
- Checked the interaction with
_add_cast's existingmust_preserve_io_typeguard and_sanity_check; both now read the same boundary map, and the fallback whenoriginal_network_io_metadata is None(i.e.keep_io_types=False) reproduces the previous behavior exactly. - Cast-up/cast-down ordering for an output present in both lists still resolves to the boundary type, which is the intended outcome.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2451 +/- ##
==========================================
+ Coverage 71.50% 78.83% +7.33%
==========================================
Files 590 590
Lines 64749 64944 +195
==========================================
+ Hits 46297 51198 +4901
+ Misses 18452 13746 -4706
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: Ajinkya Rasane <[email protected]>
Signed-off-by: Ajinkya Rasane <[email protected]>
ad24f7f to
aeb0e2c
Compare
|
/ok to test aeb0e2c |
Type of change: Bug fix Preserves the public ONNX graph I/O types captured at the API boundary when `PrecisionConverter` wires output casts. Type inference can change the working graph's output declaration before conversion; consulting that mutated declaration caused the required cast back to the original public type to be discarded and metadata restoration to fail. The converter now derives its I/O type map from the preserved boundary metadata and uses that map when deciding whether a cast should become a public graph output. A regression test covers an FP32 output whose working declaration is inferred as FP16, and the changelog records the corrected behavior. ```python converted = convert_to_f16(model, keep_io_types=True) ``` - Ran `pytest tests/unit/onnx/autocast/test_precisionconverter.py` (186 passed). - Ran `pytest tests/unit/onnx/autocast` (249 passed). - Ran Ruff check and format validation on the changed Python files. - Verified the original minimal end-to-end reproduction with Python 3.12 and TensorRT 10.16.1.11; conversion now completes without the output-metadata restoration error. - Verified the full CLI quantization path proceeds through the formerly failing one-Q/DQ scheme and successfully benchmarks the generated TensorRT engine. Make sure you read and follow [Contributor guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md) and your commits are signed (`git commit -s -S`). Make sure you read and follow the [Security Best Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors) (e.g. avoiding hardcoded `trust_remote_code=True`, `torch.load(..., weights_only=False)`, `pickle`, etc.). - Is this change backward compatible?: ✅ - 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?: ✅ - Did you update [Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?: ✅ - Did you get Claude approval on this PR?: N/A Tracking: [6771663] <!-- This is an auto-generated comment: release notes by coderabbit.ai --> - **Bug Fixes** - Fixed ONNX FP16 conversion to preserve public graph output types when type inference changes internal declarations. - Ensured output casts are inserted correctly when preserving input/output types is enabled. - **Tests** - Added regression coverage confirming preserved output types, correct cast insertion, and valid ONNX model generation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Ajinkya Rasane <[email protected]> Co-authored-by: Ajinkya Rasane <[email protected]> Signed-off-by: Chad Voegele <[email protected]>
Type of change: Bug fix Preserves the public ONNX graph I/O types captured at the API boundary when `PrecisionConverter` wires output casts. Type inference can change the working graph's output declaration before conversion; consulting that mutated declaration caused the required cast back to the original public type to be discarded and metadata restoration to fail. The converter now derives its I/O type map from the preserved boundary metadata and uses that map when deciding whether a cast should become a public graph output. A regression test covers an FP32 output whose working declaration is inferred as FP16, and the changelog records the corrected behavior. ```python converted = convert_to_f16(model, keep_io_types=True) ``` - Ran `pytest tests/unit/onnx/autocast/test_precisionconverter.py` (186 passed). - Ran `pytest tests/unit/onnx/autocast` (249 passed). - Ran Ruff check and format validation on the changed Python files. - Verified the original minimal end-to-end reproduction with Python 3.12 and TensorRT 10.16.1.11; conversion now completes without the output-metadata restoration error. - Verified the full CLI quantization path proceeds through the formerly failing one-Q/DQ scheme and successfully benchmarks the generated TensorRT engine. Make sure you read and follow [Contributor guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md) and your commits are signed (`git commit -s -S`). Make sure you read and follow the [Security Best Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors) (e.g. avoiding hardcoded `trust_remote_code=True`, `torch.load(..., weights_only=False)`, `pickle`, etc.). - Is this change backward compatible?: ✅ - 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?: ✅ - Did you update [Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?: ✅ - Did you get Claude approval on this PR?: N/A Tracking: [6771663] <!-- This is an auto-generated comment: release notes by coderabbit.ai --> - **Bug Fixes** - Fixed ONNX FP16 conversion to preserve public graph output types when type inference changes internal declarations. - Ensured output casts are inserted correctly when preserving input/output types is enabled. - **Tests** - Added regression coverage confirming preserved output types, correct cast insertion, and valid ONNX model generation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Ajinkya Rasane <[email protected]> Co-authored-by: Ajinkya Rasane <[email protected]> Signed-off-by: Chad Voegele <[email protected]>
#2438 #2402 #2434 (#2504) ## Cherry-picked PRs - #2202 - #2317 - #2314 - #2403 - #2203 - #2413 - #2436 - #2451 - #2336 - #2438 - #2402 - #2434 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added Step-3.7 PTQ recipes for routed experts and MLPs using NVFP4, with FP8 KV-cache support. * Added SDXL FP4 quantization with FP8 convolution support. * Expanded FP4 ONNX export guidance to include Flux and SDXL. * Added BF16 compatibility for FP8 ONNX export. * **Bug Fixes** * Improved ONNX handling for large models, external data, metadata, opsets, and output types. * Improved attention quantization and invalid dynamic-scale handling. * Quantization now reports unmatched weight configurations, with an override for valid pipeline-parallel workflows. * **Documentation** * Updated calibration, ONNX opset, CLI, Step-3.7, and TensorRT-LLM deployment guidance. * Updated deployment guidance to use unified Hugging Face exports with the TensorRT-LLM PyTorch backend. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Zhiyu Cheng <[email protected]> Signed-off-by: Chad Voegele <[email protected]> Signed-off-by: ajrasane <[email protected]> Signed-off-by: Noey Yang <[email protected]> Signed-off-by: Ajinkya Rasane <[email protected]> Signed-off-by: Yue <[email protected]> Signed-off-by: yingguo-trt <[email protected]> Co-authored-by: Zhiyu <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Ajinkya Rasane <[email protected]> Co-authored-by: Codex <[email protected]> Co-authored-by: Codex <[email protected]> Co-authored-by: noeyy-mino <[email protected]> Co-authored-by: Ajinkya Rasane <[email protected]> Co-authored-by: yueshen2016 <[email protected]> Co-authored-by: yingguo-trt <[email protected]>
What does this PR do?
Type of change: Bug fix
Preserves the public ONNX graph I/O types captured at the API boundary when
PrecisionConverterwires output casts. Type inference can change the working graph's output declaration before conversion; consulting that mutated declaration caused the required cast back to the original public type to be discarded and metadata restoration to fail.The converter now derives its I/O type map from the preserved boundary metadata and uses that map when deciding whether a cast should become a public graph output. A regression test covers an FP32 output whose working declaration is inferred as FP16, and the changelog records the corrected behavior.
Usage
Testing
pytest tests/unit/onnx/autocast/test_precisionconverter.py(186 passed).pytest tests/unit/onnx/autocast(249 passed).Before your PR is "Ready for review"
Make sure you read and follow Contributor guidelines and your commits are signed (
git commit -s -S).Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded
trust_remote_code=True,torch.load(..., weights_only=False),pickle, etc.).CONTRIBUTING.md: N/AAdditional Information
Tracking: [6771663]
Summary by CodeRabbit
Bug Fixes
Tests