How to use "surgeon sanitize" of polygraphy using python API?

Description

I want to include the “surgeon sanitize” of polygraphy in my python script, but I don’t find the way to do that.
Is it possible to do that? there is API fot the sanitize option?

Environment

NA

Relevant Files

NA

Steps To Reproduce

NA

Hi,

Please checkout TensorRT/tools/Polygraphy/examples/api at main · NVIDIA/TensorRT · GitHub, which may help you.

Thank you.

The easiest way would be to run it using subprocess:

sp.run(["polygraphy", "surgeon", "sanitize", ...])

Otherwise, you can refer to the source code here to see what it’s doing.

Assuming you just want the constant folding functionality, something like this should work:

from polygraphy.backend.onnx import fold_constants

model = onnx.load("/path/to/model.onnx")
folded = fold_constants(model)

Thank you, that’s what I was looking for

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.