FP16 training will occurs NaN problem after last code updates
I noticed that you remove the code
if qkv.dtype == torch.float16:
qkv = qkv.float()
in relu_linear_att and relu_quadratic_att function.
But it might have Nan output after state 4
Hi Yunzhe,
You can use BF16 for mixed precision training. It does not have the NAN issue.
If your machines do not support BF16, you can add the code back to avoid the NAN issue:
if qkv.dtype == torch.float16:
qkv = qkv.float()
In addition, the following code can be removed in such case https://github.com/mit-han-lab/efficientvit/blob/1ccfc0caa4360f20e20fb948aab2d5d1992608eb/efficientvit/models/nn/ops.py#L427-L428
Hi Yunzhe,
You can use BF16 for mixed precision training. It does not have the NAN issue.
If your machines do not support BF16, you can add the code back to avoid the NAN issue:
if qkv.dtype == torch.float16: qkv = qkv.float()In addition, the following code can be removed in such case
https://github.com/mit-han-lab/efficientvit/blob/1ccfc0caa4360f20e20fb948aab2d5d1992608eb/efficientvit/models/nn/ops.py#L427-L428
Thank you so much for clarifying it.
Would it be better to reserve the code that converts qkv to float in fp16 and out to float if out is bfloat16?
By the way, which precision the pre-trained model trained on? I guess it is fp16 mixed precision, right?
Good idea! I have updated the code.
L models were trained with fp16. B models were trained with fp32.