-
Notifications
You must be signed in to change notification settings - Fork 16
Log KL Divergence in GRPO Loss function #323
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
base: main
Are you sure you want to change the base?
Conversation
def forward_backward( | ||
self, inputs: dict[str, Tensor], targets: dict[str, Tensor] | ||
) -> Tensor: | ||
) -> Tensor | LossMetrics: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be tuple[..,..]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should!
@casteryh let's merge |
self.beta = beta | ||
|
||
def forward(self, logprobs, ref_logprobs, advantages, padding_mask): | ||
kl = torch.exp(ref_logprobs - logprobs) - (ref_logprobs - logprobs) - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we log the KL divergence minus padding tokens? May have to move that op up in the loss function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adressed
import torch | ||
from torch import nn | ||
|
||
from forge.data_models.loss_metrics import LossMetrics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is a fully fleshed out data model we want to use.
For now could we just define a loose type in this file and shove the metrics in that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done it with data_model, because we might want to log some other things from different losses in future (margins from DPO loss for instance).
Resolves #298