This is an automated email from the ASF dual-hosted git repository.
ruihangl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 2601733f56 [Relax] ingest Tensor.contiguous from torch export (#17728)
2601733f56 is described below
commit 2601733f56652103f757a7a393a3d2c4b6b75b1e
Author: Hugo Latendresse <[email protected]>
AuthorDate: Mon Mar 10 11:11:13 2025 -0400
[Relax] ingest Tensor.contiguous from torch export (#17728)
Implement Tensor.contiguous() as a no-op in the exported
program translator and added a unit test
---
.../frontend/torch/exported_program_translator.py | 1 +
.../relax/test_frontend_from_exported_program.py | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/python/tvm/relax/frontend/torch/exported_program_translator.py
b/python/tvm/relax/frontend/torch/exported_program_translator.py
index c8d9d12505..335de7a240 100644
--- a/python/tvm/relax/frontend/torch/exported_program_translator.py
+++ b/python/tvm/relax/frontend/torch/exported_program_translator.py
@@ -285,6 +285,7 @@ class ExportedProgramImporter(BaseFXGraphImporter):
# tensor creation
"_to_copy.default": self._to_copy,
"arange.start": self._arange,
+ "contiguous.default": lambda node: self.env[node.args[0]], # no-op
"clone.default": lambda node: self.env[node.args[0]],
"empty.memory_format": self._empty,
"fill.Scalar": self._fill,
diff --git a/tests/python/relax/test_frontend_from_exported_program.py
b/tests/python/relax/test_frontend_from_exported_program.py
index 8ca335c2fe..6406610bf5 100644
--- a/tests/python/relax/test_frontend_from_exported_program.py
+++ b/tests/python/relax/test_frontend_from_exported_program.py
@@ -2930,6 +2930,26 @@ def test_arange():
verify_model(Arange(), example_args, {}, Expected)
+def test_contiguous():
+ class Contiguous(Module):
+ def forward(self, input):
+ return input.contiguous()
+
+ @tvm.script.ir_module
+ class Expected:
+ @R.function
+ def main(
+ input: R.Tensor((10, 10), dtype="float32"),
+ ) -> R.Tuple(R.Tensor((10, 10), dtype="float32")):
+ with R.dataflow():
+ gv: R.Tuple(R.Tensor((10, 10), dtype="float32")) = (input,)
+ R.output(gv)
+ return gv
+
+ example_args = (torch.randn(10, 10, dtype=torch.float32),)
+ verify_model(Contiguous(), example_args, {}, Expected)
+
+
def test_clone():
class Clone(Module):
def forward(self, input):