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

GRPO loss fix #535

Merged
merged 4 commits into from
Jan 31, 2025
Merged

GRPO loss fix #535

merged 4 commits into from
Jan 31, 2025

Conversation

vwxyzjn
Copy link
Collaborator

@vwxyzjn vwxyzjn commented Jan 30, 2025

CC @gauravpandeyamu @hamishivi for a second look.

I think the pg_loss = pg_loss + (args.beta * kl).mean() is incorrect because the mean operation happens after the scores are added with the corresponding KL

image

The correct impl should be

pg_loss = masked_mean(pg_loss_max + (args.beta * kl), ~padding_mask[micro_batch_inds])

Let me know what you think.

@gauravpandeyamu
Copy link
Contributor

Yes, masked_mean is indeed correct to use here.

Also check my comment at #534 (comment)

The current kl1 estimator will completely ignore the ref_logprobs during trainining. kl2 and kl3 are fine.

@vwxyzjn
Copy link
Collaborator Author

vwxyzjn commented Jan 31, 2025

image

Copy link
Collaborator

@hamishivi hamishivi left a comment

Choose a reason for hiding this comment

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

Looks good to me. Nice on the metrics improvement!

@@ -487,6 +487,34 @@ def remove_padding(sequences, pad_token_id):
return [[inneritem for inneritem in item if inneritem != pad_token_id] for item in sequences]


class MetricsTracker:
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

open_instruct/grpo_vllm_thread_ray_gtrl.py Outdated Show resolved Hide resolved
@vwxyzjn vwxyzjn merged commit 79ff8fb into main Jan 31, 2025
3 checks passed
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