Pratheesh-04-MCW opened a new issue, #17959:
URL: https://github.com/apache/tvm/issues/17959

   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 
<module>
       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)
   
   # Create input tensor
   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)
   
   # Build the VM executable
   with tvm.transform.PassContext(opt_level=3):
       ex = relax.build(relax_mod, target)
   
   # Create and run the VM
   vm = tvm.runtime.relax_vm.VirtualMachine(ex, device)
   
   # Prepare input (convert PyTorch tensor to TVM NDArray)
   input_data = tvm.nd.array(a.numpy(), device=device)
   
   # Run the VM
   result = vm["main"](input_data)
   
   # Extract the tensor from the tuple
   result_tensor = result[0]  # The tuple contains a single tensor
   
   # Show results
   print("\nInput tensor:")
   print(input_data.numpy())
   
   print("\nOutput tensor (fractional parts):")
   print(result_tensor.numpy())
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to