Uh oh!
There was an error while loading. Please reload this page.
llm_runner: add streaming text boundary helpers - #20242
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20242
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 6 PendingAs of commit ee1ea74 with merge base d7ca5db ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a |
There was a problem hiding this comment.
Pull request overview
Adds runner-level helper utilities to make incremental text streaming safer by (1) avoiding emission of incomplete UTF-8 sequences and (2) avoiding emission of prefixes that could still be part of a stop-string match across chunk boundaries. This supports the broader goal of making ExecuTorch’s LLM serving stack streaming-correct without duplicating fragile string logic across server paths.
Changes:
- Introduces
utf8_complete_prefix_len()to compute a UTF-8-safe emit prefix length. - Introduces
stop_safe_prefix_len()to compute a stop-string-safe emit prefix length (with UTF-8 boundary snapping) and astop_hitsignal. - Adds focused unit tests for both helpers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| extension/llm/runner/util.h | Adds UTF-8 boundary and stop-string boundary helper functions for streaming-safe text emission. |
| extension/llm/runner/test/test_util.cpp | Adds unit tests covering UTF-8 prefix handling and stop-string-safe prefix handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
2ceae8c to
f0bc5c8Comparemergennachin
commented
Jun 12, 2026
@claude Review this PR |
Claude finished @mergennachin's task in 2m 15s —— View job Review: |
The serving stack streams decoded text incrementally, but token boundaries do not guarantee user-visible text boundaries. A chunk can end in the middle of a UTF-8 sequence, or immediately before bytes that complete a configured stop string. Handling that ad hoc in each server path would make streaming correctness easy to regress. This adds small, model-agnostic runner helpers for computing UTF-8-safe and stop-string-safe prefixes before emitting text. Keeping the logic in the runner utility layer gives both generic and model-specific workers one tested implementation instead of duplicating fragile string handling. The change is intentionally narrow: it introduces pure helper functions and focused unit coverage only. It does not change runner generation behavior on its own.
f0bc5c8 to
ee1ea74CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
mergennachin
commented
Jun 12, 2026
@claude Validate the last copilot comments, wdyt? |
Claude finished @mergennachin's task in 1m 15s —— View job Validating the latest Copilot commentsI read 1. |
Uh oh!
There was an error while loading. Please reload this page.
The serving stack streams decoded text incrementally, but token boundaries do not guarantee user-visible text boundaries. A chunk can end in the middle of a UTF-8 sequence, or immediately before bytes that complete a configured stop string. Handling that ad hoc in each server path would make streaming correctness easy to regress.
This adds small, model-agnostic runner helpers for computing UTF-8-safe and stop-string-safe prefixes before emitting text. Keeping the logic in the runner utility layer gives both generic and model-specific workers one tested implementation instead of duplicating fragile string handling.
The change is intentionally narrow: it introduces pure helper functions and focused unit coverage only. It does not change runner generation behavior on its own.
#20001