# Finetuning for fp16 compatibility

**URL:** <https://discuss.huggingface.co/t/finetuning-for-fp16-compatibility/977>\
**Category:** Research\
**Created:** [September 3, 2020, 5:26pm UTC](https://discuss.huggingface.co/t/finetuning-for-fp16-compatibility/977 "2020-09-03T17:26:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sshleifer](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sshleifer/32/3304_2.png) [@sshleifer](https://discuss.huggingface.co/u/sshleifer)\
**Post date:** [September 3, 2020, 5:26pm UTC](https://discuss.huggingface.co/t/finetuning-for-fp16-compatibility/977/1 "2020-09-03T17:26:08Z")

</div>

t5 and pegasus don’t really work in fp16 because they create activations that overflow fp16 bits. (they were trained in bfloat 16 which has larger range) Has anyone read/seen/heard anything about finetuning/scaling models so that their activations can fit in fp16. (or generally to encourage smaller magnitude activations?

I tried one experiment on google/pegasus-xsum where I finetune with summarization lm loss and add some additional losses based on the magnitude of hidden states, but I haven’t weighted them (the model instantly forgets how to summarize) so I’m looking around.

---

<div class="post-metadata">

**Author:** ![Igor](https://avatars.discourse-cdn.com/v4/letter/i/dec6dc/32.png) [@Igor](https://discuss.huggingface.co/u/Igor)\
**Post date:** [June 7, 2021, 10:05am UTC](https://discuss.huggingface.co/t/finetuning-for-fp16-compatibility/977/2 "2021-06-07T10:05:31Z")

</div>

It’s been a long time since this post, but maybe you remember if the problem with fp16 will appear when training the models from scratch (pretraining)?

I’ve seen some NaNs already while training with fp16 on, but after lowering the learning rate, beginning of training looks reasonable.

---

<div class="post-metadata">

**Author:** ![Igor](https://avatars.discourse-cdn.com/v4/letter/i/dec6dc/32.png) [@Igor](https://discuss.huggingface.co/u/Igor)\
**Post date:** [June 17, 2021, 10:33am UTC](https://discuss.huggingface.co/t/finetuning-for-fp16-compatibility/977/3 "2021-06-17T10:33:53Z")

</div>

After 3 days of training with fp16 on NaN loss happened. Created issue [Pegasus pretraining in fp16 results in NaN loss · Issue #12225 · huggingface/transformers · GitHub](https://github.com/huggingface/transformers/issues/12225), maybe someone knows how it can be fixed.
