gemma3 fp16 fix - #36832
Conversation
|
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. When it is ready for review, please click the |
There was a problem hiding this comment.
This looks okay to me, but I'm a bit worried about the clamp_ - it implies that the model is getting overflows in float16, and after clamping the values may be significantly incorrect depending on how large the overflow was.
As a result, the model quality might significantly decline in float16 instead of bfloat16. There's not much we can do about this, but we should be careful not to advertise that we fully support it!
cc @ArthurZucker do you think it's okay?
|
@Rocketknight1 True! But it's better than not outputting anything. The few tests I ran looked quite fine. I can run some evaluations to compare bfloat16 vs. fp16 with this fix. |
|
Meanwhile, I am also looking into more accurate ways of doing this...so let's not merge yet when approved. |
ArthurZucker
left a comment
There was a problem hiding this comment.
My main inquire is to put this in the layer norm layer directly instead of the decoder layer if possible. Now I get that's not super feasible if you want to keep float32 for the residuals, but if you return hiddenstates as f32 but residuals are fp16 mixed precision should be alright no?
Yeah that was my first version, then I noticed that the range expands when the residual is added, so they should be clipped before entering the layernorm. Let me run some lm-eval benchmarks to see the impact between different settings, it's difficult to judge with a single output. |
|
@ArthurZucker lm-eval results |
|
Thanks for the update, let's keep this open for reference, unless the google team wants to merge it! |
What does this PR do?
Fixes float16 inference with Gemma 3 models by simply clipping the activations. The residual addition step should also be clipped for more accurate outputs. Without this fix, the output is empty because of NaN in the activations.
Fixes #36822
Test it here: https://gist.github.com/mobicham/2be18274476bbb32fe6c7aab9d50b316
Outputs:
Who can review?
@ArthurZucker @Rocketknight1