mshr-h commented on issue #17546:
URL: https://github.com/apache/tvm/issues/17546#issuecomment-2540695118

   Seems like the torch.nn.Linear converter is the root of the problem.
   Minimum repro.
   
   ```python
   import tvm
   import torch
   import onnx
   from tvm import relay
   import os
   
   
   class LinearModel(torch.nn.Module):
       def __init__(self, *args, **kwargs):
           super().__init__(*args, **kwargs)
           self.linear = torch.nn.Linear(in_features=128, out_features=512, 
bias=True)
   
       def forward(self, x: torch.Tensor) -> torch.Tensor:
           return self.linear(x)
   
   
   def main():
       target = "llvm"
       dummy_input = torch.randn(2, 56, 56, 128)
   
       linear_model = LinearModel()
   
       # torch frontend
       trace_model = torch.jit.trace(linear_model, dummy_input).eval()
   
       mod, params = relay.frontend.from_pytorch(trace_model, [("input", 
dummy_input.shape)])
       with tvm.transform.PassContext(opt_level=3):
           lib = relay.build(mod, target, params=params)
   
       lib.export_library("linear_model_torch.so")
   
       # onnx frontend
       torch.onnx.export(
           linear_model,
           dummy_input,
           "linear_model_onnx.onnx",
           input_names=["input"],
           opset_version=13,
       )
   
       onnx_model = onnx.load("linear_model_onnx.onnx")
       mod, params = relay.frontend.from_onnx(onnx_model, {"input": 
dummy_input.shape})
   
       with tvm.transform.PassContext(opt_level=3):
           lib = relay.build(mod, target, params=params)
   
       lib.export_library("linear_model_onnx.so")
   
       print("File size")
       print("  linear_model_torch.so : ", 
os.path.getsize("linear_model_torch.so"))
       print("  linear_model_onnx.onnx: ", 
os.path.getsize("linear_model_onnx.onnx"))
       print("  linear_model_onnx.so  : ", 
os.path.getsize("linear_model_onnx.so"))
   
   
   if __name__ == "__main__":
       main()
   ```


-- 
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