Skip to content

Commit 89c686c

Browse files
authored
[5591945][5589019@13][ONNX] Fix 'nodes not sorted' failure (#507)
## What does this PR do? **Type of change:** Bug fix **Overview:** Ensure nodes are topologically sorted in ONNX graph. ## Usage ```python python -m modelopt.onnx.quantization --onnx_path=$MODEL_NAME.onnx ``` ## Testing See bug 5591945 (model 4) and 5589019@13. ## 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 - **Did you write any new necessary tests?**: No - **Did you add or update any necessary documentation?**: No - **Did you update [Changelog](https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/CHANGELOG.rst)?**: No --------- Signed-off-by: gcunhase <4861122+gcunhase@users.noreply.github.com>
1 parent 017c11b commit 89c686c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

modelopt/onnx/trt_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ def load_onnx_model(
321321
# Infer types and shapes in the graph for ORT compatibility
322322
onnx_model = infer_types_shapes_tensorrt(onnx_model, trt_plugins or [], all_tensor_info)
323323

324+
# Ensure nodes are topologically sorted
325+
graph = gs.import_onnx(onnx_model)
326+
graph.toposort()
327+
onnx_model = gs.export_onnx(graph)
328+
324329
# Enforce IR version = 10
325330
ir_version_onnx_path = None
326331
if onnx_model.ir_version > MAX_IR_VERSION:

0 commit comments

Comments
 (0)