Skip to content

[None][feat] Frontend Proto-over-ZMQ feasibility prototype (Server + tensorrt_llm/engine_client) - #3

Closed
JunyiXu-nv wants to merge 11 commits into
mainfrom
dev-junyix-feat-serve-proto-zmq-frontend
Closed

JunyiXu-nv wants to merge 11 commits into
mainfrom
dev-junyix-feat-serve-proto-zmq-frontend

Conversation

@JunyiXu-nv

@JunyiXu-nv JunyiXu-nv commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Feasibility prototype PR (5 structured commits) demonstrating the target Frontend (Server + top-level tensorrt_llm/engine_client/) ↔ Pure Engine architecture on the trtllm.serve_engine.v1 (+ v1.1 Dynamo additions) Proto contract over ZMQ (Phase 1 transport).

Key Design Decisions

  • Top-level tensorrt_llm/engine_client/ (synced with QiJune): replaces serving-side llmapi + proxy roles so serve/, llmapi/, and grpc/ share one client layer without cyclic or inverted dependencies.
  • Language-neutral, pickle-free ZMQ-Proto wire (contracts/serve_engine/v1/zmq_wire.py): [hmac_sha256_32B, kind_1B, proto_bytes, aux_tensor_0, ...] over two DEALER<->ROUTER channels (SessionService + 13 ControlService RPCs), with large tensors carried as zero-copy ZMQ multipart aux frames (TensorRef). Designed so a future Rust frontend or gRPC engine_host transport can plug in cleanly.
  • Existing startup flow preserved: opt-in via TRTLLM_ENGINE_PROTOCOL=v1_zmq (rank-0 thin bridge) and TRTLLM_ENGINE_ENDPOINT (frontend attachment), leaving the default pickled path untouched.

Commit Breakdown

  1. Commit 1 (773e72a6c4) — Pure Move: Relocate the 9 existing frontend-side modules out of tensorrt_llm/executor/ into top-level tensorrt_llm/engine_client/ with FutureWarning compatibility shims and updated allowlists/CI lists.
  2. Commit 2 (19ceb26551) — Core Proto-over-ZMQ Stack: Land tensorrt_llm/contracts/serve_engine/v1/ (8 .proto + v1.1 P-2/P-3/P-4 + codegen + zmq_wire.py), build engine_client/{interface,capabilities,request_mapper,frame_decoder,transport,transport_zmq,facade}.py, add thin opt-in executor/proto_bridge.py, and wire serve/openai_server.py + commands/serve.py.
  3. Commit 3 (51abf435bd) — Tests: Add real ZMQ MockProtoEngine + CPU unit, Hypothesis property, AST layering/pickle-free, shim identity, multi-frontend Rank0ProtoBridge, and OpenAIServer HTTP ASGI E2E tests (registered in l0_cpu.yml).
  4. Commit 4 (b3a97c9033) — Lift Postproc/Detok/Stop/Metrics Into Frontend: Add engine_client/postproc_pool.py (handle-sharded pool, incremental detok, text stop truncation + explicit CancelBatch(STOP_STRING) fixing H1, post_processor_hook with detokenize=False + CANCEL_REASON_POSTPROC_TERMINATE, best_of > n selection, FinalInfo metrics extraction).
  5. Commit 5 (5ed7b744ae) — Lift Declarative Request Prep, Disagg Handoff & Multimodal: Add engine_client/handoff.py (DG-04/DG-60), signed_handoff_b64 / rendezvous_ticket_b64 + POST /_internal/release_handoffs, sparse logit_bias / declarative thinking_budget engine-side materialization, and MEDIA (v1.1 uuid) + zero-copy PREPROCESSED multimodal support.

Verification

  • All 5 commits pass full pre-commit (ruff, ruff-format, ruff-legacy, isort, yapf, l0_cpu.yml AST, DCO sign-off).
  • CPU verification on HEAD: 149 passed, 0 failed (21 new contracts/ + engine_client/ tests + 128 existing executor/ tests).
  • Real GPU A/B parity verified on computelab-sc-01 (4u4g-0074, NVIDIA H100 NVL 96GB, Slurm job 6474375, Qwen3-0.6B):
    • Path A (legacy pickled PyTorchLLM): tokens=[12095, 13, 576, 6722, 315, 9625, 374, 1083, 279, 6722, 315, 279], text=' Paris. The capital of France is also the capital of the'
    • Path B (ProtoEngineFacade -> ZmqEngineTransport -> Rank0ProtoBridge -> PyExecutor): exact 12/12 token & text match
    • Path B (OpenAIServer HTTP /health, /v1/completions non-streaming & SSE data: [DONE] streaming): exact text match (COMPLETED 0:0).

Additional Verification (Round-2 Review Fixes + 16xGB300 Kimi K3.1 Pro E2E)

  • Adversarial review (gpt-6.2-astra): Completed Round-1 (36 findings) + Round-2 verification; fixed all P1/P2/P3 blockers and added tests/unittest/engine_client/test_astra_review_regressions.py (CPU suite now 155 passed, 0 failed, lazy-import verified with 0 eager _pb2 modules loaded).
  • H100 NVL re-verification (computelab-sc-01, Slurm job 6660467, a1u1g-mil-0689, Qwen3-0.6B): COMPLETED 0:0, exact 12/12 token & HTTP text parity on latest fixes.
  • 16xGB300 Kimi K3.1 Pro (1.5 TB DEP16, 4-node MNNVL5) E2E (nsc-lhr, isolated Slurm job 1004125, nvl72d044-t[07,12,14,18]): COMPLETED 0:0 in 9m00s (zero impact on production gateway/instances):
    • Discovery file permissions verified 0o600; handshake v1.1 (vocab=163840); ControlService verified HEALTH_STATE_SERVING, v1.1 sampled_at_unix_nanos, and GetKvCapacity (29,272 blocks × 64 = 1,873,408 tokens).
    • Baseline trtllm-serve vs ProtoEngineFacade (non-stream + streaming snapshots) vs OpenAIServer HTTP (/v1/completions non-stream + SSE include_usage=true): exact text match (' Paris. It is known for the Eiffel Tower and the Louvre Museum.').
    • 8-request concurrent DEP16 in-flight batch over ZMQ-Proto completed in 14.04s with 8/8 distinct prompts verified.
  • 32xGB300 (1P1D: 16xGB300 CTX + 16xGB300 GEN) Kimi K3.1 Pro Disaggregated NIXL E2E (nsc-lhr, isolated Slurm job 1006127, nvl72d007-t[09,11,17-18] CTX + nvl72d037-t[11-12,15,17] GEN): COMPLETED 0:0 in 8m40s (zero impact on production gateway/instances):
    • Dual-host Proto handshake verified INTEGRITY_SCHEME_HMAC_SHA256 with shared engine-only TRTLLM_DISAGG_HANDOFF_KEY_HEX, GetKvCapacity (ctx_kv_blocks=29,272, gen_kv_blocks=41,270), and 0o600 discovery files.
    • Leg 1 (PHASE_CONTEXT_ONLY on 16xGB300 CTX) emitted opaque SignedHandoff (first_toks=[17374], real NIXL endpoint tcp://7.247.18.211:40323); tampered MAC rejected by GEN with ERROR_CODE_HANDOFF_INVALID.
    • Leg 2 (PHASE_GENERATION_ONLY on 16xGB300 GEN via real cross-rack NIXL KV transfer, streaming steps=3) matched baseline HTTP 1P1D NIXL Disagg byte-for-byte.
    • 4-request concurrent 32xGB300 2-leg NIXL Disagg batch completed in 14.06s (4/4 exact); abandoned handoff ControlService.ReleaseHandoffs verified idempotent (RELEASED -> NOT_FOUND).

…sorrt_llm/engine_client

Move the nine frontend-side client modules out of tensorrt_llm/executor/
into top-level tensorrt_llm/engine_client/ without changing runtime
behavior: executor.py, result.py, proxy.py, rpc_proxy.py,
rpc_proxy_mixin.py, ray/executor.py -> ray_executor.py,
postproc_worker.py, postprocessor_hook.py, and prompt_tail.py.

Engine-used definitions stay under tensorrt_llm/executor/:
- executor/logprobs.py: Logprob types and prompt-logprob helpers
- executor/request.py: PostprocArgs and PostprocParams
- executor/utils.py: PostprocWorkerConfig, ResponseWrapper,
  get_metrics_dict, and _check_collective_rpc_guard

Keep FutureWarning compatibility shims for external callers
(executor/__init__.py, executor/result.py, executor/postprocessor_hook.py,
executor/ray/executor.py, executor/ray_executor.py) and update internal
imports, serialization allowlists, legacy-file lists, CODEOWNERS, and CI
multi-GPU trigger paths.

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
…e, and serve wiring

Add the versioned trtllm.serve_engine.v1 (+ v1.1 Dynamo additions) Proto
contract and implement the Phase 1 ZMQ-Proto frontend client stack:
- tensorrt_llm/contracts/serve_engine/v1/: 8 .proto sources, v1.1 fields
  (P-2 sampled_at_unix_nanos, P-3 image_routing_version, P-4
  KvEventSourceInfo), Python pb2 codegen script, and shared pickle-free
  ZMQ wire framing (zmq_wire.py).
- tensorrt_llm/engine_client/: EngineClientInterface, CapabilityGate,
  RequestMapper, columnar FrameBuilder/decode_frame, pluggable
  EngineTransport + ZmqEngineTransport (DEALER<->ROUTER session/control
  + HMAC + zero-copy aux tensor frames), and ProtoEngineFacade.
- tensorrt_llm/executor/proto_bridge.py: thin opt-in rank-0 ZMQ-Proto
  bridge behind TRTLLM_ENGINE_PROTOCOL=v1_zmq.
- tensorrt_llm/serve/openai_server.py & commands/serve.py: wire
  EngineClientInterface / ProtoEngineFacade opt-in via
  TRTLLM_ENGINE_ENDPOINT while keeping existing startup and pickle paths
  unchanged.

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
…d HTTP E2E tests

Add test coverage for the trtllm.serve_engine.v1 ZMQ-Proto frontend stack:
- tests/test_common/engine_client/mock_proto_engine.py: real ZMQ-speaking
  mock engine implementing SessionService, ControlService (13 RPCs),
  columnar Frame emission, zero-copy aux tensors, disagg SignedHandoff /
  ReleaseHandoffs, and fault injection (ENGINE_DEAD, SubmitAck rejection).
- tests/unittest/contracts/test_serve_engine_proto_sync.py: verifies
  generated _pb2 bindings stay in sync with .proto sources and v1.1 fields.
- tests/unittest/engine_client/test_layering_and_shims.py: enforces
  pickle-free ZMQ wire modules, unidirectional engine_client/proto_bridge
  layering, and compatibility shim identity.
- tests/unittest/engine_client/test_proto_zmq_stack.py: Hypothesis
  columnar Frame property tests, TensorRef inline/aux round-trip, HMAC
  tamper checks, CapabilityGate & RequestMapper checks, live multi-frontend
  ZMQ & Rank0ProtoBridge tests, and OpenAIServer HTTP ASGI E2E tests.
- Register the three cpu_only test modules in l0_cpu.yml and apply small
  proto field fixes surfaced by the new tests.

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
…and metrics into Frontend

Move runtime post-processing and output-side frontend responsibilities out
of tensorrt_llm/executor/ into tensorrt_llm/engine_client/postproc_pool.py
on the trtllm.serve_engine.v1 Proto path:
- FrontendPostprocPool: handle-sharded frontend worker pool (strict
  per-handle ordering, replacing rank-0 PostprocWorker spawning).
- Incremental detokenization, stop_index / text stop-string truncation,
  and explicit CancelBatch(CANCEL_REASON_STOP_STRING) emission when a
  text-level stop string triggers before engine completion.
- post_processor_hook execution even when detokenize=False, emitting
  CancelBatch(CANCEL_REASON_POSTPROC_TERMINATE) on terminate() verdicts.
- Frontend best_of > n selection by cumulative_logprob and FinalInfo
  usage/decoding/spec/timing extraction.
- Add CPU unit and live ZMQ tests in test_frontend_postproc.py and
  register in l0_cpu.yml.

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
…handoff, and multimodal boundaries

Complete the remaining boundary cleanups between Frontend and Engine on
the trtllm.serve_engine.v1 Proto-over-ZMQ path:
- tensorrt_llm/engine_client/handoff.py: implement DG-04/DG-60 opaque
  SignedHandoff / RendezvousTicket base64 helpers, frontend-readable key
  extraction, and HandoffReleaseTracker.
- tensorrt_llm/serve/openai_protocol.py & openai_server.py: add optional
  signed_handoff_b64 and rendezvous_ticket_b64 fields on HTTP
  DisaggregatedParams and expose POST /_internal/release_handoffs
  delegating to ControlService.ReleaseHandoffs.
- tensorrt_llm/engine_client/request_mapper.py: support both MEDIA
  (including v1.1 P-3 image uuid) and PREPROCESSED (zero-copy TensorRef
  over ZMQ aux frames) multimodal inputs alongside sparse logit_bias and
  declarative thinking_budget.
- Add CPU unit and live ZMQ/HTTP tests in test_declarative_disagg_mm.py
  and register in l0_cpu.yml.

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
…e_for_ipc_batched and deserialize LlmResult

Fix two issues discovered during real H100 NVL Qwen3-0.6B GPU A/B parity
testing:
- Intercept Rank0ProtoBridge responses inside BaseWorker.handle_for_ipc_batched
  using namespaced bridge client_ids instead of competing with
  await_response_thread on worker.await_responses(), and clean up
  worker._results on completion.
- Deserialize serialized LlmResult payloads before reading output_token_ids
  and avoid double-calling GenerationRequest.set_id().

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
Replace Chinese comments in the eight trtllm.serve_engine.v1 .proto files
with concise English comments. Verified zero protobuf descriptor changes
via scripts/generate_serve_engine_proto.py --check.

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
…ontend, wire, bridge, and serve

Fix all P1/P2/P3 issues surfaced by the gpt-6.2-astra review of PR #3:
- Frontend correctness & isolation (#1, #3, NVIDIA#7, NVIDIA#10, NVIDIA#11, NVIDIA#14, NVIDIA#15, NVIDIA#31, NVIDIA#33, NVIDIA#35):
  owned per-step stream snapshots, sticky aresult() future, single ordered
  outbound writer with batched aux blob_id rebasing, per-handle postproc
  exception isolation, prefix-safe streaming stop-string buffering preserving
  sibling n>1 choices, beam replace_from logprob alignment, chunked prompt
  logprobs / streaming tensor concatenation, async postproc dispatch, and
  aclose() waiter wakeup.
- Request mapping, capabilities & wire hardening (#2, NVIDIA#5, NVIDIA#6, NVIDIA#8, NVIDIA#12, NVIDIA#17, NVIDIA#18, NVIDIA#20, NVIDIA#28, NVIDIA#29, NVIDIA#30, NVIDIA#32):
  lazy PEP 562 engine_client exports (no eager _pb2 import on default serve),
  sparse tuple logit_bias handling, DisaggScheduleStyle IntEnum mapping,
  sampling/beam cardinality and merged stop+bad token sequences, full
  TokenizerFingerprint and multimodal capability gating, BF16 TensorRef and
  strict CSR bounds validation, exact HTTP error status mapping, strict
  zmq_wire header checks, connection-unique DEALER identity, and late control
  RPC reply discarding.
- Rank0ProtoBridge, worker & serve security/fidelity (#4, NVIDIA#9, NVIDIA#13, NVIDIA#16, NVIDIA#19, NVIDIA#21, NVIDIA#22, NVIDIA#23, NVIDIA#24, NVIDIA#25, NVIDIA#26, NVIDIA#27, NVIDIA#34, NVIDIA#36):
  session handshake/version negotiation and reconnect fencing, duplicate
  handle rejection and transactional rollback on submit failure, bounded HWM
  and max_rows_per_frame splitting, separate engine-only handoff HMAC key,
  camelCase GetKvCapacity, explicit UNSUPPORTED for unimplemented admin RPCs,
  atomic 0600 bridge info file with stop() cleanup, worker.py finally init,
  HTTP DisaggregatedParams envelope round-trip, authenticated
  POST /_internal/release_handoffs, and CLI hook/worker/endpoint wiring.
- Add test_astra_review_regressions.py (registered in l0_cpu.yml) covering
  all fixes and language-independent wire vectors.

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
… gate, hook suppress/final error, multi-choice diffs, stream _done, signed handoff)

Address all critical blockers and regressions caught by gpt-6.2-astra Round-2 review:
- commands/serve.py (NVIDIA#9): import load_post_processor_hook (fixes ImportError on TRTLLM_ENGINE_ENDPOINT).
- executor/worker.py (NVIDIA#18): check TRTLLM_ENGINE_PROTOCOL env var before importing proto_bridge so default pickled worker never touches protobuf bindings.
- engine_client/postproc_pool.py (NVIDIA#11 + suppress regression): restore stream._done when final hook raises so stream.fail() wakes waiters, and sync out._raw_text = out.text after hook execution so suppressed chunks never resurface.
- engine_client/facade.py (#1, NVIDIA#20, NVIDIA#34 + include_usage regression): advance sibling choice diff cursors on every row, add _done property and candidate_metrics on ProtoStreamStep/ProtoGenerationStream, and carry signed_handoff_b64 directly on output.disaggregated_params.
- executor/proto_bridge.py (NVIDIA#15, NVIDIA#24): use O_EXCL + fchmod(0o600) + inode check on bridge info file, and keep routing intact during CancelBatch.all so terminal CANCELLED rows still deliver.

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
…d model vocab_size in verify_tokenizer

Fix issue surfaced on real H100 Qwen3-0.6B parity run:
- TransformersTokenizer inherits PreTrainedTokenizerBase whose outer .vocab_size
  raises NotImplementedError; check inner .tokenizer first and guard NotImplementedError.
- Do not copy padded model.config.vocab_size (e.g., 151936 on Qwen3) into
  TokenizerFingerprint.vocab_size (151643).

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
…edError in verify_tokenizer

Signed-off-by: JunyiXu-nv <219237550+JunyiXu-nv@users.noreply.github.com>
@JunyiXu-nv

Copy link
Copy Markdown
Owner Author

Superseded by #4, which stacks cleanly on NVIDIA/TensorRT-LLM NVIDIA#23145/NVIDIA#23146/NVIDIA#23147 with zero duplicated moves or proto files.

@JunyiXu-nv JunyiXu-nv closed this Dec 2, 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.

1 participant