ENH Support models with low precision float dtypes#3055
Open
BenjaminBossan wants to merge 5 commits intohuggingface:mainfrom
Open
ENH Support models with low precision float dtypes#3055BenjaminBossan wants to merge 5 commits intohuggingface:mainfrom
BenjaminBossan wants to merge 5 commits intohuggingface:mainfrom
Conversation
More recent models can use low precision float dtypes for the base weights, e.g. torch.float8_e4m3fn. This PR enables LoRA to work with these models. Implementing this for LoRA is not difficult, we just upcast the LoRA weights to float32 (unless indicated otherwise by the user), which is already what we do with fp16 and bf16. This was just a matter of adding the other dtypes to the list of dtypes to upcast. The main difficulty comes from target_parameters. There, we materialize the delta_weight and add it to the base weight. However, low precision floats do not support addition. The current solution is to temporarily upcast the weight to a higher precision, add the delta_weight, clamp the result to the low fp range, and cast the weight back to that dtype. This is not optimal, as upcasting can be quite expensive and clamping could be too primitive. But at least it's a working solution for now.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
- merging currently fails - prevent upcast possible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
More recent models like https://huggingface.co/MiniMaxAI/MiniMax-M2.5 can use low precision float dtypes for the base weights, e.g.
torch.float8_e4m3fn. This PR enables LoRA to work with these models.Implementing this for normal LoRA or other PEFT adapters is not difficult, we just upcast the weights to float32 (unless indicated otherwise by the user), which is already what we do with fp16 and bf16 by default. This was just a matter of adding the other dtypes to the list of dtypes to upcast.
The main difficulty comes from
target_parameters. There, we materialize thedelta_weightand add it to the base weight. However, low precision floats do not support addition. The current solution is to temporarily upcast the weight to a higher precision, add thedelta_weight, clamp the result to the low fp range, and cast the weight back to thatdtype. This is not optimal, as upcasting can be quite expensive and clamping could be too destructive. But at least it's a working solution for now.For the same reason (i.e. W + dW not being possible ootb), merging also doesn't work right now. We could implement a similar solution as for
target_parameters, but it would require to update all PEFT methods that support merging separately. Maybe there is a better solution, for now it's not addressed.