Skip to content

fix(scheduler): match stop strings with incremental decoding - #464

Open
taking-lying-flat wants to merge 1 commit into
FlashML-org:mainfrom
taking-lying-flat:fix/stop-string-decoding
Open

taking-lying-flat wants to merge 1 commit into
FlashML-org:mainfrom
taking-lying-flat:fix/stop-string-decoding

Conversation

@taking-lying-flat

Copy link
Copy Markdown
Contributor

A stop string such as 🧬 can span four byte tokens despite having one Python character. The scheduler's character-sized token window could decode only part of it and let generation continue past the stop.

Reuse the frontend's incremental decode state for scheduler matching. Preserve the token context needed to finish decoding characters, and bound only the retained matching text. Keep both sides consistent when a frontend batch contains multiple messages for one request and when an ignored EOS participates in a matched stop. No new tokenizer dependency or model-specific handling is introduced.

Validation on Linux x86_64, Intel Core i7-12800HX, Python 3.12.13; CPU only, with no model checkpoint or GPU inference. Host GPU: NVIDIA RTX A1000 Laptop GPU (4 GiB), driver 595.84.

  • Local regression harness: 54 cases covering explicit UTF-8 byte tokens, Hugging Face ByteFallback/ByteLevel, WordPiece cleanup, Unicode stops, streaming clipping, EOS, and overlapping scheduler completion. Against base 08d728d5, 32 failed and 22 passed; all 54 pass with this change. The harness is retained locally and is not included in this PR.
  • Existing tokenizer, request, message, generation and prepare-stop accounting tests: 60 passed, 4 skipped because Qwen VL checkpoints were unavailable. Combined with the local harness: 114 passed, 4 skipped.
  • git diff --check passed.

Commands run from the source checkout:

PYTHONPATH=python /tmp/freetoken-glm-shared-venv/bin/python -m pytest /tmp/freetoken-stop-validation/test_stop_strings.py tests/tokenizer tests/scheduler/test_req_append_host.py tests/server/test_message_wire.py tests/server/test_generation_accounting.py -q --tb=short
PYTHONPATH=python timeout 30 /tmp/freetoken-glm-shared-venv/bin/python -m pytest tests/server/test_prepare_stop_accounting.py -q --tb=short -o faulthandler_timeout=10

JUNQINGV587 added a commit to JUNQINGV587/FreeToken that referenced this pull request Sep 23, 2026
Stop matching now runs on the same incrementally decoded text the frontend produces
(DecodeStatus.update, with partial-UTF-8 hold-back) instead of decoding a bounded suffix
of the generated tail on every step, and a terminal EOS the frontend would not emit is
excluded (including at the output limit under ignore_eos).

Conflict resolution: python/freetoken/core.py -- this fork's extra Req field
(output_token_counts) sits exactly where upstream added stop_decode_status; kept both.

Verified: tests/tokenizer/ tests/scheduler/ tests/server/test_prepare_stop_accounting.py
=> 226 passed, 9 skipped.
KarrAcaRn pushed a commit to KarrAcaRn/FreeToken-ByAI that referenced this pull request Oct 3, 2026
… with incremental decoding

Assisted-by: Claude Opus 5.5
KarrAcaRn pushed a commit to KarrAcaRn/FreeToken-ByAI that referenced this pull request Oct 3, 2026
Upstream PR FlashML-org#464 shipped without tests. With a byte-level tokenizer (a CJK
character or emoji spans several tokens, as in byte-level BPE) the old
max_chars+1-token window never matched a CJK stop, could match the
replacement character of a half-decoded emoji, and the detokenizer then failed
to trim the stop. Four of the five tests fail before the PR.

Assisted-by: Claude Opus 5.5

This branch has not been deployed

No deployments
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.

1 participant