masahi commented on issue #12524:
URL: https://github.com/apache/tvm/issues/12524#issuecomment-1221975095
This is an example of "minimal script":
```
import torch
import tvm
from tvm import relay
from tvm.contrib.download import download_testdata
from tvm.contrib import graph_executor
import numpy as np
DEVICE='cpu'
model=torch.load("model.pt", map_location=torch.device('cpu'))
data=torch.load("data2.pt", map_location=torch.device('cpu'))
pt_inp = torch.unsqueeze(data[0][0], 0)
with torch.no_grad():
pt_out = model(pt_inp).numpy()
input_name = "input0"
target = tvm.target.Target("llvm", host="llvm")
dev = tvm.cpu(0)
scripted_model = torch.jit.trace(model, pt_inp).eval()
input_data = pt_inp.numpy()
shape_list = [(input_name, input_data.shape)]
mod, params = relay.frontend.from_pytorch(scripted_model, shape_list)
# print(mod)
with tvm.transform.PassContext(opt_level=3):
lib = relay.build(mod, target=target, params=params)
m = graph_executor.GraphModule(lib["default"](dev))
m.set_input(input_name, tvm.nd.array(pt_inp.numpy()))
m.run()
output = torch.tensor(m.get_output(0).asnumpy())
tvm_out = m.get_output(0).asnumpy()
# print(np.max(np.abs(tvm_out - pt_out)), np.mean(np.abs(tvm_out - pt_out)))
print(pt_out)
```
Running this script, I see PT output like
```
[[-4.39299689e+36 3.77933626e+35 -4.14227049e+36 -4.03090327e+36
-4.95762177e+36 -1.81598428e+36 -1.35176413e+36 1.13814440e+36
-4.90326143e+35 1.11240001e+36 -3.27343576e+36 -4.31897940e+36
-3.87017024e+36 -1.74157477e+36 5.59471333e+35 -2.40675192e+36
-1.40862270e+36 -4.29128504e+36 4.14507723e+35 -5.33183350e+36
-5.69302083e+35 -4.26776790e+36 2.10849216e+35 -3.88321310e+36
-9.52957448e+35 9.93559742e+35 4.13343307e+35 -2.29166969e+36
-1.85837942e+36 -1.26610193e+36 -2.77660958e+35 -8.23837505e+36
1.42649498e+36 -1.72732131e+36 -4.55971259e+36 -4.42550959e+36
-3.68109445e+36 -4.73053168e+36 -1.91429644e+36 4.43432768e+36
-6.18386068e+35 -3.07289027e+36 -3.72914158e+36 -9.81286935e+36
-1.02773259e+36 1.03946589e+36 -2.20454802e+36 -2.38695376e+36
```
Is this expected?
--
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]