Skip to content

Fix protobuf size-check failures in ONNX deployment - #2403

Merged
ajrasane merged 1 commit into
NVIDIA:mainfrom
noeyy-mino:noeyy/fix_bug_6701737
Sep 11, 2026
Merged

ajrasane merged 1 commit into
NVIDIA:mainfrom
noeyy-mino:noeyy/fix_bug_6701737

Conversation

@noeyy-mino

@noeyy-mino noeyy-mino commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix:6701737

The ONNX deployment path assumed that ModelProto.ByteSize() would always return a valid size. With newer protobuf versions, querying the size of a model exceeding the protobuf serialization limit can itself raise EncodeError: Failed to serialize proto.

Replaced both direct size checks with the existing is_model_too_large_for_protobuf() helper. This helper handles size-query failures conservatively and checks the protobuf size limit:

Shape inference now selects the external-data/file-based path when ByteSize() fails or the model is too large.
Metadata creation uses the same safe check instead of raising another serialization error.
The unused TWO_GB constant was also removed.

Usage

python examples/diffusers/quantization/diffusion_trt.py --model flux-dev --benchmark --skip-image

Testing

the above test case pass on B100

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.).

  • Is this change backward compatible?: N/A
  • 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?: N/A
  • Did you update Changelog?: N/A
  • Did you get Claude approval on this PR?: N/A

Additional Information

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Improved ONNX model size detection during shape inference and export processing.
    • Ensured large models consistently use the appropriate external-data handling path.

@noeyy-mino
noeyy-mino requested a review from a team as a code owner September 11, 2026 10:30
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: cc6456a4-bee7-418e-9b2b-9210438831ee

📥 Commits

Reviewing files that changed from the base of the PR and between 59d93af and 40b2c3fe1703db6c01ed394d133ea306de0abe17.

📒 Files selected for processing (2)
  • modelopt/torch/_deploy/utils/onnx_optimizer.py
  • modelopt/torch/_deploy/utils/torch_onnx.py

Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review.


📝 Walkthrough

Walkthrough

The ONNX shape-inference and serialization utilities now use is_model_too_large_for_protobuf instead of local 2 GB size comparisons.

Changes

ONNX protobuf size detection

Layer / File(s) Summary
Adopt shared protobuf size check
modelopt/torch/_deploy/utils/onnx_optimizer.py, modelopt/torch/_deploy/utils/torch_onnx.py
Both utilities import and use is_model_too_large_for_protobuf. The local TWO_GB constant is removed. Existing external-data and serialization paths remain unchanged.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to ba36c

The shared protobuf size handling is applied consistently to both ONNX workflows without an identified regression.

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
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: fixing protobuf size-check failures in the ONNX deployment path.
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. Analyzed 2 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns ✅ Passed PASS. The authoritative PR range changes only two Python files: onnx_optimizer.py and torch_onnx.py. The added lines only import and call is_model_too_large_for_protobuf and remove TWO_GB. No …
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.77%. Comparing base (59d93af) to head (ba36ce2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2403      +/-   ##
==========================================
+ Coverage   71.15%   78.77%   +7.62%     
==========================================
  Files         543      543              
  Lines       64346    64345       -1     
==========================================
+ Hits        45785    50690    +4905     
+ Misses      18561    13655    -4906     
Flag Coverage Δ
examples-diffusers 20.64% <50.00%> (-0.01%) ⬇️
examples-gpt-oss 13.19% <0.00%> (+0.02%) ⬆️
examples-hf_ptq 22.19% <0.00%> (+0.57%) ⬆️
examples-llm_distill 13.26% <0.00%> (+0.01%) ⬆️
examples-llm_eval 17.10% <0.00%> (+0.06%) ⬆️
examples-llm_qat 17.44% <0.00%> (+0.04%) ⬆️
examples-llm_sparsity 15.74% <0.00%> (-0.01%) ⬇️
examples-megatron_bridge 26.05% <0.00%> (-0.20%) ⬇️
examples-specdec_bench 12.94% <0.00%> (+0.02%) ⬆️
examples-speculative_decoding 17.51% <0.00%> (-0.14%) ⬇️
examples-torch_onnx 21.62% <100.00%> (-0.03%) ⬇️
examples-torch_trt 14.95% <0.00%> (+<0.01%) ⬆️
gpu 58.18% <100.00%> (+25.95%) ⬆️
regression 14.96% <0.00%> (+0.09%) ⬆️
unit 57.52% <100.00%> (+<0.01%) ⬆️

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.

@ajrasane
ajrasane merged commit a1bcda4 into NVIDIA:main Sep 11, 2026
56 checks passed
@chadvoegele chadvoegele added the cherry-pick-done Added by bot once PR is cherry-picked to the release branch label Sep 22, 2026
chadvoegele pushed a commit that referenced this pull request Sep 22, 2026
### What does this PR do?

Type of change:  Bug fix:6701737

The ONNX deployment path assumed that ModelProto.ByteSize() would always
return a valid size. With newer protobuf versions, querying the size of
a model exceeding the protobuf serialization limit can itself raise
EncodeError: Failed to serialize proto.

Replaced both direct size checks with the existing
is_model_too_large_for_protobuf() helper. This helper handles size-query
failures conservatively and checks the protobuf size limit:

Shape inference now selects the external-data/file-based path when
ByteSize() fails or the model is too large.
Metadata creation uses the same safe check instead of raising another
serialization error.
The unused TWO_GB constant was also removed.

### Usage

```
python examples/diffusers/quantization/diffusion_trt.py --model flux-dev --benchmark --skip-image
```

### Testing
the above test case pass on B100

### Before your PR is "*Ready for review*"

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?:  N/A
- 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?: N/A
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
N/A
- Did you get Claude approval on this PR?: N/A

### Additional Information
N/A

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved ONNX model size detection during shape inference and export
processing.
* Ensured large models consistently use the appropriate external-data
handling path.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Noey Yang <[email protected]>
Signed-off-by: Chad Voegele <[email protected]>
chadvoegele added a commit that referenced this pull request Sep 22, 2026
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants