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 Chunked SimPO Loss #386

Merged
merged 9 commits into from
Nov 19, 2024
Merged

Add Chunked SimPO Loss #386

merged 9 commits into from
Nov 19, 2024

Conversation

pramodith
Copy link
Collaborator

Summary

This PR adds the Simple Preference Optimization Loss function. The only difference between SimPO and CPO is a margin term gamma which specifies that the preferred response should be atleast gamma logit points better than the losing response.

$$SimPOLoss = -\log(\sigma(\beta\log(\pi_\theta(y_c|x)) - \beta\log(\pi_\theta(y_r|x)) - \gamma))$$

Note that SimPO explicitly specifies that $$\pi_\theta(y|x)$$ needs to be normalized by length, unlike DPO.

This corresponds to Eq 6 in the paper.

Testing Done

GPU A100-80G-SXM

Screenshot 2024-11-15 at 2 38 23 PM
Screenshot 2024-11-15 at 2 38 37 PM

  • Hardware Type:
  • run make test to ensure correctness
  • run make checkstyle to ensure code style
  • run make test-convergence to ensure convergence

@pramodith pramodith changed the title Add Chunked Simpo Loss Add Chunked SimPO Loss Nov 15, 2024
@shivam15s
Copy link
Collaborator

Great PR @pramodith ! Could you rebase?

@pramodith
Copy link
Collaborator Author

Great PR @pramodith ! Could you rebase?

Good to go now!

@pramodith pramodith enabled auto-merge (squash) November 19, 2024 11:45
Copy link
Collaborator

@shivam15s shivam15s left a comment

Choose a reason for hiding this comment

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

lgtm

beta (float): Weight for the odds ratio loss.
gamma (float): The simpo gamma, margin term.
"""
logits = beta * (chosen_logps - rejected_logps) - gamma
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be normalized by length, as you said in the description?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nvm, the logps are already averaged

@pramodith pramodith merged commit ebd5303 into main Nov 19, 2024
3 checks passed
@pramodith pramodith deleted the pramodith/chunked_simpo_loss branch November 19, 2024 17:46
@pramodith pramodith mentioned this pull request Dec 5, 2024
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.

3 participants