Skip to content

Add bounded LLM worker cancellation - #22070

Open
seyeong-han wants to merge 3 commits into
pytorch:mainfrom
seyeong-han:llm-server/worker-cancellation
Open

Add bounded LLM worker cancellation#22070
seyeong-han wants to merge 3 commits into
pytorch:mainfrom
seyeong-han:llm-server/worker-cancellation

Conversation

@seyeong-han

Copy link
Copy Markdown
Contributor

Summary

Add bounded cancellation for the existing process-isolated LLM worker protocol.

  • Negotiate supports_cancel and pass monotonically increasing request IDs over JSONL.
  • Deliver cancellation out of band through an inherited POSIX pipe, so stop() never waits behind the blocking request/response lock.
  • Cooperatively call LLMSession::stop() once at the next decode boundary. Cancelled sessions are marked dirty and reset before reuse.
  • If cooperative cancellation misses its grace period, terminate/kill/reap the worker, fail queued and future work, and report /health as unavailable. Model reload remains the supervisor's responsibility.
  • Keep older and non-POSIX workers compatible; they do not advertise cancellation and use the bounded process-termination fallback.

Review guide:

  1. Python transport and process lifecycle: examples/llm_server/python/worker_client.py.
  2. Async cancellation, escalation, and health: examples/llm_server/python/session_runtime.py, serving_chat.py, and server.py.
  3. Native request controller and dirty-on-cancel semantics: examples/llm_server/cpp/worker_loop.h.
  4. MuseGlimmer custom-loop integration: examples/models/muse-glimmer/runtime/runners/muse_glimmer_worker.cpp.
  5. The remaining changes are focused tests, documentation, and thread linkage for worker targets that include the shared controller.

Cancellation remains token-boundary cooperative: it cannot interrupt active prefill, vision preparation, or an in-progress backend invocation. The process fallback provides the bound in those cases.

Test plan

  • pytest -q examples/llm_server/python/tests (229 passed, 6 skipped)
  • Built and ran test_worker_loop and test_worker_prefill_plan (2/2 CTests passed)
  • Built and linked the MLX muse_glimmer_worker, qwen3_5_moe_worker, and gemma4_31b_worker targets
  • Ran the real loopback Uvicorn/socket disconnect test five consecutive times
  • Ran exact-file Python, C++, CMake, and documentation linters

@pytorch-bot

pytorch-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit ca6c74a with merge base cff6f4d (image):
💚 Looks good so far! There are no failures yet. 💚

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 Aug 24, 2026
@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.

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.

1 participant