Files
Model-Optimizer/tests/unit/torch/deploy
Riyad Islam c3f6cef87e ONNX save fix (#496)
## 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 <rislam@nvidia.com>
2025-11-05 09:18:56 +05:30
..
2025-11-05 09:18:56 +05:30