Skip to content

Conversation

kashif
Copy link
Collaborator

@kashif kashif commented Oct 18, 2025

What does this PR do?

We log the mean token accuracy from Liger kernel if it is available

Requires linkedin/Liger-Kernel#910

to test do:

pip install git+https://github.com/kashif/Liger-Kernel.git@mean_token_accuracy
pip install git+https://github.com/huggingface/trl.git@iiger-mean-acc

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

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.

@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.

# Compute token accuracy if we have labels and if the model is not using Liger (no logits)
if not self.args.use_liger_kernel:
if self.args.use_liger_kernel:
if hasattr(outputs, "token_accuracy") and outputs.token_accuracy is not None:
Copy link
Member

Choose a reason for hiding this comment

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

I prefer using an explicit condition, like this:

if self.args.use_liger_kernel and version("liger_kernel") >= "0.6.4":
    token_accuracy = self.accelerator.gather_for_metrics(outputs.token_accuracy).mean().item()
    self._metrics[mode]["mean_token_accuracy"].append(token_accuracy)

Having the explicit condition makes it much easier to spot when the check can be removed after we bump the minimum liger_kernel version. It’s clearer and more maintainable than hiding the logic elsewhere.

Copy link
Member

Choose a reason for hiding this comment

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

the question is then, which version will include this feature

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