Skip to content
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

[DPOTrainer] Fix peft + DPO + bf16 if one uses generate_during_eval or pre-computed logits #1203

Merged
merged 8 commits into from
Jan 9, 2024

Conversation

younesbelkada
Copy link
Contributor

What does this PR do ?

Fixes #1202 which is a regression

#1143 introduced peft_module_casting_to_bf16 for DPOTrainer which worked fine when generate_during_eval is set to False.

peft_module_casting_to_bf16 will cast the LayerNorm layers in fp32 for stability purposes for smoother training, in case one uses peft + 4-bit quantization (QLoRA).

If one uses bf16=True in the TrainingArguments, Trainer will automatcially compute the loss under the torch.cuda.amp.autocast regime, making the forward pass possible to work without any dtype mismatch issue

However, we need to make sure all other methods inside DPOTrainer that call the model's forward pass will also use that context manager to make sure there is no dtype mismatch

since this is a regression, will publish a patch release after merging this pr

cc @kashif @pacman100 @lvwerra

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

@kashif
Copy link
Collaborator

kashif commented Jan 9, 2024

thanks @younesbelkada awesome!

@kashif kashif merged commit d116887 into main Jan 9, 2024
9 checks passed
@kashif kashif deleted the fix-peft-bf16 branch January 9, 2024 08:35
lapp0 pushed a commit to lapp0/trl that referenced this pull request May 10, 2024
…l` or pre-computed logits (huggingface#1203)

* fix peft + DPO + bf16

* fix

* revert old behaviour

* fix tests

* fix

* fix

* fix

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

After upgrade from 0.7.5 to 0.7.8 DPOTrainer get RuntimeError: expected scalar type Float but found BFloat16
4 participants