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

How to force layernorm to run at FP32 precision with "config->setFlag(BuilderFlag::kFP16);" #3692

Closed
w1005444804 opened this issue Mar 3, 2024 · 4 comments
Assignees
Labels
triaged Issue has been triaged by maintainers

Comments

@w1005444804
Copy link

w1005444804 commented Mar 3, 2024

I just want to use VIT with fp16 precision ,
but [W]Running layernorm after self-attention in FP16 may cause overflow.
Now I hope other layers run in FP16,but layernorm layers run in fp32!
Can you provide some C++examples for manually setting the layernorm layers to run in FP32 with "config->setFlag(BuilderFlag::kFP16);"

onnx opset == 17;
TRT == 8.6,
windows11

[W] [TRT] Detected layernorm nodes in FP16: /neck/neck.1/ReduceMean_1, /neck/neck.3/ReduceMean_1, /neck/neck.1/Sqrt, /neck/neck.3/Sqrt, /neck/neck.1/Pow, /neck/neck.3/Add, /neck/neck.1/Add_1, /neck/neck.3/Sub, /neck/neck.3/Div, /neck/neck.1/Mul, /neck/neck.1/Div, /neck/neck.3/Add_1, /neck/neck.3/Pow, /neck/neck.1/Add, /neck/neck.3/Mul, /neck/neck.1/Sub
[03/03/2024-21:53:14] [W] [TRT] Running layernorm after self-attention in FP16 may cause overflow. Exporting the model to the latest available ONNX opset (later than opset 17) to use the INormalizationLayer, or forcing layernorm layers to run in FP32 precision can help with preserving accuracy.

so, How to force layernorm to run at FP32 precision with "config->setFlag(BuilderFlag::kFP16);

@nvluxiaoz
Copy link
Contributor

@w1005444804
Copy link
Author

@nvluxiaoz Thank you so much for your help. I really appreciate it.

@zerollzeng zerollzeng self-assigned this Mar 8, 2024
@zerollzeng zerollzeng added the triaged Issue has been triaged by maintainers label Mar 8, 2024
@zerollzeng
Copy link
Collaborator

Looks like problem solved, can we close this? Thanks!

@ttyio
Copy link
Collaborator

ttyio commented Apr 16, 2024

Closing, thanks all

@ttyio ttyio closed this as completed Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Issue has been triaged by maintainers
Projects
None yet
Development

No branches or pull requests

4 participants