[Bug] Unsupported Function Type 'frac.default' in ExportedProgram and fx_graph Translator
- Dominant language
- Python
- Stars
- 13.7k
- Forks
- 4k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 111
Description
When attempting to convert a PyTorch exported program to TVM's Relax format using from_exported_program(), the process fails with an AssertionError indicating that the function type 'frac.default' is not supported.
## Environment
- tvm 0.21.dev26+g2ca6ec8a5
- torch 2.6.0
## Error Message
warnings.warn("Can't initialize NVML")
Traceback (most recent call last):
File "/home/pratheesh04/tvm/examples/relax_support/frac.py", line 16, in
relax_mod = from_exported_program(exported_program)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pratheesh04/tvm/python/tvm/relax/frontend/torch/exported_program_translator.py", line 679, in from_exported_program
return ExportedProgramImporter().from_exported_program(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pratheesh04/tvm/python/tvm/relax/frontend/torch/exported_program_translator.py", line 544, in from_exported_program
self._check_unsupported_func_type(nodes)
File "/home/pratheesh04/tvm/python/tvm/relax/frontend/torch/base_fx_graph_translator.py", line 114, in _check_unsupported_func_type
assert not missing_func_types, f"Unsupported function types {missing_func_types}"
^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Unsupported function types ['frac.default']
## Expected behavior
Should generate the relax IR:
#from tvm.script import ir as I
#from tvm.script import relax as R
@I.ir_module
class Module:
@R.function
def main(x: R.Tensor((4,), dtype="float32")) -> R.Tuple(R.Tensor((4,), dtype="float32")):
with R.dataflow():
lv: R.Tensor((4,), dtype="float32") = R.frac(x)
gv: R.Tuple(R.Tensor((4,), dtype="float32")) = (lv,)
R.output(gv)
return gv
## Steps to reproduce
import torch
from torch.export import export
from tvm.relax.frontend.torch import from_exported_program
import tvm
from tvm import relax
class FracModel(torch.nn.Module):
def forward(self, x):
return torch.frac(x)
a = torch.tensor([3.4742, 0.5466, -0.8008, -0.9079], dtype=torch.float32)
model = FracModel()
exported_program = export(model, (a,))
relax_mod = from_exported_program(exported_program)
print("Original Relax IR Module:")
print(relax_mod)
target = tvm.target.Target("llvm")
device = tvm.device(target.kind.name)
with tvm.transform.PassContext(opt_level=3):
ex = relax.build(relax_mod, target)
vm = tvm.runtime.relax_vm.VirtualMachine(ex, device)
input_data = tvm.nd.array(a.numpy(), device=device)
result = vm["main"] (input_data)
result_tensor = result[0] # The tuple contains a single tensor
print("\nInput tensor:")
print(input_data.numpy())
print("\nOutput tensor (fractional parts):")
print(result_tensor.numpy())
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with python/tvm/relax/frontend/torch/base_fx_graph_translator.py and exported_program_translator.py, tracing _check_unsupported_func_type and from_exported_program; run the provided torch.frac reproduction. Done means from_exported_program accepts frac.default, produces the shown Relax IR, and the provided build and execution path completes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- compilers, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100