bhahn221 opened a new issue #8881:
URL: https://github.com/apache/tvm/issues/8881


   First, I generated a network with `torch.rand` using following code
   ```
   import torch
   from torch import nn
   
   class Net(nn.Module):
       def __init__(self, input_shape=(-1, 3, 224, 224)):
           super().__init__()
           self.given_shape = input_shape[1:]
   
       def forward(self, x):
           return x + torch.rand(size=self.given_shape, device=x.device)
   
   net = Net()
   
   traced_net = torch.jit.trace(net, torch.rand(1, 3, 224, 224))
   traced_net.save("random-trace.pt")
   ```
   
   I want to compile this net down to Relay IR.
   My initial stab at this looks like this:
   ```
   import tvm
   from tvm import relay
   
   import torch
   loaded_model = torch.jit.load("random-trace.pt")
   relay_model = relay.frontend.from_pytorch(script_module=loaded_model, 
       input_infos=[("input0", (1, 3, 224, 224))])
   ```
   
   This gave me:
   > NotImplementedError: The following operators are not implemented: 
['aten::rand']
   
   
   My next try used `custom_convert_map`
   ```
   import tvm
   from tvm import relay
   
   import torch
   
   loaded_model = torch.jit.load("random-trace.pt")
   relay_model = relay.frontend.from_pytorch(script_module=loaded_model, 
       input_infos=[("input0", (1, 3, 224, 224))],
       custom_convert_map={
           "aten::rand": 
relay.op.random.uniform(key=relay.op.random.threefry_key(0), shape=(3, 224, 
224))
       }
   )
   ```
   
   However, this gave me:
   >   Check failed: (!checked_type.defined()) is false: Expected 
Array[RelayExpr], but got Array[index 0: Array]
   
   
   I think I am doing completely wrong here so I am wondering if I can get some 
help with this.
   My question in one line would be "how can I compile networks with 
`torch.rand` or `torch.randn`?"


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