Skip to content

Conversation

@lanluo-nvidia
Copy link
Collaborator

@lanluo-nvidia lanluo-nvidia commented Nov 23, 2025

Description

two changes:

  1. thor non_zero is fixed in trt 14, reenable back the converter and tests
  2. save engine to /tmp/trt.ep has side effect when run the tests in parallel in dlfw
    change to the unique tmp dir so that test run in parallel won't mixed up

Fixes # (issue)

Type of change

Please delete options that are not relevant and/or add your own.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@meta-cla meta-cla bot added the cla signed label Nov 23, 2025
@github-actions github-actions bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Nov 23, 2025
@github-actions github-actions bot requested a review from peri044 November 23, 2025 04:44
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_serde.py	2025-11-23 04:44:15.040051+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_serde.py	2025-11-23 04:44:58.015912+00:00
@@ -15,10 +15,11 @@

assertions = unittest.TestCase()
if importlib.util.find_spec("torchvision"):
    import torchvision.models as models

+
@pytest.mark.unit
@pytest.mark.critical
def test_base_full_compile(ir):
    """
    This tests export serde functionality on a base model
--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_kwargs_serde.py	2025-11-23 04:44:15.040051+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_kwargs_serde.py	2025-11-23 04:44:58.214570+00:00
@@ -299,11 +299,13 @@
    assertions.assertTrue(
        cos_sim > COSINE_THRESHOLD,
        msg=f"CustomKwargs Module TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
    )
    # Save the module
-    tmp_dir = tempfile.mkdtemp(prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    torchtrt.save(trt_gm, trt_ep_path, retrace=False)
    # Clean up model env
    torch._dynamo.reset()

@@ -390,11 +392,13 @@
    assertions.assertTrue(
        cos_sim > COSINE_THRESHOLD,
        msg=f"CustomKwargs Module TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
    )
    # Save the module
-    tmp_dir = tempfile.mkdtemp(prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    torchtrt.save(trt_gm, trt_ep_path, retrace=False)
    # Clean up model env
    torch._dynamo.reset()

--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_model_refit.py	2025-11-23 04:44:15.040051+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_model_refit.py	2025-11-23 04:44:58.911484+00:00
@@ -530,11 +530,13 @@
    not torch_trt.ENABLED_FEATURES.refit,
    "Refit feature is not supported in Python 3.13 or higher",
)
@pytest.mark.unit
def test_refit_one_engine_inline_runtime_with_weightmap():
-    tmp_dir = tempfile.mkdtemp(prefix="test_refit_one_engine_inline_runtime_with_weightmap")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_refit_one_engine_inline_runtime_with_weightmap"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    model = models.resnet18(pretrained=False).eval().to("cuda")
    model2 = models.resnet18(pretrained=True).eval().to("cuda")
    inputs = [torch.randn((1, 3, 224, 224)).to("cuda")]
    enabled_precisions = {torch.float}
@@ -888,11 +890,13 @@
    not torch_trt.ENABLED_FEATURES.refit,
    "Refit feature is not supported in Python 3.13 or higher",
)
@pytest.mark.unit
def test_refit_one_engine_inline_runtime_without_weightmap():
-    tmp_dir = tempfile.mkdtemp(prefix="test_refit_one_engine_inline_runtime_without_weightmap")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_refit_one_engine_inline_runtime_without_weightmap"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    model = models.resnet18(pretrained=True).eval().to("cuda")
    model2 = models.resnet18(pretrained=False).eval().to("cuda")
    inputs = [torch.randn((1, 3, 224, 224)).to("cuda")]
    enabled_precisions = {torch.float}
--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_reexport.py	2025-11-23 04:44:15.040051+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_reexport.py	2025-11-23 04:44:59.288504+00:00
@@ -158,10 +158,11 @@
        def forward(self, x):
            conv = self.conv(x)
            conv = conv * 0.5
            relu = self.relu(conv)
            return conv, relu
+
    tmp_dir = tempfile.mkdtemp(prefix="test_no_compile")
    trt_ep_path = os.path.join(tmp_dir, "trt.ep")
    model = MyModule().eval().cuda()
    input = torch.randn((1, 3, 224, 224)).to("cuda")

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_kwargs_serde.py	2025-11-23 04:46:35.093132+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_kwargs_serde.py	2025-11-23 04:47:21.201660+00:00
@@ -299,11 +299,13 @@
    assertions.assertTrue(
        cos_sim > COSINE_THRESHOLD,
        msg=f"CustomKwargs Module TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
    )
    # Save the module
-    tmp_dir = tempfile.mkdtemp(prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    torchtrt.save(trt_gm, trt_ep_path, retrace=False)
    # Clean up model env
    torch._dynamo.reset()

@@ -390,11 +392,13 @@
    assertions.assertTrue(
        cos_sim > COSINE_THRESHOLD,
        msg=f"CustomKwargs Module TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
    )
    # Save the module
-    tmp_dir = tempfile.mkdtemp(prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    torchtrt.save(trt_gm, trt_ep_path, retrace=False)
    # Clean up model env
    torch._dynamo.reset()

--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_serde.py	2025-11-23 04:46:35.093132+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_serde.py	2025-11-23 04:47:21.577144+00:00
@@ -15,10 +15,11 @@

assertions = unittest.TestCase()
if importlib.util.find_spec("torchvision"):
    import torchvision.models as models

+
@pytest.mark.unit
@pytest.mark.critical
def test_base_full_compile(ir):
    """
    This tests export serde functionality on a base model
--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_model_refit.py	2025-11-23 04:46:35.093132+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_model_refit.py	2025-11-23 04:47:22.496365+00:00
@@ -530,11 +530,13 @@
    not torch_trt.ENABLED_FEATURES.refit,
    "Refit feature is not supported in Python 3.13 or higher",
)
@pytest.mark.unit
def test_refit_one_engine_inline_runtime_with_weightmap():
-    tmp_dir = tempfile.mkdtemp(prefix="test_refit_one_engine_inline_runtime_with_weightmap")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_refit_one_engine_inline_runtime_with_weightmap"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    model = models.resnet18(pretrained=False).eval().to("cuda")
    model2 = models.resnet18(pretrained=True).eval().to("cuda")
    inputs = [torch.randn((1, 3, 224, 224)).to("cuda")]
    enabled_precisions = {torch.float}
@@ -888,11 +890,13 @@
    not torch_trt.ENABLED_FEATURES.refit,
    "Refit feature is not supported in Python 3.13 or higher",
)
@pytest.mark.unit
def test_refit_one_engine_inline_runtime_without_weightmap():
-    tmp_dir = tempfile.mkdtemp(prefix="test_refit_one_engine_inline_runtime_without_weightmap")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_refit_one_engine_inline_runtime_without_weightmap"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    model = models.resnet18(pretrained=True).eval().to("cuda")
    model2 = models.resnet18(pretrained=False).eval().to("cuda")
    inputs = [torch.randn((1, 3, 224, 224)).to("cuda")]
    enabled_precisions = {torch.float}
--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_reexport.py	2025-11-23 04:46:35.093132+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_reexport.py	2025-11-23 04:47:22.542164+00:00
@@ -158,10 +158,11 @@
        def forward(self, x):
            conv = self.conv(x)
            conv = conv * 0.5
            relu = self.relu(conv)
            return conv, relu
+
    tmp_dir = tempfile.mkdtemp(prefix="test_no_compile")
    trt_ep_path = os.path.join(tmp_dir, "trt.ep")
    model = MyModule().eval().cuda()
    input = torch.randn((1, 3, 224, 224)).to("cuda")

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_serde.py	2025-11-23 04:48:33.156579+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_serde.py	2025-11-23 04:49:18.306172+00:00
@@ -15,10 +15,11 @@

assertions = unittest.TestCase()
if importlib.util.find_spec("torchvision"):
    import torchvision.models as models

+
@pytest.mark.unit
@pytest.mark.critical
def test_base_full_compile(ir):
    """
    This tests export serde functionality on a base model
--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_kwargs_serde.py	2025-11-23 04:48:33.156579+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_kwargs_serde.py	2025-11-23 04:49:18.559689+00:00
@@ -299,11 +299,13 @@
    assertions.assertTrue(
        cos_sim > COSINE_THRESHOLD,
        msg=f"CustomKwargs Module TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
    )
    # Save the module
-    tmp_dir = tempfile.mkdtemp(prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    torchtrt.save(trt_gm, trt_ep_path, retrace=False)
    # Clean up model env
    torch._dynamo.reset()

@@ -390,11 +392,13 @@
    assertions.assertTrue(
        cos_sim > COSINE_THRESHOLD,
        msg=f"CustomKwargs Module TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
    )
    # Save the module
-    tmp_dir = tempfile.mkdtemp(prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    torchtrt.save(trt_gm, trt_ep_path, retrace=False)
    # Clean up model env
    torch._dynamo.reset()

--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_reexport.py	2025-11-23 04:48:33.156579+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_reexport.py	2025-11-23 04:49:19.558116+00:00
@@ -158,10 +158,11 @@
        def forward(self, x):
            conv = self.conv(x)
            conv = conv * 0.5
            relu = self.relu(conv)
            return conv, relu
+
    tmp_dir = tempfile.mkdtemp(prefix="test_no_compile")
    trt_ep_path = os.path.join(tmp_dir, "trt.ep")
    model = MyModule().eval().cuda()
    input = torch.randn((1, 3, 224, 224)).to("cuda")

--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_model_refit.py	2025-11-23 04:48:33.156579+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_model_refit.py	2025-11-23 04:49:19.609943+00:00
@@ -530,11 +530,13 @@
    not torch_trt.ENABLED_FEATURES.refit,
    "Refit feature is not supported in Python 3.13 or higher",
)
@pytest.mark.unit
def test_refit_one_engine_inline_runtime_with_weightmap():
-    tmp_dir = tempfile.mkdtemp(prefix="test_refit_one_engine_inline_runtime_with_weightmap")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_refit_one_engine_inline_runtime_with_weightmap"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    model = models.resnet18(pretrained=False).eval().to("cuda")
    model2 = models.resnet18(pretrained=True).eval().to("cuda")
    inputs = [torch.randn((1, 3, 224, 224)).to("cuda")]
    enabled_precisions = {torch.float}
@@ -888,11 +890,13 @@
    not torch_trt.ENABLED_FEATURES.refit,
    "Refit feature is not supported in Python 3.13 or higher",
)
@pytest.mark.unit
def test_refit_one_engine_inline_runtime_without_weightmap():
-    tmp_dir = tempfile.mkdtemp(prefix="test_refit_one_engine_inline_runtime_without_weightmap")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_refit_one_engine_inline_runtime_without_weightmap"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    model = models.resnet18(pretrained=True).eval().to("cuda")
    model2 = models.resnet18(pretrained=False).eval().to("cuda")
    inputs = [torch.randn((1, 3, 224, 224)).to("cuda")]
    enabled_precisions = {torch.float}

@lanluo-nvidia lanluo-nvidia marked this pull request as ready for review November 23, 2025 04:58
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_kwargs_serde.py	2025-11-23 04:58:27.029037+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_kwargs_serde.py	2025-11-23 04:59:09.451767+00:00
@@ -299,11 +299,13 @@
    assertions.assertTrue(
        cos_sim > COSINE_THRESHOLD,
        msg=f"CustomKwargs Module TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
    )
    # Save the module
-    tmp_dir = tempfile.mkdtemp(prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    torchtrt.save(trt_gm, trt_ep_path, retrace=False)
    # Clean up model env
    torch._dynamo.reset()

@@ -390,11 +392,13 @@
    assertions.assertTrue(
        cos_sim > COSINE_THRESHOLD,
        msg=f"CustomKwargs Module TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}",
    )
    # Save the module
-    tmp_dir = tempfile.mkdtemp(prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    torchtrt.save(trt_gm, trt_ep_path, retrace=False)
    # Clean up model env
    torch._dynamo.reset()

--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_serde.py	2025-11-23 04:58:27.029037+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_export_serde.py	2025-11-23 04:59:09.545289+00:00
@@ -15,10 +15,11 @@

assertions = unittest.TestCase()
if importlib.util.find_spec("torchvision"):
    import torchvision.models as models

+
@pytest.mark.unit
@pytest.mark.critical
def test_base_full_compile(ir):
    """
    This tests export serde functionality on a base model
--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_model_refit.py	2025-11-23 04:58:27.029037+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_model_refit.py	2025-11-23 04:59:10.265129+00:00
@@ -530,11 +530,13 @@
    not torch_trt.ENABLED_FEATURES.refit,
    "Refit feature is not supported in Python 3.13 or higher",
)
@pytest.mark.unit
def test_refit_one_engine_inline_runtime_with_weightmap():
-    tmp_dir = tempfile.mkdtemp(prefix="test_refit_one_engine_inline_runtime_with_weightmap")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_refit_one_engine_inline_runtime_with_weightmap"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    model = models.resnet18(pretrained=False).eval().to("cuda")
    model2 = models.resnet18(pretrained=True).eval().to("cuda")
    inputs = [torch.randn((1, 3, 224, 224)).to("cuda")]
    enabled_precisions = {torch.float}
@@ -888,11 +890,13 @@
    not torch_trt.ENABLED_FEATURES.refit,
    "Refit feature is not supported in Python 3.13 or higher",
)
@pytest.mark.unit
def test_refit_one_engine_inline_runtime_without_weightmap():
-    tmp_dir = tempfile.mkdtemp(prefix="test_refit_one_engine_inline_runtime_without_weightmap")
+    tmp_dir = tempfile.mkdtemp(
+        prefix="test_refit_one_engine_inline_runtime_without_weightmap"
+    )
    trt_ep_path = os.path.join(tmp_dir, "compiled.ep")
    model = models.resnet18(pretrained=True).eval().to("cuda")
    model2 = models.resnet18(pretrained=False).eval().to("cuda")
    inputs = [torch.randn((1, 3, 224, 224)).to("cuda")]
    enabled_precisions = {torch.float}
--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_reexport.py	2025-11-23 04:58:27.029037+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/models/test_reexport.py	2025-11-23 04:59:10.616549+00:00
@@ -158,10 +158,11 @@
        def forward(self, x):
            conv = self.conv(x)
            conv = conv * 0.5
            relu = self.relu(conv)
            return conv, relu
+
    tmp_dir = tempfile.mkdtemp(prefix="test_no_compile")
    trt_ep_path = os.path.join(tmp_dir, "trt.ep")
    model = MyModule().eval().cuda()
    input = torch.randn((1, 3, 224, 224)).to("cuda")

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

Labels

cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants