Skip to content

ENH Support models with low precision float dtypes#3055

Open
BenjaminBossan wants to merge 5 commits intohuggingface:mainfrom
BenjaminBossan:enh-lora-support-for-fp8-base-model
Open

ENH Support models with low precision float dtypes#3055
BenjaminBossan wants to merge 5 commits intohuggingface:mainfrom
BenjaminBossan:enh-lora-support-for-fp8-base-model

Conversation

@BenjaminBossan
Copy link
Member

@BenjaminBossan BenjaminBossan commented Feb 20, 2026

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 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 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.

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.
@HuggingFaceDocBuilderDev

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants