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

Why gpt2-xl (based transformer-xl) onnx slower than the originer pytorch #11293

Open
lileilai opened this issue Apr 21, 2022 · 7 comments
Open
Labels
core runtime issues related to core runtime model:transformer issues related to a transformer model: BERT, GPT2, Hugging Face, Longformer, T5, etc.

Comments

@lileilai
Copy link

Describe the bug
I have a transformer-xl (Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context) gpt-xl ( 41 layer ), and the code is implemented by myself; After transfer to onnx and optimized by gpt2_optimizer ( LayerNormalization kernel fusion, fastGelu kernel fusion )。Even with the IOBinding, the inference time still slower than original pytorch。

Urgency
If there are particular important use cases blocked by this or strict project-related timelines, please share more information and dates. If there are no hard deadlines, please specify none.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
  • ONNX Runtime installed from (source or binary):
  • ONNX Runtime version: 1.81
  • Python version: 3.8
  • Visual Studio version (if applicable):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version: 11.3
  • GPU model and memory: 40G

To Reproduce

  • Describe steps/code to reproduce the behavior.
  • Attach the ONNX model to the issue (where applicable) to expedite investigation.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here. If the issue is about a particular model, please share the model details as well to facilitate debugging.

image

@pranavsharma
Copy link
Contributor

Looks like you're using ver 1.8.1. Have you tried with the latest ORT ver? Also, attach the model and the repro code.
cc @tianleiwu

@tianleiwu
Copy link
Contributor

@lileilai, to get fully optimized, you will need a custom Attention operator. It is because current Attention operator only applies to the self attention in BERT and GPT-2, and it cannot apply to transformer-xl.

See our guide if you would like to create a custom operator and fusion: https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/python/tools/transformers/Dev_Guide.md

@lileilai
Copy link
Author

Looks like you're using ver 1.8.1. Have you tried with the latest ORT ver? Also, attach the model and the repro code. cc @tianleiwu

Thanks for your reply, and i will try the latest ORT version later

@lileilai
Copy link
Author

I have try ORT 1.11,but it got the same statistic。My confusion is when i using " torch.onnx.export(opt_version=12) ", the onnx model have a slower inference perfermance than original pytorch . Comparing to the result of baseline onnx model without additional kenel fusion ( LayerNorm、Attention、FastGlue ),it is abnormal.

@sophies927 sophies927 added model:transformer issues related to a transformer model: BERT, GPT2, Hugging Face, Longformer, T5, etc. core runtime issues related to core runtime and removed model:GPT2 labels Aug 12, 2022
@elephantpanda
Copy link

Hi can you

Describe the bug I have a transformer-xl (Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context) gpt-xl ( 41 layer ), and the code is implemented by myself; After transfer to onnx and optimized by gpt2_optimizer ( LayerNormalization kernel fusion, fastGelu kernel fusion )。Even with the IOBinding, the inference time still slower than original pytorch。

Urgency If there are particular important use cases blocked by this or strict project-related timelines, please share more information and dates. If there are no hard deadlines, please specify none.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
  • ONNX Runtime installed from (source or binary):
  • ONNX Runtime version: 1.81
  • Python version: 3.8
  • Visual Studio version (if applicable):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version: 11.3
  • GPU model and memory: 40G

To Reproduce

  • Describe steps/code to reproduce the behavior.
  • Attach the ONNX model to the issue (where applicable) to expedite investigation.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here. If the issue is about a particular model, please share the model details as well to facilitate debugging.

image

Hi could you share how you used IOBinding for this model and did it give a speed up? I am trying to implement something similar myself.

@elephantpanda
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core runtime issues related to core runtime model:transformer issues related to a transformer model: BERT, GPT2, Hugging Face, Longformer, T5, etc.
Projects
None yet
Development

No branches or pull requests

5 participants