crawlingcub opened a new issue, #12632:
URL: https://github.com/apache/tvm/issues/12632

   The SoftPlus layer produces different outputs for given input. Maybe some 
numerical instability?
   
   Let me know if you need more info.
   
   Code:
   ```python
   import torch
   import tvm
   from tvm import relay
   from tvm.contrib.download import download_testdata
   from tvm.contrib import graph_executor
   import os
   import pickle as pkl
   import numpy as np
   import sys
   
   
   DEVICE='cuda'
   model=torch.nn.Softplus()
   pt_inp=torch.Tensor(pkl.load(open(os.path.join(sys.argv[1], "data.pkl"), 
"rb")))
   
   pt_inp=pt_inp.to(DEVICE)
   model.to(DEVICE)
   
   
   with torch.no_grad():
           pt_out = model(pt_inp).cpu().numpy()
   
   model.to('cpu')
   pt_inp=pt_inp.to('cpu')
   input_name = "input0"
   target = tvm.target.cuda()
   dev = tvm.gpu(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)
   
   
   
   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[0][20:30])
   print(tvm_out[0][20:30])
   #print(pt_out)
   ```
   
   Find data 
[here](https://drive.google.com/drive/folders/19PZYIsBbXBcWDcMDR81sGXs4Oww7IqtG?usp=sharing)
   
   ### Expected behavior
   
   Outputs should be same
   
   ### Actual behavior
   Output:
   ```
   inf inf
   [ 54.105717  15.969946  36.069256  13.273791  19.722383  31.054518
     44.89835   15.706258 114.94983   67.98223 ]
   [54.105713 15.969945 36.069256 13.27379  19.722383 31.054516 44.89835
    15.706258       inf 67.98223 ]
   ```
   
   ### Environment
   
   Any environment details, such as: Operating System, TVM version, etc
   
   ```
   torch==1.12.1
   torchvision==0.13.1
   python 3.8.13
   Ubuntu 18.04
   TVM 1afd05939
   ```
   


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