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

Using cross entropy loss to calculate DPO? #67

Open
zachares opened this issue Feb 14, 2024 · 4 comments
Open

Using cross entropy loss to calculate DPO? #67

zachares opened this issue Feb 14, 2024 · 4 comments

Comments

@zachares
Copy link

I think that you can replace most of the logic in _get_batch_logps with torch.nn.CrossEntropyLoss and then to get the average instead of the sum divide by the number of tokens that are not ignored. This would remove some of the bespoke code from the repo. Do you think this is a correct interpretation of the maths in the paper?

@Tianranse
Copy link

I have a similar question about get the average of the losses

@ChenmienTan
Copy link

  1. DPO relies on \log p(y|x)=\sum_t \log p(y_t|x, y_{<t}), where the average is not applied.
  2. Even if applied, the provided implementation is different with reduction='mean' in F.cross_entropy. You can imagine that F.cross_entropy averages over all tokens. Here the loss is averaged over the tokens in each sequence and then averaged over sequences.

@yiyepiaoling0715
Copy link

2. the loss is averaged over the tokens in each sequence and then averaged over sequences

the loss is averaged over the tokens in each sequence and then averaged over sequences=> if do like this ,has any problme? my test is not as good as sum

@yiyepiaoling0715
Copy link

  1. DPO relies on \log p(y|x)=\sum_t \log p(y_t|x, y_{<t}), where the average is not applied.
  2. Even if applied, the provided implementation is different with reduction='mean' in F.cross_entropy. You can imagine that F.cross_entropy averages over all tokens. Here the loss is averaged over the tokens in each sequence and then averaged over sequences.

image

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

No branches or pull requests

4 participants