Skip to content

[ATOM gRPC] atomesh: discover ATOM gRPC workers and run ATOM P/D over gRPC - #3676

Open
Jasen2201 wants to merge 94 commits into
jasen/atom-grpc-d-mesh-clientfrom
jasen/atom-grpc-e-mesh-discovery-pd
Open

Jasen2201 wants to merge 94 commits into
jasen/atom-grpc-d-mesh-clientfrom
jasen/atom-grpc-e-mesh-discovery-pd

Conversation

@Jasen2201

@Jasen2201 Jasen2201 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Part E of the 8 PRs proposed in #3657 (regrouped by function). No blocking issues.

Based on D, which it needs.

Why

An ATOM gRPC port never registered with atomesh, DP-aware discovery asked HTTP for its DP size, and a P/D pair of ATOM workers went through SGLang's dual dispatch, so D never got P's KV.

What changed

  • Detection probes ATOM after SGLang and vLLM, keeping the runtime that answered; it refuses an unhealthy ATOM worker, and another protocol version without retries. GetModelInfo's fields become labels.
  • An ATOM chat renders as HTTP does, with the worker's template and kwargs unless --chat-template is set. A model's live workers serve one template; its last worker leaving drops the tokenizer. A model with ChatControls (DeepSeek V3.2/V4/V4.1, Kimi-K3) renders with its encoder, as main's chat_render does; a template model whose ATOM worker reports no template, with no --chat-template, gets 501 naming HTTP routing.
  • With --dp-aware, an ATOM worker's DP size comes from GetServerInfo; a url@rank gRPC worker of any runtime connects to its instance's URL.
  • With --kv-events, an ATOM gRPC worker's KV event sources come from GetServerInfo, as an HTTP worker's do; other gRPC workers are skipped.
  • AtomPairs (engine/atom/pair.rs) keeps ATOM's HTTP P/D flow: relay, or chunked. P's GetServerInfo is read once per instance within its health timeout (504), again after re-registration; a mixed ATOM/non-ATOM pair gets 500.

Size: over 1,000 lines and 15 files: P/D pairs workers only discovery registers, with their ranks.

Review focus

  1. The @rank connect fix reaches SGLang and vLLM ranks too.
  2. Where the pair's loads live; the status each failure answers.

Testing

Stubs: registration (labels, parsers, ranks, runtime, health, one template per model, admission/teardown races, stale jobs, placement); relay, chunked, cancels, idx2idx; refusals; prefill re-reads.

jasen/atom-grpc-e-mesh-discovery-pd @ 2d4da70: all tests pass (Evidence); fmt clean; 1 new clippy warning.

Follow-ups

none

What changed, in detail
  • One template per model: an ATOM worker whose template (ranked as placement ranks it, below) differs from the one its model's tokenizer carries (while that tokenizer still loads, the one the model's registered workers serve) is refused at registration while another worker of the model is registered; the check and the registry insert run under one lock, and so do a model's last worker's leaving and the drop of its tokenizer. A tokenizer job a worker's registration submitted keeps nothing it loaded once that worker is gone. A chat carries the template its prompt rendered with (RenderedTemplate), and placement offers it only the ATOM workers serving that template (their own file, else the file the tokenizer was loaded with, else --chat-template, else the one they advertised, as the chat's fingerprint ranks them); with none, it gets a 503 chat_template_changed, to retry. A chat's tokenizer and what it was loaded with come from one registry lookup.
Stack

ATOM serves atom.grpc.v1.AtomEngine beside its HTTP server (token ids in, token ids out, ATOM's P/D flow unchanged), and atomesh routes to ATOM gRPC workers over a Generate call per request or one Session per instance. One linear stack, merged bottom to top: A, B, C, D, E, F, G, H; each PR's base is the one before it.

Evidence

In atom/mesh (rustc and clippy 1.100.0), at 2d4da70: cargo fmt --check and cargo clippy --all-targets with and without atom-engine pass.

cargo test --features atom-engine --lib            1475 passed, 0 failed, 8 ignored
cargo test --features atom-engine --test <each>    304 passed, 0 failed
cargo test --lib                                   1470 passed, 0 failed, 8 ignored
cargo test --test <each>                           304 passed, 0 failed

a_leaving_last_worker_keeps_the_tokenizer_a_same_template_worker_was_admitted_with fails without the tokenizer-teardown lock (3 of 3 runs) and passes with it.

Clippy against D (warnings matched by message and file):

[clippy] base 110, branch 111, new 1, gone 0
[clippy-ae] base 110, branch 111, new 1, gone 0

The new one: result_large_err on lookup_tokenizer_entry, which returns a Response error as lookup_tokenizer beside it does.

🤖 Generated with Claude Code

… gRPC

Without a runtime flag atomesh probes a gRPC worker as SGLang, then vLLM,
then ATOM, and an ATOM worker registers with the labels GetModelInfo
returns: model and tokenizer paths, served name, context length, EOS ids,
chat template, default template kwargs and reasoning markers. The
tokenizer job renders an ATOM chat with the label's template when no flag
names one, and merges the default template kwargs under the request's own;
a server of another protocol version is refused without retries.

With `--dp-aware`, `get_dp_info` asks an ATOM gRPC worker's GetServerInfo
for its DP size and model id, chosen by the same `determine_runtime_type`
worker creation uses; HTTP workers keep `/server_info`.
`BasicWorker::get_grpc_client` strips a worker's `@rank` suffix before
connecting, which fixes rank workers' connects and health checks for
SGLang and vLLM too.

A pair of ATOM gRPC workers goes to `AtomPairs` (`engine/atom/pair.rs`),
which keeps ATOM's HTTP P/D flow. Relay runs P with streaming off and
max_tokens 1, releases P's load when P completes, and sends D the enriched
kv_transfer_params; chunked starts P and D together and returns D's stream
only after P completes, a failure on either side cancelling the other. P's
transfer info comes from GetServerInfo through the shared
`parse_atom_prefill_info`, P is picked by the shared rank mapping, and
`Dispatcher::holds_load` keeps the pipeline from taking a second pair.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jasen2201 and others added 6 commits November 22, 2026 13:44
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…omesh discovery and P/D

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… P/D

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wanzhenchn

Copy link
Copy Markdown
Contributor

With --kv-events, ATOM gRPC workers get no KV events and no Mooncake Store sources, so cache_aware places their requests by the approximate tree alone.

FollowKvEventsStep skips every worker that isn't ConnectionMode::Http: it reads the sources from the worker's HTTP /kv_event_sources, and the router knows a gRPC worker only by its gRPC address. With no indexed events for the candidates, cache_aware leaves the choice to the tree. The Store tier (#3340, #3344) is out too, since its stores come in the same response. The step skips without a warning, so a gRPC run with --kv-events looks normal. No PR in this stack touches the step, kv_events/ or kv_storage/.

A small fix, following how GetServerInfoResponse already carries the bodies of /kv_transfer_info and /server_info:

  1. ATOM: add string kv_event_sources_json = 4; // the body of /kv_event_sources. That body is fixed for the engines' lifetime (engine_core_mgr.py).
  2. Mesh: for an ATOM gRPC worker, have the step read that field from GetServerInfo, as get_atom_grpc_server_info reads server_info_json, and pass it to the same parse with the gRPC URL's host. The subscriptions, the Store sources and cache_aware stay as they are.

Could you cover this in the stack, or as a follow-up on top of it? It is the remaining piece for tiered cache-aware routing over gRPC P/D.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jasen2201 added a commit that referenced this pull request Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jasen2201
Jasen2201 added this pull request to stack #3735 November 23, 2026 07:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:45
@Jasen2201

Copy link
Copy Markdown
Collaborator Author

Fixes the template-replacement races at their source in 02e31a7: all live workers of a model serve one template. A worker with another template is refused at registration while one is registered; changing it is a redeploy, and an ATOM model's last worker leaving drops its tokenizer. This supersedes the swap-aware /v1/tokenize lookup (bae97a5), the placement check (46055b2) and the stale-job guards (9f34019, 731d59d), now removed; E's diff shrinks by about 670 lines.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error::internal_error("model_id_not_set", "model_id not set in request")
})?;
let tokenizer = lookup_tokenizer(model_id_str, &components.tokenizer_registry)?;
let workers = components.worker_registry.get_by_model(model_id_str);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 16076b3. A chat carries the fingerprint of the template its tokenizer was loaded with (RenderedTemplate), and placement offers it only ATOM workers serving that template: own file, else --chat-template, else the advertised one. With none, or a tokenizer dropped mid-render, it gets a retryable 503 chat_template_changed. Test: test_a_chat_is_placed_only_on_workers_serving_its_template.

Jasen2201 and others added 2 commits November 24, 2026 13:58
A worker's tokenizer job could still be queued or loading when the worker,
its model's last, was removed. A successor with another template then
registered, as no tokenizer was loaded yet, and the old job published the
removed worker's template; the successor's own job found the model loaded
and every chat for it rendered with the old template. A job a worker's
registration submits now names that worker, and once it has loaded, drops
what it loaded unless that worker is still registered serving the job's
template. The check runs after publishing, under the model's registration
lock: a removal that ran before it is seen, and one that runs after it finds
the tokenizer and drops it with the model's last worker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When an ATOM model's last worker leaves, its tokenizer goes with it, and a
successor may register with another template. A chat that rendered with the
old tokenizer meanwhile was placed from the live registry, and its ids went
to the successor, which reads them with its own template. A chat now
carries the template its prompt rendered with (`RenderedTemplate`: the
fingerprint of the file or text the tokenizer was loaded with, read with
that tokenizer), and placement offers it only the ATOM workers serving that
template: a worker's own file, else --chat-template, else the one it
advertised. When a pool has none, or the tokenizer was dropped while the
prompt rendered, the chat gets a 503 chat_template_changed, to be retried.
A prompt ATOM rendered is not bound, nor is a worker other than ATOM's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread atom/mesh/src/routers/prepare/mod.rs Resolved
Comment thread atom/mesh/src/routers/prepare/mod.rs Resolved
Jasen2201 and others added 2 commits November 24, 2026 15:00
… lookup

Chat preparation looked the tokenizer up by name and, on a miss, again
through `TokenizerRegistry::get`. A tokenizer job publishing between the two,
or a model named by the tokenizer's id, left preparation with a tokenizer but
no registry entry, so it skipped the built-in-encoder refusal and the
template fingerprint placement binds the chat with. One lookup (name, then
id, as `get` reads) now returns both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt does

A chat's template fingerprint ranks the file its tokenizer was loaded with
first, but placement compared an ATOM worker's template against
`--chat-template` alone. A tokenizer added with `chat_template_path` and no
worker or router file rendered every chat with that file and then had no
worker serve it: 503 `chat_template_changed`. The fallback a worker without
its own file serves is now the tokenizer's file, else `--chat-template`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An ATOM worker is checked against the template its model's tokenizer was loaded
with. Before that tokenizer has loaded there was nothing to check against, so a
second worker with another template registered and went active beside the first;
once the first one's template loaded, the second's chats answered 503
chat_template_changed for as long as both stayed. With no tokenizer loaded yet,
the template the model's registered workers serve (recorded when each registered,
before its tokenizer job) is now the one a new worker must match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…e an advertised one

Admission read an ATOM worker's template as its own file, else --chat-template,
else the template it advertised, and placement as its own file, else the file the
model's tokenizer was loaded with, else --chat-template, else the advertised one.
A tokenizer registered with a template file therefore took a worker advertising a
template for another template: the first such worker dropped the file-backed
tokenizer and reloaded it with the advertised template, and later ones were refused.
Admission now ranks the templates as placement does, so the file is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Concurrent registrations can admit conflicting templates before either worker is published, leaving a registered worker unusable and potentially causing every chat request for a P/D model to return 503.

6 open issues
1 resolved since last review

Review effort: Balanced

@Jasen2201

Copy link
Copy Markdown
Collaborator Author

Fixes the review's registration-race point in 7f44954. While a model's tokenizer is still loading, a new ATOM worker is checked against the template the model's registered workers serve, so a worker with another template is refused, not activated. Test: a_worker_with_another_template_is_refused_while_the_tokenizer_loads.

…step

The template check ran when the worker was created and the worker was published
a step later, so two registrations with different templates could both pass the
check before either was registered, leaving a model with two templates. The check
now runs in the register step, under one lock with the registry insert: of two
concurrent registrations with different templates, the second sees the first's
workers and is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because tokenizer cleanup can race with same-template worker registration, deleting a tokenizer still in use and causing chat and text-completion requests to fail with 500 errors.

6 open issues

Review effort: Balanced

@Jasen2201

Copy link
Copy Markdown
Collaborator Author

Fixes the review's template-file point in 356436b. Admission now ranks a worker's template as placement does: its own file, then the file the model's tokenizer was loaded with, then --chat-template, then the advertised one. A tokenizer loaded with a file keeps it when workers that only advertise a template register. Test: a_tokenizer_s_template_file_wins_over_an_advertised_template.

… admitted with

Removing a model's last ATOM worker checked that none was left and then dropped the
model's tokenizer. A worker with the same template could be admitted against that
tokenizer and registered in between, its tokenizer job finding the tokenizer
loaded, and be left serving a model without one. The check and the drop now run
under the admission lock, so such a worker is registered before the check and
keeps the tokenizer, or is admitted after the drop and loads it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because interacting worker-update and tokenizer-loading lifecycles can leave mismatched templates or stale tokenizers active, causing persistent chat failures or incorrect tokenization.

6 open issues

Review effort: Balanced

@Jasen2201

Copy link
Copy Markdown
Collaborator Author

Fixes both registration races from the last two reviews:

  • Two different templates both passing the check: c0780dd checks the template in the register step, under one lock with the registry insert. Test: of_two_concurrent_registrations_with_different_templates_one_is_admitted.
  • Tokenizer cleanup racing a same-template registration: 2d4da70 runs the last-worker check and the tokenizer drop under that lock, so the new worker keeps the tokenizer or loads it again. Test: a_leaving_last_worker_keeps_the_tokenizer_a_same_template_worker_was_admitted_with, failing without the change.

@Jasen2201

Copy link
Copy Markdown
Collaborator Author

No blocking issues: all six are fixed or answered in their threads, and none needs a change at 2d4da70. A model's live workers serve one template, admitted under the lock of the registry insert (c0780dd) that the last-worker tokenizer drop also takes (2d4da70). A chat goes only to workers serving its RenderedTemplate, else 503 chat_template_changed (planner.rs:204-228).

Per issue
  • r4677559030, r4676676842, r4674638479 (a chat rendered with another template than its worker's): the placement filter above, 16076b3.
  • r4676676771 (idx2idx remap): the mapped prefill is another DP rank of the planned prefill's own instance ({base_url}@{rank}, placement/backend/atom.rs:268), one ATOM server with one template. A different template there is a redeploy, refused while D is registered.
  • r4670531006 (D's load after the client leaves): cbf9011.
  • r4666896811 (built-in DeepSeek encoders): 4b869b3.

…sh discovery and P/D

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +53 to +56
AtomPairs::new(
worker_registry.clone(),
ctx.router_config.atom_pd_rank_mapping_policy,
)
Main renders every chat in Rust: a checkpoint with ChatControls renders with
its encoder, and one llm-tokenizer renders with an uncontrolled built-in
encoder is refused at registration. So chats_without_template and the
built-in-encoder 501 go; prepare_chat renders a model with controls through
chat_render, bound to no template, and keeps the ATOM worker's default
kwargs, reasoning toggle and template fingerprint for template models.
forget_tokenizer drops the controls with the rest. Test plans carry
prefill_tokens: 0, and the 501 tests now check the controlled render.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// ATOM is sent the text as well; an ATOM worker must serve the same template.
pub fn served_by(&self, worker: &dyn Worker) -> bool {
worker.metadata().runtime_type != RuntimeType::Atom
|| served_template(worker, self.fallback_file.as_deref()) == self.fingerprint
.map_err(|e| error::internal_error("invalid_reasoning_toggle", e))?;

let (text, prompt_opener) = match controls {
Some(_) => chat_render::render_chat(&body_ref, sent, &*tokenizer, controls),

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.

4 participants