📎 Fix is_clipped to compute the effective clip_ratio#3175
Merged
Conversation
|
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. |
qgallouedec
reviewed
Mar 30, 2025
qgallouedec
reviewed
Mar 30, 2025
qgallouedec
left a comment
Member
There was a problem hiding this comment.
Thanks @pandong2011! A small remark
Contributor
Author
|
@qgallouedec if the situation is per_token_loss1 == per_token_loss2 or advantage == 0, your code will trigger the clip operation. If you really and definitely want to make such a modification, it should be is_clipped = (per_token_loss == -per_token_loss2) & (per_token_loss1 != per_token_loss2). However, I don't recommend doing this because it will obscure your judgment process, especially the influence of the "advantage" on the judgment. |
Member
|
Ah yes good point |
qgallouedec
reviewed
Mar 31, 2025
Member
|
what is clip_radio? |
qgallouedec
approved these changes
Mar 31, 2025
kashif
pushed a commit
to kashif/trl
that referenced
this pull request
Mar 31, 2025
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com> Co-authored-by: Quentin Gallouédec <gallouedec.quentin@gmail.com>
BjarniHaukur
pushed a commit
to ASSERT-KTH/trl
that referenced
this pull request
Apr 15, 2025
…ggingface#3131) Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com> Co-authored-by: Quentin Gallouédec <gallouedec.quentin@gmail.com> log answer key to wandb all Table HTML logging table bump patch hmm formatting html esacape reward isnt string [Liger] Liger KTO support (huggingface#2812) Co-authored-by: Kashif Rasul <kashif.rasul@gmail.com> Co-authored-by: Quentin Gallouédec <gallouedec.quentin@gmail.com> 🏃 Migrate CI to self-hosted runners (huggingface#3174) ❤️🩹 [CI] fix transformers dev CI failure (huggingface#3176) Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com> ⏯️ Fix: handle None inputs when resuming GRPO Trainer from checkpoint (huggingface#3148) Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com> 📎 Fix is_clipped to compute the effective clip_ratio (huggingface#3175) Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com> Co-authored-by: Quentin Gallouédec <gallouedec.quentin@gmail.com> Fix breaking typo for flash_attention reducing_memory_usage.md (huggingface#3190) Show unique prompts in GRPO WandB tables (huggingface#3191) 🐗 [CI] Fix trufflehog false positives (huggingface#3192) [GRPO] Improve completion length logging (huggingface#3188) preliminary openai compatible endpoint early concept, needs refining dedupe debug print some slop to work on unslop, missing hist almost valid pseudocode middle-ware monkey patch in mp.Pool()... remove unused More accurate .md need gpu renting lambda again much nicer small aider-chat and datasets conflict risky reqs change should work, but hacky some insights, but monkeypatching probably wont suffice refactor: Rewrite test script to use SWE-bench dataset with MultiProcessAider refactor: Remove logging statements from test.py one step closer finally, the correct abstraction doc todo unslop unslop undo accidental black cleaner abstraction new abstraction
yxliu-TAMU
pushed a commit
to mincheolseong/ECEN743-GRPO-Project-Proposal
that referenced
this pull request
Apr 20, 2025
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com> Co-authored-by: Quentin Gallouédec <gallouedec.quentin@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Below, let me briefly explain my motives and reasons, the code mainly uses the part marked in the figure.

if (coef_1 < (1 - self.epsilon_low) and advantage > 0) or (coef_1 > (1 + self.epsilon_high) and advantage < 0)
then coef_1 * advantage < (1 - self.epsilon_low) * advantage
coef_1 * advantage < (1 + self.epsilon_high) * advantage
min(per_token_loss1, per_token_loss2) = per_token_loss1
From the perspective of loss, it is actually not clipped.
clip_ratio = (is_clipped * completion_mask).sum() / completion_mask.sum()And this code also calculates an effective clip_ratio
original code:
is_clipped = (coef_1 < (1 - self.epsilon_low)) | (coef_1 > (1 + self.epsilon_high))Therefore, we must combine the sign of the advantage with the original code to calculate is_clipped, thereby computing an effective clip_ratio
As follows
is_clipped = (coef_1 < (1 - self.epsilon_low) and advantage < 0) or (coef_1 > (1 + self.epsilon_high) and advantage > 0)if (coef_1 < (1 - self.epsilon_low) and advantage < 0) or (coef_1 > (1 + self.epsilon_high) and advantage > 0)
then coef_1 * advantage > (1 - self.epsilon_low) * advantage
coef_1 * advantage > (1 + self.epsilon_high) * advantage
min(per_token_loss1, per_token_loss2) = per_token_loss2
Therefore, by modifying is_clipped as described above, the effective clip_ratio can be correctly calculated