Skip to content

[LLM runner] Keep stop() requests made during prefill - #25101

Open
abdelaziz-mahdy wants to merge 1 commit into
pytorch:mainfrom
abdelaziz-mahdy:fix/llm-stop-during-prefill
Open

abdelaziz-mahdy wants to merge 1 commit into
pytorch:mainfrom
abdelaziz-mahdy:fix/llm-stop-during-prefill

Conversation

@abdelaziz-mahdy

Copy link
Copy Markdown
Contributor

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 to max_new_tokens.

Fix

  • TextTokenGenerator:
    • new reset_stop() clears the flag;
    • generate() takes reset_stop (default true, so existing callers behave as before);
    • the loop also checks the flag before each step.
  • TextLLMRunner::generate() and MultimodalRunner::generate():
    • call reset_stop() when they start, before prefill;
    • then call the generator with reset_stop=false.

Result

  • Stop during prefill: only the token prefill produced is emitted, and no decode steps run.
  • A stop from before generate() still doesn't carry into it.

Test plan

New tests in extension/llm/runner/test/test_text_llm_runner.cpp:

  • StopDuringPrefillEndsGeneration:
    • fails without the fix: the decoder runs 9 steps and the callback fires 10 times;
    • passes with it: 1 callback, 0 steps.
  • StopBeforeGenerateDoesNotCarryOver: passes.

Run on macOS arm64 (Release, -DEXECUTORCH_BUILD_TESTS=ON -DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON):

cmake --build cmake-out --target test_runner
./test_runner --gtest_filter='RunnerTest.*:*TextPrefiller*:*TextDecoderRunner*:*GenerationConfig*:*TextStream*'
[  PASSED  ] 57 tests.

The changed files are clang-format clean.

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
Copilot AI balanced review requested due to automatic review settings November 15, 2026 14:12
@pytorch-bot

pytorch-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25101

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 25 Awaiting Approval

As of commit bc35054 with merge base d3369c4 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

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

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLM runner: stop() during prefill is ignored

2 participants