FIX: Initialize DoRA weights in float32 if float16 is being used #1653
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When DoRA weights are initialized in float16 on CPU and when an older PyTorch version is being used (<2.2), there is an error because the the operation is not supported for float16 on CPU. This commit temporarily converts the LoRA weights to float32 beforehand if they're in float16.
Of course, when the user tries to train or predict with this model on CPU, they will still encounter errors. However, in certain situations, only the initialization might be on CPU and later it is moved to GPU. This could be some framework code that the user has no control over, as in #1597. Therefore, it's good to have this safety hatch.
Note that since our CI uses the latest PyTorch version, we cannot run a test for this, as the latest PyTorch runs no matter what.