- Notifications
You must be signed in to change notification settings - Fork2k
[GRPO] Log generation entropy#3700
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 ourterms of service andprivacy 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
…ng-in-grpo-trainingAdd entropy logging to GRPOTrainer
HuggingFaceDocBuilderDev commentedJul 8, 2025
The docs for this PR livehere. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Uh oh!
There was an error while loading.Please reload this page.
entropy_mask = None | ||
if self.log_entropy and entropies is not None: | ||
with torch.no_grad(): |
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 think it'd be more efficient if thetorch.no_grad()
context is here
trl/trl/trainer/grpo_trainer.py
Lines 905 to 907 in640a9f3
ifcompute_entropy: | |
entropies=entropy_from_logits(logits) | |
all_entropies.append(entropies) |
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.
Yeah, I was considering this but didn’t want to complicate things with_get_per_token_logps_and_entropies
. I’ll take another look and see if I can find a clean way to incorporate it. Either way, I’m leaning toward always logging entropy instead of making it configurable, which will probably change things.
Uh oh!
There was an error while loading.Please reload this page.
What does this PR do?
Log the average per-token entropy of the generations/completions (normalized over the local batch, BNPO-style). Since entropy is not computed by default, you need to set
log_entropy
in the config. However, given the importance of this metric, I'm open to the idea of always computing entropy–provided that it doesn't introduce noticeable overhead.Fixes#3571
This PR also includes a minor refactoring of the _compute_loss function.
Before submitting
Pull Request section?
to it if that's the case.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.