Repository navigation
[LLM runner] Keep stop() requests made during prefill - #25101
Open
abdelaziz-mahdy wants to merge 1 commit into
Open
abdelaziz-mahdy wants to merge 1 commit into
abdelaziz-mahdy wants to merge 1 commit into
Conversation
TextTokenGenerator::generate() cleared the stop flag when its decode loop started, after prefill, so a stop() that arrived during prefill was lost and generation ran to max_new_tokens. TextLLMRunner and MultimodalRunner now clear the flag when generate() starts, before prefill, and ask the generator not to clear it again (new reset_stop argument, default true, so other callers are unchanged). The decode loop also checks the flag before each step. Fixes pytorch#25100
abdelaziz-mahdy
requested review from
larryliu0820 and
mergennachin
as code owners
November 15, 2026 14:12
This PR needs a
|
This branch has not been deployed
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.
Summary
Fixes #25100.
Bug: a
stop()that arrives while the prompt is being prefilled is lost.TextTokenGenerator::generate()clears the stop flag when its decode loop starts, after prefill, so generation runs tomax_new_tokens.Fix
TextTokenGenerator:reset_stop()clears the flag;generate()takesreset_stop(defaulttrue, so existing callers behave as before);TextLLMRunner::generate()andMultimodalRunner::generate():reset_stop()when they start, before prefill;reset_stop=false.Result
generate()still doesn't carry into it.Test plan
New tests in
extension/llm/runner/test/test_text_llm_runner.cpp:StopDuringPrefillEndsGeneration:StopBeforeGenerateDoesNotCarryOver: passes.Run on macOS arm64 (Release,
-DEXECUTORCH_BUILD_TESTS=ON -DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON):The changed files are clang-format clean.