jsheng-jian opened a new pull request, #14122:
URL: https://github.com/apache/tvm/pull/14122

   Minor fix in pytorch frontend to compile gpt2 model, reproduce script.
   
   ```
   from transformers import GPT2LMHeadModel
   import torch
   import tvm
   from tvm import relay
   
   inp = torch.ones((1, 128)).to(torch.int64)
   input_shapes = [("input_ids", ((1, 128), "int64"))]
   
   model = GPT2LMHeadModel.from_pretrained('gpt2', return_dict=False)
   trace_model = torch.jit.trace(model, inp, strict=False)
   outputs = trace_model(inp)
   
   mod, params = relay.frontend.from_pytorch(trace_model, input_shapes)
   with tvm.transform.PassContext(opt_level=3):
       lib = relay.build(mod, target='llvm', params=params)
   
   runtime = 
tvm.contrib.graph_executor.GraphModule(lib["default"](tvm.device('cpu', 0)))
   runtime.set_input("input_ids", inp.numpy())
   runtime.run()
   out = runtime.get_output(0).numpy()
   print(out)
   print('Done...')
   ```
   
   Before the fix, the error message
   ```
   Traceback (most recent call last):
     File "gpt2_compile.py", line 13, in <module>
       mod, params = relay.frontend.from_pytorch(trace_model, input_shapes)
     File "/home/ubuntu/apache_tvm/tvm/python/tvm/relay/frontend/pytorch.py", 
line 4791, in from_pytorch
       outputs = 
converter.convert_operators(_get_operator_nodes(graph.nodes()), outputs, 
ret_name)
     File "/home/ubuntu/apache_tvm/tvm/python/tvm/relay/frontend/pytorch.py", 
line 4164, in convert_operators
       relay_out = relay_op(
     File "/home/ubuntu/apache_tvm/tvm/python/tvm/relay/frontend/pytorch.py", 
line 841, in full
       return self.full_impl(data, fill_value, dtype)
     File "/home/ubuntu/apache_tvm/tvm/python/tvm/relay/frontend/pytorch.py", 
line 743, in full_impl
       fill_value = _expr.const(fill_value, dtype=dtype)
     File "/home/ubuntu/apache_tvm/tvm/python/tvm/relay/expr.py", line 707, in 
const
       raise ValueError("value has to be scalar or NDArray")
   ValueError: value has to be scalar or NDArray
   ```
   
   because `fill_value` is
   ```
   %0 = cast(64, dtype="float32");
   power(%0, 0.5f)
   ```


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