Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused fix matches SentencePiece behavior and has comprehensive regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Aligns SentencePiece BPE tie-breaking with the reference implementation.
Changes:
- Merges leftmost equal-score pairs first.
- Adds regression cases for repeated symbols.
| File | Description |
|---|---|
SentencePieceBpeModel.cs |
Corrects equal-score pair ordering. |
LlamaTests.cs |
Verifies IDs, tokens, and offsets. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7752 +/- ##
=======================================
Coverage 70.25% 70.25%
=======================================
Files 1419 1419
Lines 272569 272593 +24
Branches 27938 27938
=======================================
+ Hits 191500 191521 +21
- Misses 73652 73657 +5
+ Partials 7417 7415 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Laurianti
force-pushed
the
fix-sentencepiece-bpe-leftmost-tie
branch
from
October 2, 2026 03:52
e6b950f to
cb66549
Compare
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.
When several pairs of symbols can merge into pieces with the same score,
SentencePieceBpeModelmerged the rightmost pair first, while SentencePiece merges the leftmost one, so some runs of repeated characters were encoded differently:____1, 4770, 1649(▁__,__)1, 903, 22359(▁_,___)......1, 6317, 3045(▁..,....)1, 13035, 636(▁....,..)~~~~1, 3695, 30022, 7377(▁~,~,~~)1, 3695, 7377, 30022(▁~,~~,~)SymbolPair.CompareTonow breaks ties withLeft.CompareTo(other.Left), as theSymbolPairofCodeGenTokenizerdoes. The three cases are added toLlamaTestData, with the ids, tokens and offsets SentencePiece 0.2.2 gives; they fail without the change. Compared with SentencePiece 0.2.2 (Hugging Facetokenizersgives the same ids on all three sets):Fixes #7751