Skip to content

[Fix] Fix Method to Obtain Prefix Token ID#18317

Open
anzr299 wants to merge 1 commit intopytorch:mainfrom
anzr299:patch-4
Open

[Fix] Fix Method to Obtain Prefix Token ID#18317
anzr299 wants to merge 1 commit intopytorch:mainfrom
anzr299:patch-4

Conversation

@anzr299
Copy link
Contributor

@anzr299 anzr299 commented Mar 19, 2026

Summary

Fix prefix_token_id to return the BOS token ID instead of the EOT token ID.

EagerEvalWrapper.prefix_token_id was incorrectly returning the EOT token ID.
Since lm-eval prepends prefix_token_id to every evaluation sequence, this caused
Llama 3's <|end_of_text|> (token 128001) to be used instead of <|begin_of_text|>
(token 128000), resulting in higher perplexity scores.

Llama 3 8B Wikitext PPL before fix : 9.18
Llama 3 8B Wikitext PPL after fix : 7.793

The result after the fix matches the expected perplexity when evaluating
the same model directly via HuggingFace.

@anzr299 anzr299 requested a review from lucylq as a code owner March 19, 2026 13:13
Copilot AI review requested due to automatic review settings March 19, 2026 13:13
@pytorch-bot
Copy link

pytorch-bot bot commented Mar 19, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18317

Note: Links to docs will display an error until the docs builds have been completed.

❌ 6 Awaiting Approval, 1 New Failure

As of commit 55fd4d1 with merge base 1925873 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 19, 2026
@github-actions
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Llama evaluation behavior by returning a proper prefix token id (BOS when available) instead of incorrectly defaulting to the end-of-text/end-of-sequence token, aligning perplexity results with Hugging Face’s eval flow.

Changes:

  • Update prefix_token_id to prefer tokenizer.bos_id when present.
  • Preserve prior fallback behavior by using eot_token_id when BOS is unavailable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants