Conversation

cehongwang

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

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

@github-actions-actions bot added component: api [Python]Issues re: Python APIcomponent: runtime component: dynamoIssues relating to the `torch.compile` or `torch._dynamo.export` pathslabels Jun 13, 2025
@github-actions-actions bot requested a review from peri044 June 13, 2025 19:19

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/dynamo/runtime/_TorchTensorRTModule.py	2025-06-13 19:19:30.680941+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/runtime/_TorchTensorRTModule.py	2025-06-13 19:19:58.614974+00:00
@@ -225,20 +225,28 @@
            return
        self.engine = torch.classes.tensorrt.Engine(self._pack_engine_info())

    def encode_metadata(self, metadata: Any) -> str:
        metadata = copy.deepcopy(metadata)
-        metadata["settings"].torch_executed_ops = TorchTensorRTModule.serialize_aten_ops(metadata["settings"].torch_executed_ops)
+        metadata["settings"].torch_executed_ops = (
+            TorchTensorRTModule.serialize_aten_ops(
+                metadata["settings"].torch_executed_ops
+            )
+        )
        dumped_metadata = pickle.dumps(metadata)
        encoded_metadata = base64.b64encode(dumped_metadata).decode("utf-8")
        return encoded_metadata

    @staticmethod
    def decode_metadata(encoded_metadata: bytes) -> Any:
        dumped_metadata = base64.b64decode(encoded_metadata.encode("utf-8"))
        metadata = pickle.loads(dumped_metadata)
-        metadata["settings"].torch_executed_ops = TorchTensorRTModule.deserialize_aten_ops(metadata["settings"].torch_executed_ops)
+        metadata["settings"].torch_executed_ops = (
+            TorchTensorRTModule.deserialize_aten_ops(
+                metadata["settings"].torch_executed_ops
+            )
+        )
        return metadata

    @staticmethod
    def serialize_aten_ops(aten_ops: Set[torch._ops.OpOverload]) -> Set[str]:
        return {str(op) for op in aten_ops}

return metadata

@staticmethod
def serialize_aten_ops(aten_ops: Set[torch._ops.OpOverload]) -> Set[str]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

call this _serialize_torch_ops

Choose a reason for hiding this comment

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

Should we associate this function with CompileSettings not the TorchTensorRTModule? as something like getstate /setstate

@cehongwangcehongwang force-pushed the cehongwang--1 branch 2 times, most recently from 1f50da4 to 0b3edfe Compare June 16, 2025 20:46

Choose a reason for hiding this comment

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

LGTM can you add a testcase for the serialization? Just save and load a module that uses torch_executed_ops?

@github-actions-actions bot added the component: testsIssues re: Testslabel Jun 16, 2025
@@ -372,6 +372,36 @@ def test_resnet18_dynamic(ir):
)


@pytest.mark.unit
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just add this to help @lanluo-nvidia out

@unittest.skipIf(
        not importlib.util.find_spec("torchvision"), "torchvision not installed"
    )

Then feel free to merge

@@ -84,6 +84,41 @@ def test_resnet18_cpu_offload(ir):
torch._dynamo.reset()


@pytest.mark.unit
def test_resnet18_torch_exec_ops(ir):
Copy link
Collaborator

Choose a reason for hiding this comment

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

@unittest.skipIf(
not importlib.util.find_spec("torchvision"), "torchvision not installed"
)
Same here

Choose a reason for hiding this comment

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

LGTM just add the skips for the tests

Sign up for free to join this conversation on . Already have an account? Sign in to comment
cla signed component: api [Python]Issues re: Python APIcomponent: dynamoIssues relating to the `torch.compile` or `torch._dynamo.export` pathscomponent: testsIssues re: Tests
None yet

Successfully merging this pull request may close these issues.

🐛 [Bug] Using torch_executed_ops causes the metadata packing to fail