Skip to content

extension/llm/server: isolated multi-session serving (V2a)#20159

Open
mergennachin wants to merge 2 commits into
gh/mergennachin/8/headfrom
gh/mergennachin/9/head
Open

extension/llm/server: isolated multi-session serving (V2a)#20159
mergennachin wants to merge 2 commits into
gh/mergennachin/8/headfrom
gh/mergennachin/9/head

Conversation

@mergennachin

Copy link
Copy Markdown
Contributor

A worker now hosts one LLMEngine (weights loaded once) and serves multiple
isolated sessions keyed by session_id, each with its own KV/recurrent state, up
to the engine's serving capacity -- so one ~18GB model load backs many
independent conversations instead of one. Execution stays synchronous (one
in-flight request; the control plane serializes): this is isolation, not
concurrent streaming.

The shared worker loop (worker_loop.h) owns the sessions. Named sessions are
created on first use (or an open op) and capped at capacity-1; one slot is
reserved for a scratch session that serves anonymous, session-less requests.
Over-capacity or single-session backends return structured errors
(capacity_exhausted / unsupported_session); there is no eviction/TTL in the MVP,
so capacity_exhausted stands when named sessions exceed worker capacity. Both
workers (text_llm_worker, qwen3_5_moe_worker) now pass their LLMEngine to the
loop.

The control plane (over the SessionRuntime boundary introduced earlier) routes a
request to a session via the session_id body field or, as header aliases,
X-ExecuTorch-Session-ID / session_id / x-session-affinity (body wins, then that
header order). The aliases let a client that already emits a stable
per-conversation affinity id (e.g. pi's sendSessionAffinityHeaders) route with no
client-specific server code. The session is admitted up front (so a capacity
refusal is HTTP 429/400 before any stream bytes), and DELETE /v1/sessions/{id}
frees one.

Review order: worker_loop.h (session ownership + protocol), then the two
workers; then the control plane (protocol.py, errors.py, serving_chat.py,
server.py, serve.py); then tests.

Part of #20001

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 5 New Failures, 4 Unrelated Failures, 2 Unclassified Failures

As of commit 8d71e8e with merge base eeb0646 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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

[ghstack-poisoned]
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