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

Add CPOTrainer #1382

Merged
merged 35 commits into from Mar 22, 2024
Merged

Add CPOTrainer #1382

merged 35 commits into from Mar 22, 2024

Conversation

fe1ixxu
Copy link
Contributor

@fe1ixxu fe1ixxu commented Feb 29, 2024

Hi! This PR wants to add CPOTrainer proposed in the paper Contrastive Preference Optimization: Pushing the Boundaries of LLM
Performance in Machine Translation

The CPO method is one of the algorithm for building the state-of-the-art LLM-based translation model: ALMA

@fe1ixxu
Copy link
Contributor Author

fe1ixxu commented Feb 29, 2024

cc @kashif @lewtun

@kashif
Copy link
Collaborator

kashif commented Feb 29, 2024

@fe1ixxu how close is the trainer in terms of code to the DPOTrainer? Can one subclass from it?

@fe1ixxu
Copy link
Contributor Author

fe1ixxu commented Feb 29, 2024

@kashif Thanks for the quick response! CPO is an approximation of DPO. The key differences between CPOTrainer and DPOTrainer are:

  • Remove the need of reference model
  • add an extra NLL loss for preferred data

I'm uncertain whether subclassing CPOTrainer from DPOTrainer is a proper idea, as DPOTrainer introduces numerous features related to reference models that are unnecessary for CPOTrainer.

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

@fe1ixxu
Copy link
Contributor Author

fe1ixxu commented Mar 7, 2024

Hi @kashif CPO docs has been finished now! Thanks!

@kashif kashif requested review from kashif and lewtun March 17, 2024 12:58
@fe1ixxu
Copy link
Contributor Author

fe1ixxu commented Mar 21, 2024

Hi @kashif and @lewtun, I see implementation of CPOTrainer has been finished for a while and it has passed all checks. If this looks good to you, is there any chance to merge it to the main branch? Thanks!

Copy link
Member

@lewtun lewtun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this very nice implementation of CPO @fe1ixxu 🔥 ! I left a few small comments and a suggestion to remove a deepspeed function I don't think we need. Apart from that LGTM!

docs/source/cpo_trainer.mdx Outdated Show resolved Hide resolved
docs/source/cpo_trainer.mdx Outdated Show resolved Hide resolved
trl/trainer/cpo_trainer.py Outdated Show resolved Hide resolved
trl/trainer/cpo_trainer.py Show resolved Hide resolved
@kashif kashif merged commit d1df79f into huggingface:main Mar 22, 2024
9 checks passed
@kashif kashif deleted the cpo-trainer branch March 22, 2024 20:32
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.

None yet

4 participants