Skip to content

fix: flush byte fallback runs at end of input - #414

Merged
pcuenca merged 5 commits into
huggingface:mainfrom
TheTom:codex/bytefallback-end-of-input
Oct 28, 2026
Merged

pcuenca merged 5 commits into
huggingface:mainfrom
TheTom:codex/bytefallback-end-of-input

Conversation

@TheTom

@TheTom TheTom commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

ByteFallbackDecoder flushes buffered bytes only when an ordinary token follows. A sequence ending in byte-fallback pieces therefore loses its last character: decoding the four UTF-8 pieces for an emoji returns an empty string.

Flush the remaining byte buffer at end of input using the same UTF-8 conversion as an interior run. This keeps decoding within the configured pipeline, so subsequent Fuse/Strip stages still apply normally.

Adds five in-memory regressions covering terminal emoji, incomplete UTF-8, mixed interior/terminal runs, downstream cleanup, and PreTrainedTokenizer decoding with special-token filtering.

Validation on macOS / Swift 6.4, based on c21fdcd:

  • Original decoder: 1 test passed, 4 failed (6 recorded issues).
  • Fixed decoder and final formatted source: all 5 tests passed; the assertions were unchanged.
  • Strict Swift formatting passed for both changed files.
swift test --jobs 2 --no-parallel --filter ByteFallbackEndOfInputTests

This was a focused CPU-only package run using the actual decoder factory and tokenizer implementation. No pretrained-model downloads, GPU workloads, benchmarks, or full upstream test matrix were run.

Comment thread Tests/TokenizersTests/ByteFallbackEndOfInputTests.swift Outdated
Comment thread Tests/TokenizersTests/ByteFallbackEndOfInputTests.swift Outdated
@pcuenca
pcuenca merged commit 1987402 into huggingface:main Oct 28, 2026
4 checks passed
pcuenca added a commit that referenced this pull request Oct 28, 2026
Confirmed locally against the Python reference.
pcuenca added a commit that referenced this pull request Oct 28, 2026
* [CI] Test offline tokenizers tests on Linux

* Fix expectation after #414

Confirmed locally against the Python reference.
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.

2 participants