-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
[Flax] from_pretrained does not consider the passed dtype #12534
Comments
I wonder whether this might be problematic for layer norm weights since those should usually always be of type |
Would love to hear what @avital @marcvanzee think here |
I think it's fine to manually port weights to bfloat16 if you want to. In general all Flax layers accept a dtype attribute when it's safe to do intermediate computation in bloat16 and you can set dtype=bfloat16 for those layers. Keeping parameters as bfloat16 should only be necessary if the model is huge and the parameters can't fit on device memory, from what I know. I think it's tricky to get that right and requires careful attention to which parameters are safe to keep in bfloat16, but I don't have too much personal context here. I can ask others if that helps. So I'm first curious whether indeed it's necessary to keep parameters as bfloat16 in this case, and if so, why |
hello so |
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. |
will soon be taken care of by @patil-suraj :-) |
This issue still exists. I was trying to make a float64 GPT2 instance (using this) and noticed the initiated LayerNorm parameters having float32 dtype. |
Environment info
When loading a flax model with
from_pretrained
the type argument is not used. The weights are initialized with the dtype of saved weights.So if you do
We should probably cast the weights to
self.dtype
.As a workaround for
bf16
, one could manually cast the weighs withcc @patrickvonplaten
The text was updated successfully, but these errors were encountered: