Skip to content

[Rust Frontend] Generate through an Llm trait - #82

Closed
BugenZhao wants to merge 36 commits into
mainfrom
bz/engine-client-trait
Closed

BugenZhao wants to merge 36 commits into
mainfrom
bz/engine-client-trait

Conversation

@BugenZhao

@BugenZhao BugenZhao commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Upstream: vllm-project#64695. This fork PR stays as the base of the stack below.

Motivation

TextLlm owns a concrete Llm, the token-level facade over the engine-core client, so the server, chat, and text layers can only run over engine-core. Frontends that put a network hop between the API layer and the engine, such as a router frontend in front of vllm-rs serve workers or a tokens-in/tokens-out gateway (vllm-project#63887), want to reuse rendering, tokenization, detokenization, and parsing while supplying their own generation backend.

This PR makes the Llm layer an interface: a lowered GenerateRequest goes in, raw GenerateOutputs come out. Detokenization (with per-token attribution) and stop strings stay with the caller, so the parsers keep their full input regardless of where the engine runs.

Changes

  • Rename the existing struct Llm to EngineCoreLlm (first commit, pure rename), so Llm can name the interface. In the Rust frontend, "engine" means engine-core; naming the interface EngineClient after Python would read as a synonym of EngineCoreClient.
  • vllm_llm::Llm: the generate/abort subset of Python's EngineClient, plus info(), health, and shutdown(). EngineCoreLlm implements it.
  • LlmInfo: model and engine facts fixed at creation that the upper layers read (effective context length, model dtype, LoRA support, vLLM version). model_dtype is optional; without it, multimodal inputs are rejected.
  • The trait requires Any and does not expose the engine-core client. The server's admin and utility routes downcast to EngineCoreLlm to reach it, so they keep working unchanged.
  • vllm_llm::Error gains Unsupported, Unavailable, RemoteInvalidRequest, and Remote. The existing variants all describe engine-core failures, so an implementation backed by something else had nothing to return. vllm-text classifies the first and third as request validation errors and adds is_unavailable(); vllm-chat forwards it.
  • TextLlm holds a Box<dyn Llm> and exposes it as llm(), replacing engine_core_client(); ChatLlm and the server read facts from LlmInfo. ChatLlm::engine_core_client() is removed.

No behavior changes: the server still always builds an EngineCoreLlm.

Stack

  1. [Rust Frontend] Generate through an Llm trait #82: Llm trait and error contract (this PR)
  2. [Rust Frontend] Let the server run over any Llm #83: HTTP API over any Llm
  3. [Rust Frontend] Remote Llm over an internal MessagePack gRPC service #84: internal MessagePack gRPC remote Llm

Validation

  • cargo clippy --workspace --all-targets --all-features, cargo fmt --check: clean, on both commits.
  • cargo nextest run -p vllm-llm -p vllm-text -p vllm-chat -p vllm-server -p vllm-cmd -p vllm-bench: 1417 passed.

Open questions

  • Error shape: by HTTP semantics there are three classes (invalid request, unavailable, other remote failure). Unsupported carries the field name for the OpenAI error param; it could fold into the invalid-request class.
  • Implementing the trait still compiles the ZMQ engine-core client in. Splitting the protocol types from the transport would let implementors depend on types only.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CJckCBxv8Gtnq23avKQwau

@BugenZhao
BugenZhao added this pull request to stack #85 October 29, 2026 12:30
@BugenZhao
BugenZhao force-pushed the bz/engine-client-trait branch from 659069a to 7736993 Compare October 29, 2026 13:41
@BugenZhao BugenZhao changed the title [Rust Frontend] Generate through an EngineClient trait [Rust Frontend] Generate through an Llm trait Oct 29, 2026
@BugenZhao
BugenZhao force-pushed the bz/engine-client-trait branch 5 times, most recently from 43da6d5 to 8de8a5d Compare November 3, 2026 06:31
BugenZhao and others added 2 commits November 4, 2026 08:17
`Llm` is the token-level generate/abort facade over the engine-core client.
Name it after what it drives, so that `Llm` can name the layer's interface
in the next commit. Pure rename.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CJckCBxv8Gtnq23avKQwau
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
`TextLlm` owned a concrete `EngineCoreLlm`, so the text, chat, and server
layers could only run over an engine-core client. Make `Llm` the layer's
interface, the generate/abort subset of Python's `EngineClient`, with
`EngineCoreLlm` as its engine-core implementation:

- `generate` takes a lowered `GenerateRequest` and streams raw
  `GenerateOutput`s; detokenization and stop strings stay above it.
- `info()` returns `LlmInfo`, the model and engine facts fixed at creation
  that the upper layers read (context length, model dtype, LoRA support,
  vLLM version).
- Health is two signals, as on the engine-core client: `subscribe_health`
  turns `false` only on a permanent failure (liveness), while
  `subscribe_readiness` follows whether new requests can be taken now, such
  as while engines are paused or asleep. The gRPC health services now read
  both from the `Llm`.
- The trait requires `Any`. Callers that need engine-core specifics, such as
  the server's admin and utility routes, downcast to `EngineCoreLlm`, so the
  trait itself does not expose the engine-core client.
- New `vllm_llm::Error` variants let implementations that are not backed by
  engine-core report rejected requests, unsupported fields, unavailability,
  and remote failures; `vllm-text` classifies the first two as request
  validation errors.

`TextLlm` now holds a `Box<dyn Llm>`, and `ChatLlm` and the server read
these facts from `LlmInfo`. No behavior changes.

Co-authored-by: Sage Ahrac <80211083+sagearc@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CJckCBxv8Gtnq23avKQwau
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
@BugenZhao
BugenZhao force-pushed the bz/engine-client-trait branch from 8de8a5d to 3b03253 Compare November 4, 2026 08:36
cjackal and others added 17 commits November 4, 2026 19:14
…mm limits (vllm-project#65689)

Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
…k merge (vllm-project#64129)

Signed-off-by: NickLucche <nicolo.lucchesi@mistral.ai>
…llm-project#65537)

Signed-off-by: Yifei Wang <yifei.w@inferact.ai>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
…llm-project#64782)

Signed-off-by: Eugene Rakhmatulin <erakhmatulin@nvidia.com>
Signed-off-by: Eugene Rakhmatulin <eugr@eugr.com>
Co-authored-by: Codex <noreply@openai.com>
…% GPU Memory saved for each draft model (vllm-project#65198)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
…space creation (vllm-project#65522)

Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
…~ 7.6% E2E Throughput Improvement (vllm-project#64760)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Signed-off-by: Woosuk Kwon <woosuk@inferact.ai>
Signed-off-by: James E T Smith <11277676+jamesETsmith@users.noreply.github.com>
Signed-off-by: jamesETsmith <james.smith9113@gmail.com>
Co-authored-by: Woosuk Kwon <woosuk@inferact.ai>
Co-authored-by: Yoni Gozlan <74535834+yonigozlan@users.noreply.github.com>
Co-authored-by: Bugen Zhao <i@bugenzhao.com>
Co-authored-by: Lain <fusiyuan2000@gmail.com>
Co-authored-by: kaiwu-reflection <kai@reflection.ai>
Co-authored-by: neilkg <33635204+neilkg@users.noreply.github.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: James E T Smith <11277676+jamesETsmith@users.noreply.github.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
…Humming (vllm-project#65542)

Signed-off-by: mgoin <mgoin64@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
…vllm-project#65540)

Signed-off-by: mgoin <mgoin64@gmail.com>
Signed-off-by: Misha Goin <mgoin64@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
…equests (vllm-project#65399)

Signed-off-by: Jakub Zakrzewski <jzakrzewski@nvidia.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
…ject#55688)

Signed-off-by: Andrii Skliar <askliar@nvidia.com>
Co-authored-by: Andrii Skliar <askliar@nvidia.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…rk, 960MB GPU memory saved each rank (vllm-project#65553)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
Co-authored-by: Taneem Ibrahim <taneem.ibrahim@gmail.com>
)

Signed-off-by: Thang Nguyen <thangnguyenvn647@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
vllm-project#62881)

Signed-off-by: Dudi Lester <dudi.lester@intel.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
gc-fu and others added 17 commits November 5, 2026 07:45
…oject#64479)

Signed-off-by: Guancheng Fu <guancheng.fu@intel.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
Co-authored-by: Kunshang Ji <kunshang.ji@intel.com>
…tic sharding (vllm-project#65585)

Signed-off-by: Thang Nguyen <thangnguyenvn647@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ith spawned engines (vllm-project#65234)

Signed-off-by: Thang Nguyen <thangnguyenvn647@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…ct#64677)

Signed-off-by: CharlesWu <Charles.Wu@amd.com>
Signed-off-by: Andreas Karatzas <akaratza@amd.com>
Co-authored-by: CharlesWu <Charles.Wu@amd.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
Co-authored-by: Claude <noreply@anthropic.com>
…ject#65552)

Signed-off-by: khluu <khluu000@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: khluu <khluu000@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… persistent buffer (vllm-project#65598)

Signed-off-by: Bo Pang <bopang@inferact.ai>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
…llm-project#60895)

Signed-off-by: Canlin <canlinguosdu@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
…ends (vllm-project#60762)

Signed-off-by: xzwgit <57032909+xzwgit@users.noreply.github.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
…ction end (vllm-project#65237)

Signed-off-by: Ouail Bendidi <ouail.bendidi@gmail.com>
Signed-off-by: Juntian Liu <Juntianl777@gmail.com>
Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai>
Co-authored-by: Ouail Bendidi <ouail.bendidi@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Yifan Qiao <yifanqiao@inferact.ai>
Co-authored-by: Codex <noreply@openai.com>
…llm-project#65593)

Signed-off-by: CJJ1008 <843515223@qq.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
Signed-off-by: Alex-Wengg <hanweng9@gmail.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
…ayers on MI355X (vllm-project#63027)

Signed-off-by: chao-xu-spec <chaox@amd.com>
Co-authored-by: Douglas Lehr <91553416+dllehr-amd@users.noreply.github.com>
…lm-project#65763)

Signed-off-by: khluu <khluu000@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…llm-project#65753)

Co-authored-by: v <v@inferact.ai>
Co-authored-by: Woosuk Kwon <woosuk@inferact.ai>
Signed-off-by: Woosuk Kwon <woosuk@inferact.ai>
…65773)

Signed-off-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@BugenZhao BugenZhao closed this Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.