From afe44f92de264af2e582a5db56f74d8fd83106dc Mon Sep 17 00:00:00 2001 From: Hehang Shuai <152275085+V-aerus@users.noreply.github.com> Date: Sat, 4 Jul 2026 12:04:23 +0800 Subject: [PATCH] [Relax][PyTorch] Support aten.scatter.src in ExportedProgram importer --- .../torch/exported_program_translator.py | 1 + .../test_frontend_from_exported_program.py | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/python/tvm/relax/frontend/torch/exported_program_translator.py b/python/tvm/relax/frontend/torch/exported_program_translator.py index 79882e8f4441..c427ed1ba03c 100644 --- a/python/tvm/relax/frontend/torch/exported_program_translator.py +++ b/python/tvm/relax/frontend/torch/exported_program_translator.py @@ -1768,6 +1768,7 @@ def create_convert_map( "round.default": self._round, "rsqrt.default": self._rsqrt, "scalar_tensor.default": self._scalar_tensor, + "scatter.src": self._scatter, "scatter.value": self._scatter_value, "rsub.Tensor": self._rsub, "rsub.Scalar": self._rsub, diff --git a/tests/python/relax/test_frontend_from_exported_program.py b/tests/python/relax/test_frontend_from_exported_program.py index d91aa46f219b..0e7e070d2a50 100644 --- a/tests/python/relax/test_frontend_from_exported_program.py +++ b/tests/python/relax/test_frontend_from_exported_program.py @@ -8973,6 +8973,35 @@ def main( verify_model(ScatterValue(), example_args, {}, Expected) +def test_scatter_src(): + class ScatterSrc(Module): + def forward(self, x, index, src): + return x.scatter(1, index, src) + + @I.ir_module + class Expected: + @R.function + def main( + x: R.Tensor((4, 8), dtype="float32"), + index: R.Tensor((4, 2), dtype="int64"), + src: R.Tensor((4, 2), dtype="float32"), + ) -> R.Tuple(R.Tensor((4, 8), dtype="float32")): + with R.dataflow(): + lv: R.Tensor((4, 8), dtype="float32") = R.scatter_elements( + x, index, src, axis=1 + ) + gv: R.Tuple(R.Tensor((4, 8), dtype="float32")) = (lv,) + R.output(gv) + return gv + + example_args = ( + torch.randn(4, 8, dtype=torch.float32), + torch.randint(0, 8, (4, 2), dtype=torch.int64), + torch.randn(4, 2, dtype=torch.float32), + ) + verify_model(ScatterSrc(), example_args, {}, Expected) + + def test_grid_sample(): class GridSample(Module): def forward(self, input, grid):