Skip to content

Conversation

narendasan
Copy link
Collaborator

Description

Adds a testcase to cover #3775

Type of change

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

  • Bug fix (non-breaking change which fixes an issue)

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 Aug 14, 2025
@github-actions github-actions bot added component: tests Issues re: Tests component: api [Python] Issues re: Python API labels Aug 14, 2025
@github-actions github-actions bot requested a review from gs-olive August 14, 2025 15:59
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/py/torch_tensorrt/_compile.py	2025-08-14 15:59:14.216704+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/_compile.py	2025-08-14 15:59:39.529516+00:00
@@ -578,11 +578,13 @@

def save(
    module: Any,
    file_path: str = "",
    *,
-    output_format: Literal["exported_program", "torchscript", "aot_inductor"] = "exported_program",
+    output_format: Literal[
+        "exported_program", "torchscript", "aot_inductor"
+    ] = "exported_program",
    inputs: Optional[Sequence[torch.Tensor]] = None,
    arg_inputs: Optional[Sequence[torch.Tensor]] = None,
    kwarg_inputs: Optional[dict[str, Any]] = None,
    retrace: bool = False,
    pickle_protocol: int = 2,
--- /home/runner/work/TensorRT/TensorRT/tests/py/ts/api/test_export_serde.py	2025-08-14 15:59:14.249704+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/ts/api/test_export_serde.py	2025-08-14 15:59:46.067071+00:00
@@ -12,10 +12,11 @@
    cosine_similarity,
    get_model_device,
)

assertions = unittest.TestCase()
+

@pytest.mark.unit
def test_save_load_ts(ir):
    """
    This tests save/load API on Torchscript format (model still compiled using ts workflow)

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/ts/api/test_export_serde.py	2025-08-14 20:24:49.095701+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/ts/api/test_export_serde.py	2025-08-14 20:25:20.385752+00:00
@@ -12,10 +12,11 @@
    cosine_similarity,
    get_model_device,
)

assertions = unittest.TestCase()
+

@pytest.mark.unit
def test_save_load_ts(ir):
    """
    This tests save/load API on Torchscript format (model still compiled using ts workflow)

Comment on lines +49 to +51
torchtrt.save(trt_gm, "./trt.ts", output_format="torchscript", inputs=[input])

trt_ts_module = torchtrt.load("./trt.ts")

Choose a reason for hiding this comment

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

I'd suggest to use the pytest's tmp_path fixture here, so that pytest could automatically cleanup the file once the tests are finished.

@pytest.mark.unit
def test_save_load_ts(ir, tmp_path):
    ...
    trt_file = tmp_path / "trt.ts"
    torchtrt.save(trt_gm, trt_file, output_format="torchscript", inputs=[input])
    
    trt_ts_module = torchtrt.load(trt_file)

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: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants