Add bounded LLM worker cancellation - #22070
Conversation
🔗 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 FailuresAs of commit ca6c74a with merge base cff6f4d ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@claude review this code |
|
Claude finished @metascroy's task in 9m 7s —— View job Code Review: Add bounded LLM worker cancellation
Overall this is a careful, well-documented design. The out-of-band POSIX pipe keeps Observations1. Client-side stop-string detection now delivers a real worker cancellation (behavior change worth confirming)
The 2. except BlockingIOError:
self._cancel_delivery = False
return False
3. Dropped preactivation frame if a cancel arrives for a not-yet-active request while another is active — if (active_session_ != nullptr) {
if (request_id == active_request_id_) { cancel_active_locked(); }
return; // conflicting active IDs are never queued for a later request
}A frame for request N+1 arriving while N is still active is silently dropped rather than parked in Minor / nits
Nice work — the cancellation state machine and its seal/dirty invariants are the tricky part and they read as correct to me. Happy to dig deeper into any specific path if useful. |
Summary
Add bounded cancellation for the existing process-isolated LLM worker protocol.
supports_canceland pass monotonically increasing request IDs over JSONL.stop()never waits behind the blocking request/response lock.LLMSession::stop()once at the next decode boundary. Cancelled sessions are marked dirty and reset before reuse./healthas unavailable. Model reload remains the supervisor's responsibility.Review guide:
examples/llm_server/python/worker_client.py.examples/llm_server/python/session_runtime.py,serving_chat.py, andserver.py.examples/llm_server/cpp/worker_loop.h.examples/models/muse-glimmer/runtime/runners/muse_glimmer_worker.cpp.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)test_worker_loopandtest_worker_prefill_plan(2/2CTests passed)muse_glimmer_worker,qwen3_5_moe_worker, andgemma4_31b_workertargets