masahi commented on issue #13664:
URL: https://github.com/apache/tvm/issues/13664#issuecomment-1365670002

   It looks like amp is adding some dynamism, do you know why?
   
   The following modified script that removed amp autocast works:
   
   ```
   from transformers import BertTokenizer, BertConfig, BertModel
   import tvm
   from tvm import relay
   import torch
   
   
   class AutoModelAMP(BertModel):
       def __init__(self, *args, **keyargs):
           super().__init__(*args, **keyargs)
   
       def forward(self, *args, **keyargs):
           return super().forward(*args, **keyargs)
   
   
   config = BertConfig.from_pretrained("bert-large-uncased")
   config.return_dict = False
   config.torchscript = True
   model = AutoModelAMP(config).eval()
   
   batch = 1
   seq_len = 128
   input = torch.zeros([batch, seq_len], dtype=torch.int).long()
   inputs = {
       "input_ids": input,
       "attention_mask": input,
       "token_type_ids": input,
   }
   input_list = []
   for k, v in inputs.items():
       input_list.append(v)
   
   shape_list = []
   for k, v in inputs.items():
       shape_list.append((k, v.shape))
   
   traced_model = torch.jit.trace(
       model, input_list, strict=False).eval()
   mod, params = relay.frontend.from_pytorch(traced_model, shape_list)
   
   ```


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