Use float32 for LoRA weights to avoid the risk of underflow and overflow.#22559
Use float32 for LoRA weights to avoid the risk of underflow and overflow.#22559james77777778 wants to merge 3 commits intokeras-team:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the LoRA implementation across several layers—including Convolutional, Dense, EinsumDense, and Embedding—to ensure that LoRA weights are initialized as float32 to prevent numerical instability. It also introduces explicit casting to the appropriate variable or compute dtypes during kernel composition and forward passes. A critical issue was identified in the EinsumDense layer where a trailing comma incorrectly converts the LoRA update into a tuple, which will cause a TypeError during tensor operations.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #22559 +/- ##
==========================================
+ Coverage 77.33% 83.27% +5.94%
==========================================
Files 596 596
Lines 67828 67835 +7
Branches 10562 10562
==========================================
+ Hits 52452 56487 +4035
+ Misses 12612 8605 -4007
+ Partials 2764 2743 -21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a9a06aa to
7722450
Compare
7722450 to
28a8fe9
Compare
As reported in keras-team/keras-hub#2629
We should use high precision (float32) for LoRA weights to stabilize the finetuning.
References:
autocast_adapter_dtype)huggingface/peftimpl)