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


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?



Relevant Files


Steps To Reproduce



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:["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.