Skip to content

[ATOM gRPC] The atom.grpc.v1 service: proto, generated modules, info, Generate, Abort and structured output - #3673

Open
Jasen2201 wants to merge 44 commits into
mainfrom
jasen/atom-grpc-b-proto-server
Open

Jasen2201 wants to merge 44 commits into
mainfrom
jasen/atom-grpc-b-proto-server

Conversation

@Jasen2201

@Jasen2201 Jasen2201 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

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

Based on A, the PR below it; it uses none of A's code.

Why

ATOM served HTTP only: a router that renders and tokenizes chats itself had no ATOM service to send token ids to and read tokens back from.

What changed

  • atom_grpc.proto defines atom.grpc.v1.AtomEngine, reusing engine_v1's SamplingParams and TokenIds; generate.py writes the committed modules (grpcio-tools 1.78.0), and pyproject.toml declares grpcio and protobuf>=6.31.1,<7.
  • --grpc-port serves it from the engine's process, in the AtomGrpcServer thread. HealthCheck, GetServerInfo and GetModelInfo answer what /health, /kv_transfer_info, /server_info and /kv_event_sources answer. GetModelInfo also names atomesh's parsers (router_parser_names), streamed usage placement (usage_on_finish) and an implicit reasoning opener.
  • Generate admits token ids through /v1/completions' checks, streams one chunk per engine step and answers refusals with the route's status. It passes the session-affinity ids to preprocess, and its complete carries ttft_s, tpot_s and latency_s, timed at engine delivery as generate_async does.
  • An unstreamed n above 1 fans out through preprocess_fanout: one complete per sibling, with its index. Greedy n above 1 collapses to 1 as on HTTP; streamed or P/D n above 1 is a 400. Abort and a failed submission end every sibling; a cancel aborts a structured submission once enqueued.
  • A chat's StructuredOutput gets the fields ATOM's HTTP chat derives; PrepareStructuredOutput answers them.

Size: over 1,000 lines, as the contract and its server: neither is testable alone.

Review focus

  1. AtomEngineServicer._admission against _completions: same checks, same order.
  2. Generate's sibling loop and its per-sibling teardown.

Testing

jasen/atom-grpc-b-proto-server @ c4da343: tests/test_grpc_server.py (Generate, Abort and the info RPCs over a fake engine), tests/test_grpc_proto.py, test_io_processor_fanout.py and test_dp_load_balance.py, 290 passed; ruff, black clean.

Follow-ups

none

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

At a352312, on main without A, CPU only (torch 2.14 CPU, no aiter or Triton):

ruff check / black --check (26.10.1) on the 6 linted .py files      clean (the 3 protoc modules excluded)
pytest tests/entrypoints tests/test_grpc_proto.py <the files importing llm_engine, engine_core, block_manager, SpeculativeConfig or the API server>
    7314 passed, 1 failed, 380 skipped, 1 collection error
  • The failure, test_server_entrypoints_initialize_native_storage_before_import[openai_server], times out a 30 s subprocess import that takes 19 to 41 s on this host on main too; main's own run failed its other variant.
  • The collection error is tests/plugin/test_sglang_qwen4_exp_mtp.py, which needs SGLang.

The integration branch's end-to-end tests, not part of this stack, ran against this server code on CPU instances with a stub model runner (ATOM's own server, CoreManager, EngineCore, Scheduler and BlockManager): test_grpc_info 16, test_grpc_generate 16, test_grpc_structured_output 4 and test_proto 5 passed, 86 in all.

🤖 Generated with Claude Code

Jasen2201 and others added 2 commits November 21, 2026 13:42
… EngineCore waits for input

A prompt sent as token ids takes the complete blocks it shares with the
stored prompt sharing the most leading tokens and hashes only the rest
(`TokenPrefixChains.block_hashes`). Stored prompts are kept sorted by
their tokens' bytes, so that prompt sorts next to the new one and a lookup
compares two, from the first token. The store is a `ByteLRU` sized by
`ATOM_TOKENIZE_CACHE_MB`; `ATOM_TOKENIZE_CACHE_BLOCK_HASHES=0` turns
reuse off, and the first 4 reuses are checked against a full
`chained_block_hashes`, any difference turning reuse off.
`/debug/cache_stats` serves the counts as `token_prefix_chains`.

With nothing to run and no KV work pending, `EngineCore.busy_loop` waits
up to `IDLE_WAIT_S` (10 ms) on the event the input thread sets after each
item it queues, so a new request no longer waits the GIL switch interval,
about 5 ms, before its first forward.

Two imports stop loading Triton where nothing needs it:
`SpeculativeConfig` imports the rejection sampler only past its
no-forced-acceptance return, and `get_dcp_local_seq_lens` moves into
`atom/distributed/dcp_layout.py`, which `BlockManager` imports
(`dcp_ops` re-exports it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Generate, Abort and structured output

`atom/entrypoints/grpc/atom_grpc.proto` defines `atom.grpc.v1.AtomEngine`,
ATOM's own gRPC service: token ids in, token ids out. It imports
engine_v1 for `SamplingParams` and `TokenIds`, so a Session carries
engine_v1 messages unchanged. `PrepareStructuredOutput` takes a chat's
`StructuredOutput` with the request's sampling, stop ids and
kv_transfer_params, and answers with the engine_v1 `SamplingParams`
fields the HTTP chat route derives from them.

`python -m atom.entrypoints.grpc.generate` writes the committed
`atom_grpc_pb2.py`, `atom_grpc_pb2_grpc.py` and `engine_v1_pb2.py` with
grpcio-tools 1.78.0; ruff and black skip them, and
`tests/test_grpc_proto.py` fails when one differs from what it writes. `pyproject.toml` declares
`grpcio>=1.78.0` and `protobuf>=6.31.1,<7`.

With `--grpc-port`, the API server process that owns the engine also
serves `atom.grpc.v1.AtomEngine` on its own event loop in the
`AtomGrpcServer` thread, started once the engine exists. A port that
cannot be bound fails the launch, and the flag is refused with
`--api-server-count` above 1. `docs/serving_benchmarking_guide.md` lists it.

HealthCheck and GetServerInfo answer from the functions `/health`,
`/kv_transfer_info` and `/server_info` now share; GetModelInfo returns
the model and tokenizer paths, served name, context length, EOS ids, chat
template, default template kwargs and reasoning markers.

Generate runs a token-id request through the same checks, in the same
order, as `/v1/completions`, and answers a refusal with that route's
status and message; n above 1 is refused. A streaming call sends one chunk
per engine step, then a completion. Stop sequences arrive as token ids,
which `preprocess` and `preprocess_fanout` now accept, dropping empty
ones. Each step's outputs reach the gRPC loop through a flush chained after
the HTTP one; a cancelled call and Abort use the HTTP stream teardown.

A Generate request carrying a chat's `StructuredOutput` is admitted with
the structured fields ATOM's HTTP chat sets for the same chat, through the
chat route's own functions, now behind `_configure_chat_structured_output`.
`PrepareStructuredOutput` answers those fields in an engine_v1
`SamplingParams` once every rank has prepared the grammar, or the HTTP
refusal with its status.

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

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Gate checks are published on every PR so required checks do not stay missing
  • ✅ Expensive jobs run only after the PR is approved, or when a matching ci:* label is present
  • ✅ Pre Checkin must pass before approved heavy jobs continue
  • ✅ Without a matching label, expensive jobs also require a relevant path
  • ✅ A matching ci:* label is an explicit request and can open the gate even when paths would otherwise skip it

Path scope:

  • Native ATOM, vLLM, and SGLang use ignore lists: docs/markdown and unrelated plugin or Mesh paths are skipped
  • ATOMesh uses an include list: Mesh code, ATOMesh scripts/workflows/catalogs, OpenAI entrypoints, and Slurm helpers
  • Relevant path alone does not start expensive jobs; approval still opens the automatic path-scoped gate
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, SGLang, and ATOMesh
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests
ci:mesh Run ATOMesh accuracy/benchmark gates for Mesh-related changes

Without a matching ci:* label, heavy jobs are skipped when the path is not relevant or the PR is not approved.
Add labels via the sidebar or gh pr edit 3673 --add-label <label>

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.

🟡 Changes recommended

Unresolved issues include a critical cancellation-related request leak, failures for multi-template models and supported prompt handoffs, and structured-output errors incorrectly reported as successful completion.

4 open issues
2 files not reviewed
  • atom/entrypoints/grpc/atom_grpc_pb2.py: Generated file
  • atom/model_engine/zmq_protocol/engine_v1_pb2.py: Generated file
What changed in this PR

Adds ATOM’s token-based gRPC service alongside HTTP, providing the server contract for later atomesh routing and Session support in the #3657 stack.

Changes:

  • Defines the protocol, generated Python bindings, and reproducible generation checks.
  • Implements Generate, Abort, health/model/server information, and structured-output preparation.
  • Adds --grpc-port, shares HTTP helpers, and accepts pre-tokenized stop sequences.
File Description
tests/​test_grpc_proto.py Checks generated bindings and protocol shapes.
pyproject.toml Adds runtime dependencies and generated-code formatting exclusions.
docs/​serving_benchmarking_guide.md Documents --grpc-port and deployment constraints.
atom/​model_engine/​zmq_protocol/​engine_v1_pb2.py Adds generated engine protocol bindings.
atom/​model_engine/​zmq_protocol/​__init__.py Documents the protocol package and binding generator.
atom/​model_engine/​llm_engine.py Accepts pre-tokenized stop sequences during preprocessing.
atom/​entrypoints/​openai/​api_server.py Shares HTTP helpers and starts the optional gRPC server.
atom/​entrypoints/​grpc/​server.py Implements RPC handling, admission, streaming, and teardown.
atom/​entrypoints/​grpc/​generate.py Regenerates bindings with a pinned compiler version.
atom/​entrypoints/​grpc/​atom_grpc.proto Defines service messages and RPCs, including the future Session interface.
atom/​entrypoints/​grpc/​atom_grpc_pb2.py Adds generated gRPC message bindings.
atom/​entrypoints/​grpc/​atom_grpc_pb2_grpc.py Adds generated client stubs and server interfaces.

Review effort: Balanced

Comment thread atom/entrypoints/grpc/server.py Resolved
Comment thread atom/entrypoints/grpc/server.py Resolved
Comment thread atom/entrypoints/grpc/server.py Resolved
Comment thread atom/entrypoints/grpc/server.py Resolved

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

some changes needed..

ci green.

served_model_name=api.model_name,
max_context_length=config.max_model_len,
eos_token_ids=config.end_token_ids,
chat_template=api.tokenizer.chat_template,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

chat_template can be a dict for multi-template tokenizers, this will raise. need a contract that carries named templates?

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.

Thanks, you're right that a multi-template tokenizer would make GetModelInfo raise. I've kept one template in the contract, and --grpc-port now refuses such a tokenizer at startup: it names the templates and asks for one with --chat-template (20c9edb, startup_refusal). It fails closed until named templates are needed.

Why not carry named templates
  • A named-template field would need a proto change, plus selection in atomesh that matches transformers (tool_use when tools are given, else default).
  • atomesh's tokenizer (llm-tokenizer 1.4.2) reads only a string chat_template from tokenizer_config.json, so atomesh could not render named templates today.
  • None of the models in our shared model store uses named templates.
  • HTTP serving is unaffected, and the proto comment on chat_template now states the rule.
  • test_grpc_port_refuses_a_tokenizer_with_named_chat_templates checks that main exits before the engine starts.

Comment thread atom/entrypoints/grpc/server.py Outdated
try:
params, kv_transfer_params, stops = self._admission(request)
prompt = resolve_prompt_token_ids(
list(request.prompt_token_ids), kv_transfer_params

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

empty repeated field means absent, so the kv_transfer-only prompt is always refused here. pass ids or None?

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.

Thanks, you're right: an absent repeated field reads as [], so resolve_prompt_token_ids saw two different prompts and refused a prompt given only in kv_transfer_params. Fixed in 6cb9d26. Generate now passes list(request.prompt_token_ids) or None (server.py:123). A request with a prompt in neither place is a 400, prompt_token_ids is required (server.py:127). test_a_prompt_only_in_kv_transfer_params_is_admitted and test_a_request_without_a_prompt_is_a_400 in the new tests/test_grpc_server.py cover both cases.

Comment thread atom/entrypoints/grpc/server.py Outdated
ids, cached = [], 0
while not finished:
output = await outputs.get()
finished = output.finished

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

structured_output_error is reported as a complete request, http raises 500 for the same. call raise_for_structured_error?

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.

Agreed, thanks. Fixed in 6cb9d26: the loop calls raise_for_structured_error(output.finish_reason) before writing that step (server.py:160). A grammar failure now ends the call with a 500 GenerateError carrying HTTP's message. #3674's Session now sends it as a Rejected INTERNAL, which atomesh answers with a 500 (8c9babc).

Details

This applies to streaming and non-streaming calls. The seq has already finished, so the teardown does not abort it. test_a_structured_output_error_ends_the_call_with_a_500 covers it.

Comment thread atom/entrypoints/grpc/server.py Outdated
request, params, kv_transfer_params, stops
)
params = replace(params, **fields)
seq = await asyncio.get_running_loop().run_in_executor(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cancel during preprocess leaks the seq in io_processor.requests, prompt kept forever. shield the future and abort the seq?

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.

Thanks, confirmed and fixed in 6cb9d26 as you suggest. Generate awaits the preprocess future through asyncio.shield. On cancellation, a done-callback pops the seq once preprocess returns (server.py:148-150, _drop_preprocessed :335). The #3674 Session submit had the same leak and is fixed the same way (8c9babc).

Details

The callback is added once, in the except that re-raises, so a repeated cancellation has nothing more to clean up. The seq was never submitted, so the engine has nothing to abort. test_a_call_cancelled_during_preprocess_leaves_no_seq holds preprocess, cancels the call, releases preprocess and checks that io_processor.requests ends empty. It fails without the fix.

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.

Follow-up: Copilot found the explicit-Abort side of this. An Abort sent while Generate is still preprocessing now keeps the request from being submitted (207f47a, in the Abort thread above). The cancellation fix here is unchanged.

temperature=temperature,
max_tokens=max_tokens,
max_tokens_is_default=sampling.max_tokens_is_default or not given,
stop_strings=None, # they arrive as ids, which preprocess takes

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

logprobs, json_schema, stop_strings etc are dropped silently, client gets an unconstrained run. reject non-default values?

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.

Thanks. Logprobs and the structured fields were dropped, and are now refused with a 400 (6cb9d26, _refuse_unserved, server.py:327). Stop strings are not lost: they arrive tokenized in stop_token_sequences, which preprocess takes (server.py:144). The #3674 Session now refuses logprobs too (8c9babc).

Details
  • Refused fields: logprobs_flag, logprobs_count, top_logprobs, json_schema, structured_tool_format, required_channel and structured_reasoning_end (UNSERVED_FIELDS, server.py:62). Generate's answer carries no logprobs. It derives the four structured fields from structured_output. test_generate_refuses_what_it_cannot_serve_with_a_400 covers the refusals.
  • Stops: preprocess encodes stop_strings only when no ids are given (llm_engine.py:892), so stop_strings=None at server.py:230 keeps the ids as the stops. atomesh sends the ids, and the same strings in sampling.stop_strings, which Generate does not read. The proto comment on sampling now says so.

self.steps = StepOutputs()
self.live: dict[str, set[int]] = {} # request_id: its live seq ids, for Abort

async def Generate(self, request, context):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

no request-log entries for this port? log them or say it's http only.

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.

Good catch, thanks. I chose to log rather than document it as HTTP-only (6cb9d26). With --request-log, Generate writes the request, each streamed chunk and its final response through HTTP's _log_request_event, keyed by request_id (_log, server.py:284). test_request_log_records_the_request_and_each_answer covers it.

Comment thread tests/test_grpc_proto.py
from atom.model_engine.zmq_protocol import engine_v1_pb2


def test_committed_modules_are_what_generate_writes():

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

only compares generated bytes, nothing exercises Generate or _admission. add a cpu test with a stub api?

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.

Agreed, thanks. 6cb9d26 adds tests/test_grpc_server.py: Generate driven on CPU through ATOM's real API server module over a fake engine. It covers _admission's defaults and refusals, and one test per fix in this review. 9 of its 14 tests fail on the parent commit. #3674 adds three Session tests there.

What the tests cover
  • streaming and non-streaming answers
  • _admission: the default max_tokens, stop ids, and refusing n above 1 and max_tokens 0
  • the unserved sampling fields
  • a prompt given only in kv_transfer_params, and a request with no prompt
  • the 500 on a grammar failure
  • cancellation during preprocess and mid-stream
  • the request log

The fake engine's preprocess registers seqs as io_processor does. Its add_request replays per-step outputs through the servicer's flush.

…s, cancel during preprocess, request log

- A prompt given only in kv_transfer_params is admitted: the empty repeated
  prompt_token_ids is read as absent, and a request with neither is a 400.
- A structured_output_error finish ends the call with a 500 GenerateError, as
  HTTP chat raises it (raise_for_structured_error).
- A call cancelled while preprocess runs drops the seq the executor registers
  in io_processor.requests once it is made.
- Generate refuses, with a 400, the SamplingParams fields it does not serve:
  logprobs, top_logprobs, and the structured-output fields it derives from
  structured_output. The proto says its stop_strings are not read: the stops
  are stop_token_sequences.
- --request-log records each Generate request and each message it writes.
- tests/test_grpc_server.py drives Generate over ATOM's API server module and
  a fake engine on CPU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 13:35
Jasen2201 added a commit that referenced this pull request Nov 22, 2026
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.

🟡 Changes recommended

Abort can acknowledge cancellation while Generate is still preprocessing, yet the request can subsequently start inference because it is not registered until preprocessing finishes.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Add RPC tests for structured output and admission

atom/​entrypoints/​grpc/​server.py:244

[verified] The committed server tests never supply structured_output or call PrepareStructuredOutput, leaving the new chat reconstruction and admission behavior untested despite HTTP coverage in tests/entrypoints/test_structured_output.py. Add CPU tests for both RPCs covering response schemas, message-declared tools, reasoning kwargs, and stop/ignore_eos refusals, asserting the derived fields and HTTP-equivalent statuses.

Medium severity Preserve top_logprobs validation in structured output

atom/​entrypoints/​grpc/​server.py:261

[verified] PrepareStructuredOutput accepts sampling.top_logprobs=2 with logprobs unset, whereas HTTP chat rejects it with 400. The constructed chat has the default top_logprobs, and this replacement also leaves the count at zero, bypassing both chat validation and SamplingParams' count checks. Copy top_logprobs into chat_params so invalid combinations are refused rather than reporting successful preparation.

3 resolved since last review
2 files not reviewed
  • atom/entrypoints/grpc/atom_grpc_pb2.py: Generated file
  • atom/model_engine/zmq_protocol/engine_v1_pb2.py: Generated file

Review effort: Balanced

Comment thread atom/entrypoints/grpc/server.py Resolved
Jasen2201 added a commit that referenced this pull request Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jasen2201 added a commit that referenced this pull request Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jasen2201 added a commit that referenced this pull request Nov 22, 2026
…t and render

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jasen2201 added a commit that referenced this pull request Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jasen2201 added a commit that referenced this pull request Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

some changes needed..

ci green.

Comment thread atom/entrypoints/grpc/server.py Outdated
except asyncio.CancelledError: # the seq it registers is dropped once made
preprocessing.add_done_callback(partial(_drop_preprocessed, api))
raise
self.live.setdefault(request.request_id, set()).add(seq.id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

seq id only reaches self.live after preprocess, so abort during _structured/preprocess is acked but the seq still submits and runs to max_tokens. register by request_id at rpc entry and drop it after preprocess if aborted?

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.

Thanks, fixed in 207f47a, pushed just after this review. Generate registers its call under the request_id on entry (_Call), before _structured and preprocess, so Abort marks it at any point. A call aborted before submission ends with finish_reason="aborted" and its seq never reaches the engine. One aborted during submission is aborted once submitted. test_abort_during_preprocess_keeps_the_request_out_of_the_engine and test_abort_during_submission_aborts_the_request_once_submitted cover both.

served_model_name=api.model_name,
max_context_length=config.max_model_len,
eos_token_ids=config.end_token_ids,
chat_template=api.tokenizer.chat_template,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

chat_template can be a dict or None, assigning to the string field raises TypeError. guard with isinstance(template, str) and leave it unset otherwise?

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.

Thanks. A dict can't reach this line: since 20c9edb, --grpc-port refuses a tokenizer with named templates at startup (startup_refusal). None already leaves the field unset. chat_template is optional string, and protobuf reads None in a constructor as unset, in both the upb and pure-Python backends. c991bec adds test_model_info_leaves_an_absent_chat_template_unset to pin that.

Generate registers its call on entry, not once preprocess has made its seq.
Abort marks the call; an Abort before submission keeps the request out of the
engine and ends the call with finish_reason "aborted", and one during a
structured submission aborts the seq once the submission settles.

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

Copy link
Copy Markdown
Collaborator Author

Round 3 pushed: c7190fd answers Copilot's overview point that gRPC token timings could reflect queue delays or stalled writes rather than engine delivery.

Generate now stamps each output in the engine's stream callback, as generate_async does, so a slow client's writes no longer inflate ttft_s and tpot_s. test_token_times_are_taken_as_the_engine_delivers_them fails without it.

ATOM's HTTP chat places streamed usage by the model's API contract:
DeepSeek-V4.1's encoder (encoding_dsv41) puts it on the finish chunk,
with "usage": null on the chunks before it under include_usage, and
every other model ends the stream with a usage-only chunk. A router
rendering ATOM's chats over gRPC could not tell which. GetModelInfo
gains usage_on_finish (field 11), from the same api_compatibility_for
the HTTP routes call.

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 HTTP and gRPC disagree on the initial reasoning state for implicit-start templates, causing reasoning to appear as answer content and requiring consideration of per-request thinking toggles.

1 open issue
2 files not reviewed
  • atom/entrypoints/grpc/atom_grpc_pb2.py: Generated file
  • atom/model_engine/zmq_protocol/engine_v1_pb2.py: Generated file

Review effort: Balanced

…ener

ATOM's HTTP chat reads a reply as starting inside the reasoning channel
when the prompt ends on the dialect's opener, or when the chat template
closes a block it never opens (DeepSeek-R1's) and the render did not
switch reasoning off (api_server.reasoning_channel). A router rendering
ATOM's chats saw only the first. GetModelInfo gains
implicit_reasoning_opener (field 12), the dialect's opener for such a
template, and reasoning_toggle_json (field 13), the kwarg that switches
reasoning with its off and on values.

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

The shared HTTP/gRPC engine architecture warrants maintainer sign-off because fake-engine tests do not validate real-engine concurrent submission, cancellation, shutdown, or P/D lifecycle behavior.

1 open issue
2 files not reviewed
  • atom/entrypoints/grpc/atom_grpc_pb2.py: Generated file
  • atom/model_engine/zmq_protocol/engine_v1_pb2.py: Generated file

Review effort: Balanced

Jasen2201 and others added 2 commits November 23, 2026 16:44
main's yield_gil() follows each idle pass; this branch's idle pass with
no KV work waits for input first, so both run there, and main's idle-GIL
test engine gains the _wait_for_input it now calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…M gRPC server

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.

🟡 Changes recommended

Rejected Generate requests can leak callbacks and output queues indefinitely, and the newly committed bindings lack the required source license headers.

3 open issues
2 files not reviewed
  • atom/entrypoints/grpc/atom_grpc_pb2.py: Generated file
  • atom/model_engine/zmq_protocol/engine_v1_pb2.py: Generated file

Review effort: Balanced

self._forget(request.request_id, call)
for seq in seqs:
if submitted: # the HTTP stream teardown, per sibling
api.cleanup_stream(seq.id, aborted=not siblings[seq.id].finished)

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 230de15: CoreManager validates every rank hint of the batch before it registers any callback, so a Generate refused for its data_parallel_rank leaves none, and an active Abort's terminal callback is untouched. test_a_refused_rank_hint_leaves_no_callback_in_core_manager runs Generate over CoreManager's own registry and kept the callback without the fix. #3674 carries the same change, which the Session's refused submissions needed too.

@Jasen2201

Copy link
Copy Markdown
Collaborator Author

Fixes the review's point that HTTP and gRPC disagreed on the initial reasoning state of implicit-start templates, in 4f59f0e: GetModelInfo now reports implicit_reasoning_opener and reasoning_toggle_json, from which atomesh (#3677, 0247234) starts such a reply in reasoning unless the render switched it off, as api_server.reasoning_channel does.

Jasen2201 and others added 4 commits November 23, 2026 17:44
CLAUDE.md's header for a new source file is three lines: SPDX, then the AMD
and the ATOM Project Contributors copyright notices.

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

CLAUDE.md's header for a new source file is three lines: SPDX, then the AMD
and the ATOM Project Contributors copyright notices. generate.py now writes
that header above protoc's output, so the committed engine_v1_pb2.py,
atom_grpc_pb2.py and atom_grpc_pb2_grpc.py carry it and stay exactly what
generate.py writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_add_prepared_requests registered each seq's stream callback, then
_dispatch_to_dp_ranks refused a data_parallel_rank outside the engines;
no engine got the seq, so no terminal output ever retired its callback,
and each Generate refused for its rank hint kept one and what it holds.
The hints are now validated before any callback is registered, and the
dispatch reuses them. A Generate test over CoreManager's own callback
registry covers it.

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.

🟡 Changes recommended

A partial fan-out send failure leaves undispatched sibling callbacks in CoreManager’s registry, retaining the output queue after generation ends; dispatch-failure rollback must remove them and regression coverage must verify registry cleanup.

3 open issues
1 resolved since last review

Review effort: Balanced

Comment thread atom/model_engine/engine_core_mgr.py Resolved
A send that failed partway left the stream callbacks of the seqs no
engine received in _seq_id_to_callback: no terminal output would ever
reach them, and an abort broadcast cannot retire them either, so each
kept its output queue after the request ended. The DP rollback now drops
the callbacks of every undispatched rank, whatever the load tracking, and
a failed send to the only engine, the PP head or RapidServe's decode
drops the whole batch'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.

🔵 Needs a closer look

Shared engine state across HTTP and gRPC requires human validation of concurrent generation and shutdown against real engine processes beyond the supplied fake-engine tests.

2 open issues
1 resolved since last review

Review effort: Balanced

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.

🟡 Changes recommended

Repeated cancellation during a blocked structured submission can let cleanup finish before the executor submits the sequence, leaving inference running after the call ends.

3 open issues

Review effort: Balanced

outputs.put_nowait((aborted, time.time()))
else:
submitted = True # a failed submission may have dispatched some seqs
await api._submit_engine_requests(seqs)

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 c4da343. Generate's structured submission is now the executor's Future, which asyncio.run's teardown does not cancel, and a repeated cancel keeps waiting for it, so its seqs are aborted only once the executor has enqueued them. Test: test_a_generate_cancelled_twice_aborts_once_its_structured_seq_is_enqueued (fails without the fix: the aborts land before the enqueue).

Generate's structured submission ran add_request in a to_thread Task. A
second cancel, as asyncio.run's teardown sends, ended the wait for it after
the first, so the seqs were aborted before the executor enqueued them, and
the later enqueue ran unaborted. The submission is now the executor's
Future, which asyncio.run does not cancel, and a repeated cancel keeps
waiting for it before the seqs are aborted.

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

Maintainer validation is needed for shared HTTP/gRPC admission, cancellation, and shutdown because fake-engine regressions do not establish correctness at the real-engine P/D teardown boundaries.

3 open issues

Review effort: Balanced

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 review is needed because the new gRPC loop shares CoreManager and the IO processor with HTTP, but fake-engine tests do not establish mixed-protocol thread safety or shutdown behavior under real engine delivery.

3 open issues

Review effort: Balanced

Jasen2201 and others added 2 commits November 26, 2026 14:08
With ATOM_TOKENIZE_CACHE_MB=0, ATOM_TOKENIZE_CACHE_BLOCK_HASHES=0 or after
a failed first-uses check, preprocess still ran TokenPrefixChains.block_hashes,
which copied, rehashed and locked for nothing: 6% over main at 120K tokens.
It now checks `chains.enabled` first and costs what main does. The idle
wait's docstring also names the worker KV outputs that set its event.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…TOM gRPC server

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.

🟢 Approval recommended

There are no active review issues blocking the gRPC server integration.

3 open issues

Review effort: Balanced

Main now carries #3672 as one squash commit, so the engine files take
main's side. api_server.py keeps both: the gRPC server stops before the
engine and the encoder close after it, health_problem() answers None
under --encoder-only, and --encoder-only refuses --grpc-port.

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.

🟡 Changes recommended

gRPC admission skips the shared cache_seed and mrope_position_delta checks, allowing malformed handoff metadata through both Generate and PrepareStructuredOutput before preprocessing.

4 open issues

Review effort: Balanced

kv_transfer_params and its stop ids as given."""
api, sampling = self.api, request.sampling
kv_transfer_params = _kv_transfer_params(request)
api._validate_chunked_receive(kv_transfer_params)

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