diff --git a/monai/networks/utils.py b/monai/networks/utils.py index 05627f9c00..1b4cb220ae 100644 --- a/monai/networks/utils.py +++ b/monai/networks/utils.py @@ -712,9 +712,10 @@ def convert_to_onnx( onnx_model = onnx.load(f) if do_constant_folding and polygraphy_imported: - from polygraphy.backend.onnx.loader import fold_constants + from polygraphy.backend.onnx.loader import fold_constants, save_onnx - fold_constants(onnx_model, size_threshold=constant_size_threshold) + onnx_model = fold_constants(onnx_model, size_threshold=constant_size_threshold) + save_onnx(onnx_model, f) if verify: if isinstance(inputs, dict): diff --git a/tests/test_trt_compile.py b/tests/test_trt_compile.py index 9716a4a715..e1323c201f 100644 --- a/tests/test_trt_compile.py +++ b/tests/test_trt_compile.py @@ -61,7 +61,7 @@ def tearDown(self): if current_device != self.gpu_device: torch.cuda.set_device(self.gpu_device) - @unittest.skipUnless(torch_trt_imported, "torch_tensorrt is required") + # @unittest.skipUnless(torch_trt_imported, "torch_tensorrt is required") def test_handler(self): from ignite.engine import Engine @@ -74,7 +74,7 @@ def test_handler(self): with tempfile.TemporaryDirectory() as tempdir: engine = Engine(lambda e, b: None) - args = {"method": "torch_trt"} + args = {"method": "onnx", "dynamic_batchsize": [1, 4, 8]} TrtHandler(net1, tempdir + "/trt_handler", args=args).attach(engine) engine.run([0] * 8, max_epochs=1) self.assertIsNotNone(net1._trt_compiler) @@ -86,7 +86,11 @@ def test_lists(self): model = ListAdd().cuda() with torch.no_grad(), tempfile.TemporaryDirectory() as tmpdir: - args = {"output_lists": [[-1], [2], []], "export_args": {"dynamo": False, "verbose": True}} + args = { + "output_lists": [[-1], [2], []], + "export_args": {"dynamo": False, "verbose": True}, + "dynamic_batchsize": [1, 4, 8], + } x = torch.randn(1, 16).to("cuda") y = torch.randn(1, 16).to("cuda") z = torch.randn(1, 16).to("cuda")