Skip to content

[4/N atomesh rust runtime] feat(engine): EngineCore and CoreManager speak msgspec, not pickle - #3911

Open
Yuechguo wants to merge 1 commit into
yuechguo/atomesh-direct-3Nfrom
yuechguo/atomesh-engine-4N
Open

Yuechguo wants to merge 1 commit into
yuechguo/atomesh-direct-3Nfrom
yuechguo/atomesh-engine-4N

Conversation

@Yuechguo

@Yuechguo Yuechguo commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Every message between CoreManager and EngineCore is a pickled tuple whose payload is a whole Sequence, in both directions. A finished sequence returns every field although the frontend reads about fifteen, and pickle is Python-only, which keeps a Rust client (#3908's EngineClient) from talking to the Core.

#3908 (3/N) defined the protocol in atom/model_engine/zmq_protocol/messages.py as msgspec structs, which Rust mirrors. This PR puts the Python engine on it. msgpack through msgspec is under pickle on every measured path (encode + decode, one core, median of two runs; measured for #3372 against main's pickle at the time with bench_v2.py, not re-run here):

message case pickle msgspec ratio
STREAM bs 1, no logprobs 6.7 µs 2.2 µs 0.32x
STREAM bs 256, top20 logprobs 832 µs 528 µs 0.64x
Completion 64 x (1K in + 256 out) 1.68 ms 79 µs 0.05x
submit (incl. the Core building the Sequence) 1 x 1K tok 51 µs 16 µs 0.32x
submit 1 image (3x448x448) 3.3 ms 0.50 ms 0.15–0.20x
P/D submit, 8K remote_block_ids 285 µs 255 µs 0.90x

Series: #3908 (3/N, Rust: protocol, EngineClient, DirectDispatcher) -> this PR (4/N, Python engine on the protocol) -> #3912 (5/N, the launcher's --engine-dispatch direct). Nothing here changes what a client sees; the classic api_server, atomesh's TokenBridge and offline LLMEngine all run on it.

Technical Details

  • Codec (zmq_protocol/codec.py): each request goes as the SubmitItem that rebuilds its Sequence; each step's tokens as STREAM items; a finished request as a Completion that reads like the finished Sequence. Bulk numbers (tokens, logprobs, hashes) ride as little-endian bytes; media tensors beside their pickle as raw buffers. What only Python reads (utility commands and replies, metrics, KV-transfer params) is pickled inside its field. share_cache's DP_PREFIX_CREDIT / PREFILL_BACKLOG / DP_REUSE ride the same protocol.
  • Core-side admission (model_engine/admission.py): the Core builds each Sequence through build_sequence, filling in what it derives from its own config, and refuses what the frontend refuses, in its order: check_sampling, a structured request's execution options, the model's own validate_request, and check_prompt (an empty prompt; a media-kept decode leg's MRoPE delta outside its prompt, feat(engine): multimodal PD through the chat path #3410; RapidServe's refusal of such a leg). A client other than this frontend skips the frontend's checks. InputOutputProcessor.preprocess_fanout runs the same functions, so the two cannot drift.
  • Failure isolation: a request that does not encode (a lone surrogate in a string, which pickle carried), or whose result does not, ends alone as rejected: ...; a failed add leaves no request state behind, online or offline; a request refused at admission counts as ingested.
  • Abort hold: an abort that overtakes its submit is held in O(1) per miss (was a scan of every hold), in the RapidServe decode scheduler too.
  • A client's prefix_cache_hit_tokens is taken only as an int count of the prompt, else 0.
  • MRoPE positions are computed only for a model that has them (registry.uses_mrope), without copying the prompt otherwise.

Test Plan

Test Result

server smoke (15 checks) GSM8K
classic api_server TP1 12 pass, 2 known, 0 fail 0.8453 / 0.8537
classic api_server DP2 12 pass, 2 known, 0 fail 0.8408 / 0.8484
atomesh TokenBridge TP1 13 pass, 2 refused, 0 fail 0.8423 / 0.8544

"known" is main's behaviour (completions logprobs ignored; Qwen3 tool calls as text, no ATOM parser for its format); "refused" is the Rust frontend's documented 400 on logprobs. All within the run-to-run spread of earlier runs on this model (0.830–0.845 flexible).

Submission Checklist

  • Wire protocol checked against the Rust client both ways (cross-language fixtures)
  • Classic api_server and atomesh TokenBridge accuracy unchanged on GPU
  • No change to what a client sees

🤖 Generated with Claude Code

The CoreManager <-> EngineCore messages are the msgspec structs of
zmq_protocol/messages.py (3/N's spec, which atom/mesh's wire.rs mirrors),
encoded by zmq_protocol/codec.py, in place of pickled tuples whose payload
was a whole Sequence.

- Submit: each sequence goes as the SubmitItem that rebuilds it; the Core
  builds its Sequence through admission.build_sequence, which fills in what
  it derives from its own config and refuses what the frontend refuses
  (check_sampling, structured execution options, the model's own
  validation, an empty prompt, a media-kept decode leg's MRoPE delta and
  RapidServe's refusal of one), since a client other than this frontend
  skips the frontend's checks. LLMEngine's InputOutputProcessor runs the
  same rules from admission.
- Output: STREAM items and finished Completions that read like the
  finished Sequence; share_cache's DP_PREFIX_CREDIT / PREFILL_BACKLOG /
  DP_REUSE ride the same protocol; metrics and utility replies are pickled
  inside their message.
- A request that does not encode, or whose result does not, ends alone as
  rejected; a failed add leaves no request state behind.
- An abort that overtakes its submit is held in O(1), in the decode
  scheduler too; a request refused at admission counts as ingested.
- A client's prefix_cache_hit_tokens is taken only as an int count of the
  prompt.

The cross-language fixtures 3/N's Rust tests read are checked from Python
too (test_engine_wire_cross_language).

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant