-
Notifications
You must be signed in to change notification settings - Fork 202
ONNX save fix #496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
ONNX save fix #496
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7210c14 to
31b23d6
Compare
e42bc6f to
8113df6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #496 +/- ##
==========================================
- Coverage 73.43% 73.43% -0.01%
==========================================
Files 180 180
Lines 18146 18144 -2
==========================================
- Hits 13326 13324 -2
Misses 4820 4820 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
12f93d7 to
d1652e2
Compare
Signed-off-by: Riyad Islam <[email protected]>
d1652e2 to
eed985e
Compare
kevalmorabia97
approved these changes
Nov 4, 2025
ajrasane
approved these changes
Nov 4, 2025
kevalmorabia97
pushed a commit
that referenced
this pull request
Nov 5, 2025
## What does this PR do?
**Type of change:** Bug <!-- Use one of the following: Bug fix, new
feature, new example, new tests, documentation. -->
**Overview:** `get_onnx_bytes` api is error prone as it returns only the
protobuf info. If model has any external data, they get discarded! We
have to use `get_onnx_bytes_and_metadata` and provide example for users
to correctly write ONNX model to disk.
## Usage
This would be proper way to save ONNX model bytes with/without external
data.
```python
onnx_bytes, _ = get_onnx_bytes_and_metadata(
model=model,
dummy_input=(input_tensor,),
weights_dtype=weights_dtype,
model_name=model_name,
)
onnx_bytes_obj = OnnxBytes.from_bytes(onnx_bytes)
# Write the onnx model to the specified directory without cleaning it
onnx_bytes_obj.write_to_disk(os.path.dirname(onnx_save_path), clean_dir=False)
```
## Testing
N/A. Existing tests are modified.
## Before your PR is "*Ready for review*"
<!-- If you haven't finished some of the above items you can still open
`Draft` PR. -->
- **Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/CONTRIBUTING.md)**
and your commits are signed.
- **Is this change backward compatible?**: Yes <!--- If No, explain why.
-->
- **Did you write any new necessary tests?**: Yes
- **Did you add or update any necessary documentation?**: Yes
- **Did you update
[Changelog](https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/CHANGELOG.rst)?**:
Yes<!--- Only for new features, API changes, critical bug fixes or bw
breaking changes. -->
## Additional Information
https://nvbugspro.nvidia.com/bug/5618246/4
Signed-off-by: Riyad Islam <[email protected]>
mxinO
pushed a commit
that referenced
this pull request
Nov 11, 2025
## What does this PR do?
**Type of change:** Bug <!-- Use one of the following: Bug fix, new
feature, new example, new tests, documentation. -->
**Overview:** `get_onnx_bytes` api is error prone as it returns only the
protobuf info. If model has any external data, they get discarded! We
have to use `get_onnx_bytes_and_metadata` and provide example for users
to correctly write ONNX model to disk.
## Usage
This would be proper way to save ONNX model bytes with/without external
data.
```python
onnx_bytes, _ = get_onnx_bytes_and_metadata(
model=model,
dummy_input=(input_tensor,),
weights_dtype=weights_dtype,
model_name=model_name,
)
onnx_bytes_obj = OnnxBytes.from_bytes(onnx_bytes)
# Write the onnx model to the specified directory without cleaning it
onnx_bytes_obj.write_to_disk(os.path.dirname(onnx_save_path), clean_dir=False)
```
## Testing
N/A. Existing tests are modified.
## Before your PR is "*Ready for review*"
<!-- If you haven't finished some of the above items you can still open
`Draft` PR. -->
- **Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/CONTRIBUTING.md)**
and your commits are signed.
- **Is this change backward compatible?**: Yes <!--- If No, explain why.
-->
- **Did you write any new necessary tests?**: Yes
- **Did you add or update any necessary documentation?**: Yes
- **Did you update
[Changelog](https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/CHANGELOG.rst)?**:
Yes<!--- Only for new features, API changes, critical bug fixes or bw
breaking changes. -->
## Additional Information
https://nvbugspro.nvidia.com/bug/5618246/4
Signed-off-by: Riyad Islam <[email protected]>
Signed-off-by: mxin <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Type of change: Bug
Overview:
get_onnx_bytesapi is error prone as it returns only the protobuf info. If model has any external data, they get discarded! We have to useget_onnx_bytes_and_metadataand provide example for users to correctly write ONNX model to disk.Usage
This would be proper way to save ONNX model bytes with/without external data.
Testing
N/A. Existing tests are modified.
Before your PR is "Ready for review"
Additional Information
https://nvbugspro.nvidia.com/bug/5618246/4