Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to convert the model to Torchscript #82

Open
arunraman opened this issue Jan 18, 2022 · 0 comments
Open

Not able to convert the model to Torchscript #82

arunraman opened this issue Jan 18, 2022 · 0 comments

Comments

@arunraman
Copy link

I am trying to convert the DialogGPT model to Torchscript to load the model into Triton. I tried to use JIT to trace the model as mentioned here but hitting the following warning

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large")
model = AutoModelForCausalLM.from_pretrained(
    "microsoft/DialoGPT-large", torchscript=True)
step = 0
new_user_input_ids = tokenizer.encode(
    "This is a test!" + tokenizer.eos_token, return_tensors='pt')
bot_input_ids = torch.cat(
    [chat_history_ids, new_user_input_ids], dim=-1) if step > 0 else new_user_input_ids
traced_model = torch.jit.trace(
    model, bot_input_ids)
torch.jit.save(traced_model, "DialogGPT.pt")
/opt/conda/lib/python3.8/site-packages/transformers/models/gpt2/modeling_gpt2.py:196: TracerWarning: Converting a tensor to a Python float might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  attn_weights = attn_weights / (float(value.size(-1)) ** 0.5)

How can I trace with the generate method?

model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)

I tried to cover the model ONNX format using this instruction but this takes three inputs
input_ids, attention_mask and token_type_ids. I am able to get input_ids and attention_mask from the tokenizer. How can I get the token_type_ids

inputs = tokenizer("How are you doing?", return_tensors="np")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant