T5 FP16: bad generations from my converted checkpoint
Author: sshleifer
Pull request: no
Labels: name: wontfix

`t5-base` can generate reasonable summaries in fp16, but my checkpoint `sshleifer/t5-base-cnn` cannot. Is there something besides the conversion script I need to do to make fp16 work? 

[Colab](https://colab.research.google.com/drive/1k8agNDPdzfF38aTrz5o1kcqvWDHUxAnD?usp=sharing) showing good generations for t5-base, bad for my checkpoint.

Without colab,
```python
from transformers import *
device = 'cuda'
tokenizer = T5Tokenizer.from_pretrained('t5-base')
my_model = T5ForConditionalGeneration.from_pretrained('sshleifer/t5-base-cnn').to(device)
TXT = """summarize:  Marseille, France (CNN)The French prosecutor leading an investigation into the crash of Germanwings Flight 9525 insisted Wednesday that he was not aware of any video footage from on board the plane. Marseille prosecutor Brice Robin told CNN that "so far no videos were used in the crash investigation." He added, "A person who has such a video needs to immediately give it to the investigators." Robin\'s comments follow claims by two magazines, German daily Bild and French Paris Match, of a cell phone video showing the harrowing final seconds from on board Germanwings Flight 9525 as it crashed into the French Alps. All 150 on board were killed. Paris Match and Bild reported that the video was recovered from a phone at the wreckage site. The two publications described the supposed video, but did not post it on their websites. The publications said that they watched the video, which was found by a source close to the investigation. "One can hear cries of \'My God\' in several languages," Paris Match reported. "Metallic banging can also be heard more than three times, perhaps of the pilot trying to open the cockpit door with a heavy object.  Towards the end, after a heavy shake, stronger than the others, the screaming intensifies. Then nothing." "It is a very disturbing scene," said Julian Reichelt, editor-in-chief of Bild online. An official with France\'s accident investigation agency, the BEA, said the agency is not aware of any such video. Lt. Col. Jean-Marc Menichini, a French Gendarmerie spokesman in charge of communications on rescue efforts around the Germanwings crash site, told CNN that the reports were "completely wrong" and "unwarranted." Cell phones have been collected at the site, he said, but that they "hadn\'t been exploited yet." Menichini said he believed the cell phones would need to be sent to the Criminal Research Institute in Rosny sous-Bois, near Paris, in order to be analyzed by specialized technicians working hand-in-hand with investigators. But none of the cell phones found so far have been sent to the institute, Menichini said. Asked whether staff involved in the search could have leaked a memory card to the media, Menichini answered with a categorical "no." Reichelt told "Erin Burnett: Outfront" that he had watched the video and stood by the report, saying Bild and Paris Match are "very confident" that the clip is real. He noted that investigators only revealed they\'d recovered cell phones from the crash site after Bild and Paris Match published their reports."""
batch = tokenizer.batch_encode_plus([TXT], return_tensors='pt').to(device)
tokenizer.batch_decode(my_model.generate(**batch, skip_special_tokens=True)) # way shorter than t5-base but english
# ['prosecutor in crash investigation says he is not aware of any video footage from on board ']
my_model = my_model.half()
my_model.generate(**batch, skip_special_tokens=True)
# [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
```

**Update:** On master +brutasse, (torch 1.5), t5-base produces bad generations in fp16. They are similar to the recently converted checkpoint -all bos. 

Comments:
Not sure whether I can help you here. I don't think fp16 is really stable for T5 no? 

Definitely not stable. But you had an idea for how to fix related to layernorm if i recall?


As it is now layer norm is always done in fp32: https://github.com/huggingface/transformers/blob/9a473f1e43221348334b9e7f95bb45770b7ef268/src/transformers/modeling_t5.py#L157
But even that does not seem to be enough to make fp16 work all the time

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.