From 1646a522351dd7e81174e69aad54767317e3d3bc Mon Sep 17 00:00:00 2001 From: tlopex <820958424@qq.com> Date: Sat, 25 Oct 2025 15:31:39 -0400 Subject: [PATCH 1/2] finish1: --- .../frontend/torch/exported_program_translator.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/python/tvm/relax/frontend/torch/exported_program_translator.py b/python/tvm/relax/frontend/torch/exported_program_translator.py index a84c35e62234..9a93bd663132 100644 --- a/python/tvm/relax/frontend/torch/exported_program_translator.py +++ b/python/tvm/relax/frontend/torch/exported_program_translator.py @@ -907,6 +907,8 @@ def create_convert_map( "pow.Scalar": self._binary_op(relax.op.power, operator.pow), "pow.Tensor_Scalar": self._binary_op(relax.op.power, operator.pow), "pow.Tensor_Tensor": self._binary_op(relax.op.power, operator.pow), + # Decomposed operators + "mul.Tensor": self._binary_op(relax.op.multiply, operator.mul), "sub.Tensor": self._binary_op(relax.op.subtract, operator.sub), "__and__.Tensor": self._binary_op(relax.op.bitwise_and, operator.and_), "__and__.Scalar": self._binary_op(relax.op.bitwise_and, operator.and_), @@ -1197,6 +1199,7 @@ def from_exported_program( keep_params_as_input: bool = False, unwrap_unit_return_tuple: bool = False, no_bind_return_tuple: bool = False, + run_ep_decomposition: bool = False, ) -> tvm.IRModule: """Convert a PyTorch ExportedProgram to a Relax program @@ -1216,6 +1219,12 @@ def from_exported_program( A boolean flag indicating whether to bind the return tuple as a relax var. If the flag is true and the return value is a tuple, it will not bind it to a var. + run_ep_decomposition : bool + A boolean flag indicating whether to run PyTorch's decomposition on the + exported program before translation. When True, high-level operators will + be decomposed into their constituent parts. Defaults to False for backward + compatibility. + Returns ------- output : tvm.IRModule @@ -1255,8 +1264,9 @@ def forward(self, input): # Use the importer to import the ExportedProgram to Relax. mod: tvm.IRModule = from_exported_program(exported_program) """ - # decompose into Core ATen operators - exported_program.run_decompositions() + # Conditionally decompose into Core ATen operators + if run_ep_decomposition: + exported_program = exported_program.run_decompositions() return ExportedProgramImporter().from_exported_program( exported_program, From 86501eda45e96f1fb5564d1cb54d14dea6b17101 Mon Sep 17 00:00:00 2001 From: tlopex <820958424@qq.com> Date: Sat, 25 Oct 2025 15:36:24 -0400 Subject: [PATCH 2/2] finish2 --- python/tvm/relax/frontend/torch/exported_program_translator.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/python/tvm/relax/frontend/torch/exported_program_translator.py b/python/tvm/relax/frontend/torch/exported_program_translator.py index 9a93bd663132..67d93b066972 100644 --- a/python/tvm/relax/frontend/torch/exported_program_translator.py +++ b/python/tvm/relax/frontend/torch/exported_program_translator.py @@ -907,8 +907,6 @@ def create_convert_map( "pow.Scalar": self._binary_op(relax.op.power, operator.pow), "pow.Tensor_Scalar": self._binary_op(relax.op.power, operator.pow), "pow.Tensor_Tensor": self._binary_op(relax.op.power, operator.pow), - # Decomposed operators - "mul.Tensor": self._binary_op(relax.op.multiply, operator.mul), "sub.Tensor": self._binary_op(relax.op.subtract, operator.sub), "__and__.Tensor": self._binary_op(relax.op.bitwise_and, operator.and_), "__and__.Scalar": self._binary_op(relax.op.bitwise_and, operator.and_),