core.inference.data_parallel_inference_coordinator.handlers#

Message handlers for the data parallel inference coordinator.

Each handler is a free function decorated with @message_handler, which records it in the module-level HANDLERS registry keyed by message header. The coordinator builds its dispatch table from this registry, so a new message type is supported simply by adding a decorated function here; the coordinator’s event loop never changes.

Handlers have the signature (coordinator, sender_identity, metadata, bodies) -> bool | None.

metadata is the decoded contents of the message’s first frame: a header followed by whatever the coordinator needs in order to route the message. It is small by construction and does not grow with prompt length.

bodies is the list of remaining raw frames, still packed. These carry the prompt (inbound) or the finished request (outbound) – the bulk of the bytes. The coordinator forwards them as opaque frames and only decodes one when it has to mutate it, which keeps its per-request cost flat in prompt length.

Returning a truthy value signals the event loop to stop.

Module Contents#

Functions#

message_handler

Register a function as the handler for one or more message headers.

handle_connect

Handshake with a new client, replying with a CONNECT_ACK.

handle_submit_request

Route a client request to a data parallel rank.

handle_submit_request_with_kv

Route a client-supplied KV handoff to a decode engine.

handle_release_kv

Broadcast release of prefill blocks retained for a completed handoff.

handle_control_signal

Validate a control signal against the transition table and broadcast it.

handle_cuda_profiler_signal

Broadcast a CUDA profiler control signal to every connected DP engine.

handle_engine_reply

Route completed requests from an engine back to their originating clients.

handle_engine_reply_partial

Route incremental engine replies without releasing request routing state.

handle_abort_request

Forward a client cancellation to the engine serving that request.

handle_shutdown

Stop the coordinator event loop on request from a known client.

handle_disconnect

Remove a disconnecting engine from the routing pool.

Data#

API#

core.inference.data_parallel_inference_coordinator.handlers.HANDLERS#

None

core.inference.data_parallel_inference_coordinator.handlers.message_handler(*headers)#

Register a function as the handler for one or more message headers.

A new message type is supported by writing a handler function and decorating it with the header(s) it serves; it is added to HANDLERS, which the coordinator turns into its dispatch table. The event loop never needs to change when a header is added.

core.inference.data_parallel_inference_coordinator.handlers.handle_connect(coordinator, sender_identity, metadata, bodies)#

Handshake with a new client, replying with a CONNECT_ACK.

Sent by InferenceClient.start.

metadata: [header]. bodies: empty.

core.inference.data_parallel_inference_coordinator.handlers.handle_submit_request(coordinator, sender_identity, metadata, bodies)#

Route a client request to a data parallel rank.

Sent by InferenceClient.add_request / add_request_streaming.

metadata: [header, client_request_id, sampling_params, media_meta], where sampling_params is the serialized dict and media_meta is the bounded media descriptor – a content key plus modality and token-expansion flags – carrying the identity the routing policy keys on. Both are small by construction, which is why they are decoded and repacked here on every request. bodies: [prompt, block_hashes, media, offload_params].

``prompt`` is a string or token id list. It is forwarded to the engine
verbatim and never decoded here, which is the point of the split.

``block_hashes`` is decoded here, used to pick a rank, and not forwarded:
the engine computes its own KV hashes. One int per block rather than per
token, which is why it is a body frame and not part of the metadata.
``None`` means the client did not hash and this handler must, paying the
prompt decode; an empty list means it did hash and the prompt was shorter
than one block.

``media`` is the raw image or video bytes, or serialized preprocessed
tensors, and is None for a text-only request. Like the prompt it is
forwarded verbatim and never decoded here: it is the largest thing on the
wire, and decoding it per request would cost this one serial loop far more
than the prompt decode the split already removed.

``offload_params`` is opaque client metadata for the engine's prompt
preparer and payload stager, None when the client sent none. It is
unbounded, so it is forwarded verbatim and never decoded here.

Returns True (stopping the loop) if no engines are reachable.

core.inference.data_parallel_inference_coordinator.handlers.handle_submit_request_with_kv(
coordinator,
sender_identity,
metadata,
bodies,
)#

Route a client-supplied KV handoff to a decode engine.

Sent by InferenceClient.add_request_with_kv_handoff / add_request_with_kv_handoff_streaming.

metadata: [header, client_request_id, sampling_params, kv_meta], where kv_meta is the peer’s NIXL agent/layout export. It is bounded by TP size and num_speculative_tokens, not by prompt length, so it stays in the metadata frame. bodies: [prompt, src_block_ids]. src_block_ids names one remote block per block_size_tokens of prompt, so it grows with the prompt and travels as its own frame. Both bodies are forwarded to the engine untouched, so the coordinator decodes nothing sequence-dependent. In disaggregated serving every decode request arrives here, so this is as hot as a plain submission.

core.inference.data_parallel_inference_coordinator.handlers.handle_release_kv(coordinator, sender_identity, metadata, bodies)#

Broadcast release of prefill blocks retained for a completed handoff.

Sent by InferenceClient.release_handoff. Broadcast to every engine; engines not holding that request id treat it as a no-op.

metadata: [header, client_request_id]. bodies: empty.

core.inference.data_parallel_inference_coordinator.handlers.handle_control_signal(coordinator, sender_identity, metadata, bodies)#

Validate a control signal against the transition table and broadcast it.

Serves PAUSE, UNPAUSE, SUSPEND, RESUME, SET_GENERATION_EPOCH and STOP, all sent by InferenceClient._send_signal_to_engines.

metadata: [header, *args]. Every signal but one carries no args; SET_GENERATION_EPOCH carries [header, generation_epoch]. The whole list is rebroadcast verbatim so data-bearing signals keep their args. bodies: empty.

core.inference.data_parallel_inference_coordinator.handlers.handle_cuda_profiler_signal(
coordinator,
sender_identity,
metadata,
bodies,
)#

Broadcast a CUDA profiler control signal to every connected DP engine.

Serves START_CUDA_PROFILER and STOP_CUDA_PROFILER, sent by InferenceClient._send_signal_to_engines.

Profiler control is not a coordinator state transition, so there are no CoordinatorState checks — the signal is simply forwarded to all engines.

metadata: [header], rebroadcast verbatim. bodies: empty.

core.inference.data_parallel_inference_coordinator.handlers.handle_engine_reply(coordinator, sender_identity, metadata, bodies)#

Route completed requests from an engine back to their originating clients.

Sent by the engine via _engine_reply_frames.

metadata: [header, [[request_id, needs_detokenize], ...]] – one entry per finished request, in the same order as bodies. bodies: one frame per entry, each a packed finished request. A finished request echoes the prompt back, so these are the largest frames the coordinator handles. A body is decoded only when needs_detokenize is set; otherwise it reaches the client as the frame the engine produced.

core.inference.data_parallel_inference_coordinator.handlers.handle_engine_reply_partial(
coordinator,
sender_identity,
metadata,
bodies,
)#

Route incremental engine replies without releasing request routing state.

Sent by the engine for streaming requests at each streaming interval.

metadata: [header, [request_id, ...]] – one id per partial, in the same order as bodies. No detokenize flag: partials are always detokenized incrementally by the client-facing streaming layer. bodies: one frame per id, each a packed partial ({"request_id": int, "new_tokens": [...]}), always forwarded untouched.

core.inference.data_parallel_inference_coordinator.handlers.handle_abort_request(coordinator, sender_identity, metadata, bodies)#

Forward a client cancellation to the engine serving that request.

Sent by InferenceClient.abort_request. Unknown or already-completed request ids are dropped silently.

metadata: [header, client_request_id]. bodies: empty.

core.inference.data_parallel_inference_coordinator.handlers.handle_shutdown(coordinator, sender_identity, metadata, bodies)#

Stop the coordinator event loop on request from a known client.

Sent by InferenceClient.shutdown_engines.

metadata: [header]. bodies: empty.

core.inference.data_parallel_inference_coordinator.handlers.handle_disconnect(coordinator, sender_identity, metadata, bodies)#

Remove a disconnecting engine from the routing pool.

Sent by an engine as it exits – the only handler here whose sender is an engine rather than a client.

metadata: [header]. bodies: empty.