-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
T5-large FP16 produces nan in loss #11461
Comments
I see nans creeping in at the T5Attention in decoder. I didn't find any inf or nan in either hidden_states or key_value_states but the computed values of both key_states and value_states have nan's |
Why do you believe this to be the case? This model was trained in bf16, which has a totally different numerical range from fp16. So it shouldn't produce NaNs under bf16 or fp32, but under fp16 it's almost guaranteed to not work. Please see: https://discuss.huggingface.co/t/mixed-precision-for-bfloat16-pretrained-models/5315 That's said, please try this branch #10956 that tries to use a workaround for AMP. Some users reported success. One user reported problems. And you can also try the new over/underflow detector: #11274 if you want to get more precise info on where the problem emerges first. Just add |
Thank you for the pointers to the discussion. Is it just finetuning or do you expect inference to be unstable as well in fp16 mode? debug_activation_overflow looks like a great tool that can be useful in identifying the source of nans. I'll give #10956 a try and see if it helps with my runs. |
There are less moving parts during inference. But more or less expect the same problems. So the workaround is to identify where under/overflow happens and force the model to perform those ops in fp32 and then convert back to fp16. In fact with finetuning if you don't have the problem happening right away like it does with mt5, you could try to stir the model into the fp16 range by punishing large activations. Please see the proposed |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
Environment info
transformers
version: 4.6.0.dev0, commit hash: 5e04d70Who can help
t5: @patrickvonplaten, @patil-suraj
Information
Model I am using (Bert, XLNet ...): t5-large
The problem arises when using:
The tasks I am working on is:
To reproduce
Steps to reproduce the behavior:
cd examples/seq2seq
CUDA_VISIBLE_DEVICES=0 PYTHONPATH=../../src USE_TF=0 ./run_translation.py
--model_name_or_path t5-large
--do_train --source_lang en --target_lang ro
--source_prefix "translate English to Romanian: "
--dataset_name wmt16 --dataset_config "ro-en"
--output_dir /tmp/tst-translation
--per_device_train_batch_size 4
--overwrite_output_dir
--predict_with_generate
--num_train_epochs 1 --fp16
Expected behavior
FP16 mode shouldn't produce nan in loss.
The text was updated successfully, but these errors were encountered: