Skip to content

🐌 Clean two-sided clipping #3499

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

Merged
merged 7 commits into from
May 27, 2025
Merged

🐌 Clean two-sided clipping #3499

merged 7 commits into from
May 27, 2025

Conversation

qgallouedec
Copy link
Member

Some late review on #3434

Copy link
Member Author

@qgallouedec qgallouedec May 27, 2025

Choose a reason for hiding this comment

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

It might seem risky to remove these tests, but having tests that are so tightly coupled to internal implementation details (like calls to _get_log_prob) makes future development extremly difficult. Even if it's less secured, I recommend manually inspecting intermediate results instead, and keeping unit tests focused on what they're meant for: validating external behavior.

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry this was my fault for asking to test the new functionality. I agree with you that we can remove these tests, with the comment that the current ones only test for a change in the weight, not whether the clipping is actually behaving as expected. I suppose those thing either need to be exposed as public methods or part of integration tests where we can access the metrics to validate the values are clipped accordingy

@qgallouedec qgallouedec marked this pull request as ready for review May 27, 2025 05:51
@qgallouedec qgallouedec changed the title Clean two sided clipping 🐌 Clean two-sided clipping May 27, 2025
@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.

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.

Thanks for the clean up and apologies for being the one who asked for the original tests!

else:
# Original GRPO clipping (only lower bound implicitly applied by the final min)
per_token_loss1 = coef_1 * advantages.unsqueeze(1)
coef_1 = torch.clamp(coef_1, max=self.args.delta)
Copy link
Member

Choose a reason for hiding this comment

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

Nice refactor!

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry this was my fault for asking to test the new functionality. I agree with you that we can remove these tests, with the comment that the current ones only test for a change in the weight, not whether the clipping is actually behaving as expected. I suppose those thing either need to be exposed as public methods or part of integration tests where we can access the metrics to validate the values are clipped accordingy

@kashif
Copy link
Collaborator

kashif commented May 27, 2025

i can try to integrate into liger too

@qgallouedec
Copy link
Member Author

Yes, I completely understand the motivation behind these tests. Ideally, we should have this kind of test that checks if the loss is well calculated with a few reference values, but considering the current implementation, it requires patching and all, so it's not ideal. If in the future we split the compute_loss method into several public sub-functions, it might be simpler.

@qgallouedec qgallouedec merged commit ac18c9d into main May 27, 2025
11 checks passed
@qgallouedec qgallouedec deleted the clean-two-sided-clipping branch May 27, 2025 16:39
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.

4 participants