Skip to content

Add in-tree isaac_deploy_trt and optimize_graph TensorRT rewrite. - #16

Open
northernLights6 wants to merge 5 commits into
nvidia-isaac:mainfrom
northernLights6:tao/inference_trt
Open

northernLights6 wants to merge 5 commits into
nvidia-isaac:mainfrom
northernLights6:tao/inference_trt

Conversation

@northernLights6

Copy link
Copy Markdown

Vendors TensorRT ONNX surgery under packages/isaac_deploy_trt, exposes optimize_graph(trt_compatible=True) after compile_graph, and stamps YAML checksums plus parameters.tensorrt_compatible on exported ONNX models.

Vendors TensorRT ONNX surgery under packages/isaac_deploy_trt, exposes
optimize_graph(trt_compatible=True) after compile_graph, and stamps YAML
checksums plus parameters.tensorrt_compatible on exported ONNX models.
@frlai
frlai self-requested a review October 27, 2026 16:28

@frlai frlai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a few major issues that will cause bugs if not taken care of. additionally, I think a major design choice is to only enable optimizations inside the optimize_graph() leapp lifecycle function and not allow optimizations the export cycle. this should help us better separate concerns and keep all the trt related stuff inside the package.

Finally, it would be good if we can revisit the optimize_graph() api. we might want to be able to add more options to it for future expandability.

Comment thread leapp/cli.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets remove this file. Not sure if it is needed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the generation tool. I recall it requires internal docs/repos right? That means a user won't be able to run this either way. Just for my information, would it be a good idea to not release the scripts folder at all?


``optimization``
Present on ONNX backends unless
``backend_params={"annotate_tensorrt_compatible": False}``.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets not have this option. we can centralize all the optimizations in the optimize_graph api

interop). Use this only to test whether those patches are involved in
a failure.

TensorRT catalog and optimize

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this deserves its own docs page. can you move make a new page called something like optimizations? keep it next to debugging.

``opset_version``
Present on ONNX backends. The ONNX opset used at export.

``optimization``

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should go into parameters, optimization should be centralized in optimize graph. when building the onnx file we should not be able to replace with tensorrt compatible ops.

Comment thread leapp/leapp.py
_get_logger().section("Graph optimization: trt_compatible")
result = rewrite_leapp_export_for_tensorrt(save_path)
rewritten = [model.filename for model in result.models if model.rewritten]
if rewritten:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if rewritten we should also update the yaml and the model hash.
previously we kept that in the onnx backend but doing it here is probably cleaner.

Comment thread leapp/leapp.py
return True


def optimize_graph(trt_compatible=False):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure this handles the case where one or some models aren't onnx.
there should also be some sort of way to only select a few models to do the optimizations for?

maybe something like

optimize_graph(validate_trt=['model 1', 'model 2'])
or also
optimize_graph(validate_trt=['all'])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considering future expansions, I am also considering maybe we have a more complex system for more fine grained control?

perhaps

leapp.apply_optimizations('model 1' : [leapp.trt_compatibility(), leapp.quantization('fp16')], 'model_2' : [...])

just a thought.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agent commented that if we install this with pip, somehow we are missing the catalogs. Might need to explicitly package them inside the pyproject.

Comment thread leapp/leapp.py
"Pass trt_compatible=True to optimize ONNX for TensorRT."
)

return applied

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we change numerical behavior, it would be best to run a validation run with configurable tolerance just like the compile graph if any changes were applied to make sure the export with the changes is within tolerance.

This should be similar to how compile graph does it.


graph = load_graph(src)
rewritten_nodes = apply_tensorrt_rewrites(graph, surgeon_ops=surgeon_ops)
save_graph(graph, dst)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent noticed that:
When the input ONNX uses external weights and this rewrite branch runs, saving into a different directory leaves the output referencing external data that hasn’t been copied. For example, input/model.onnx references model.onnx.data, but the output directory receives only model.onnx; loading it then fails because the weights file is missing.

I think the solution is we need to check if the onnx file has external data and also copy that over.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants