gRPC Workers

When workers connect via gRPC instead of HTTP, SMG becomes a full OpenAI-compatible server: it handles tokenization, chat templates, reasoning extraction, and tool calling at the gateway level. Workers run raw inference only.

For vLLM, TokenSpeed, or SGLang engines on the same host as the gateway, the ZMQ direct backend is an alternative: it runs the same gateway pipeline over local IPC sockets.


What gRPC Mode Enables

Capability HTTP Mode (worker handles) gRPC Mode (gateway handles)
Chat templates Worker Gateway
Tokenization Worker Gateway (with optional caching)
Cache-aware routing On request text, or token IDs for pre-tokenized requests On the token IDs the gateway produced
Reasoning extraction Worker Gateway
Tool call parsing Worker Gateway, with per-model parser overrides
Constrained tool calls Worker Gateway builds the grammar, worker enforces it
Image and video preprocessing Worker Gateway; vLLM workers can take it over (--mm-processing, see Multimodal Pipeline)
MCP tool execution (Responses API) Not handled by the gateway Gateway

In HTTP mode, SMG is a smart proxy that handles routing and failover only. In gRPC mode, SMG takes over the full request processing pipeline.


Start a gRPC Worker

The vLLM, SGLang, TokenSpeed and MLX gRPC servers come from the smg-grpc-servicer Python package. Install the extra for your engine: pip install "smg-grpc-servicer[vllm]", [sglang] or [mlx]. For TokenSpeed, install TokenSpeed first, then smg-grpc-servicer. SMG's engine container images already include the package. TensorRT-LLM serves gRPC from its own serve command.

python -m vllm.entrypoints.grpc_server \
  --model meta-llama/Llama-3.1-8B-Instruct \
  --host 0.0.0.0 \
  --port 50051

This starts the Rust servicer, the default. Setting SMG_VLLM_SERVICER_IMPL=python in the worker's environment serves the same contract from the deprecated Python servicer instead; see Rust vLLM Servicer.

After the engine loads, the worker holds its gRPC health at NOT_SERVING while a planned warm-up runs over the engine — about a minute by default; SMG_VLLM_SERVICER_WARMUP tunes or disables it (see Planned Warm-Up Before Serving).

python -m sglang.launch_server \
  --model-path meta-llama/Llama-3.1-8B-Instruct \
  --host 0.0.0.0 \
  --port 50051 \
  --grpc-mode

--grpc-mode serves the worker through smg-grpc-servicer, which needs SGLang 0.5.21 or later.

This starts the Rust servicer, the default. Adding --servicer-impl python — or setting SMG_SGLANG_SERVICER_IMPL=python in the worker's environment — serves the same contract from the deprecated Python servicer instead; see Rust SGLang Servicer.

On the Python servicer, SGLang also serves an HTTP sidecar (admin and profiling endpoints, plus /metrics with --enable-metrics). The Rust servicer does not start the sidecar — its admin and profiling endpoints stay off — but under --enable-metrics it still serves SGLang's scheduler metrics at the sidecar's address.

After the engine loads, the worker holds its gRPC health at NOT_SERVING while a planned warm-up runs over the engine — about a minute by default; SMG_SGLANG_SERVICER_WARMUP tunes or disables it (see Planned Warm-Up Before Serving).

# Enable XGrammar guided decoding for forced tool calls and response_format
echo "guided_decoding_backend: xgrammar" > trtllm-config.yaml

python -m tensorrt_llm.commands.serve serve
meta-llama/Llama-3.1-8B-Instruct
--grpc
--host 0.0.0.0
--port 50051
--backend pytorch
--extra_llm_api_options trtllm-config.yaml

python -m smg_grpc_servicer.tokenspeed 
--model meta-llama/Llama-3.1-8B-Instruct
--host 0.0.0.0
--port 50051
--grammar-backend xgrammar

TokenSpeed's grammar backend defaults to none, so without --grammar-backend xgrammar it doesn't enforce forced tool calls or response_format. Add --enable-output-logprobs if clients request logprobs; TokenSpeed leaves output logprobs off by default.

This starts the Rust servicer, the default. Adding --servicer-impl python — or setting SMG_TOKENSPEED_SERVICER_IMPL=python in the worker's environment — serves the same contract from the deprecated Python servicer instead; see Rust TokenSpeed Servicer.

After the engine loads, the worker holds its gRPC health at NOT_SERVING while a planned warm-up runs over the engine. A one-process engine takes about a minute, as on the other engines; an engine of more than one process takes ten minutes or more, since the pass then also warms every prompt length up to the chunk size. SMG_TOKENSPEED_SERVICER_WARMUP tunes or disables it (see Planned Warm-Up Before Serving).

python -m smg_grpc_servicer.mlx.server \
  --model mlx-community/Qwen3-0.6B-4bit \
  --host 0.0.0.0 \
  --port 50051

MLX workers are gRPC-only and run on Apple Silicon. They don't support constrained decoding: chat requests with a forced tool_choice or a response_format get a 400, as do requests with n greater than 1 or string stop sequences.

Planned Warm-Up Before Serving

vLLM, SGLang and TokenSpeed gRPC workers run a planned warm-up over the engine before they report SERVING on the standard gRPC health service (grpc.health.v1) — the signal Kubernetes gRPC startup and readiness probes read. Both the Python and Rust servicer implementations run the pass; MLX and TensorRT-LLM workers have no such pass, and a model that generates nothing (a pooling or embedding model) takes none.

TokenSpeed workers skip the pass on a disaggregation role. An encoder-only SGLang worker skips it too: the engine runs that role on its own encoder server, never on a servicer. A language-only SGLang worker runs the pass as on a single engine — its text requests carry no media, so the encoders see nothing of them — and on the Rust path the plan also ends with one image through the encoders (the media leg below).

On an SGLang prefill or decode leg the Python servicer skips the pass; the Rust path runs it, every request carrying a stand-in transfer to nobody, so the leg warms up without its peer. A decode leg runs the whole pass, as on a single engine. A prefill leg's decode steps run on its peer, so its plan is one request of the smallest shape per rank, plus the media leg when the worker has one: the first forward and the transfer path are paid before SERVING, and each prompt-length class is paid by its first request during serving.

A worker whose health stays NOT_SERVING for a while after the engine loaded is warming up, not stuck. The pass logs Planned warm-up starts (...): readiness is held until it ran, one INFO line per shape with its time (TokenSpeed's chunk remainders log at DEBUG, with an INFO progress line every 500 remainders), and Planned warm-up over: N of M steps covered ... at the end.

Engines select and compile kernels lazily: the first scheduler step at a token count the engine has not seen pays a kernel search or a compile of up to several seconds, and every request in flight during that step waits with it. The warm-up visits those token counts before the worker reports SERVING; without it, the first traffic ramp pays them — on every worker of a fleet at once when the workers start together. The pass covers, in order:

  • a decode staircase: as many concurrent requests as the running window holds, each asking for one more output token than the last, so every running-batch size runs once;
  • a prefill ladder: one request per 128-token prompt-length class up to the engine's admission step (its chunk size or prefill token budget), plus the kernel tuners' bucket grid, the engine's graph-capture sizes, and lengths one above each bucket;
  • a second pass over the bucket grid, whose logged timings show what the first pass paid;
  • on a language-only SGLang worker on the Rust path, the media leg: one request carrying one image through the encoders — the engine's own minimal warm-up image, sent as a data URL with the prompt the model's chat template renders around it — because no text request reaches the scheduler's media path, whose first use costs a fresh worker a few seconds. A chat template that renders no image placeholder leaves the leg out (a logged line says why), and the leg runs at the fast level too;
  • on a TokenSpeed engine of more than one process, the chunk remainders: every remaining prompt length up to the chunk size, because on this engine a prompt length's first use during serving can deadlock the forward pass under a collective still in flight. A one-process engine has no peer to wait on and keeps to the length classes, like the other engines. The remainders run last, in an order whose every prefix spreads evenly over the range, so a budget cut leaves even coverage rather than a missing tail. SMG_TOKENSPEED_SERVICER_WARMUP_REMAINDERS overrides whether they are planned (see below).

Every request carries its own token IDs, so prefix caching never hides a prefill, and the pass flushes the engine's prefix cache at the end. A servicer that cannot carry that flush to its engine (the Rust TokenSpeed servicer, on a TokenSpeed whose handshake declares no control reply) refuses it, and the end line then says the warm-up's blocks stay cached.

The gateway's health checks read a different signal: each engine's own HealthCheck RPC, not the standard health service. While the pass runs, a Rust servicer mirrors the hold there — not healthy, with the message Warming up, distinct from Draining — and admits only the warm-up's own requests, refusing anything else with gRPC UNAVAILABLE ("servicer is warming up"), so the gateway neither finishes registering a warming worker nor routes traffic to it.

A Python servicer answers that RPC healthy throughout (vLLM answers from engine liveness; SGLang and TokenSpeed serve the check's one-token probe like any other request) and refuses nothing, so it registers and passes the gateway's health checks while it warms: a request routed to it in that window is served, sharing the engine with the warm-up. On both implementations the hold is released when the pass ends, whatever its outcome — health flips to SERVING, and a failed warm-up request is a logged line, never a worker kept out of rotation.

SMG_VLLM_SERVICER_WARMUP, SMG_SGLANG_SERVICER_WARMUP and SMG_TOKENSPEED_SERVICER_WARMUP tune the pass per engine:

Value Effect
full The default: the whole pass above, every 128-token length class included — about a minute at a 16,384-token step. On a multi-process TokenSpeed engine, also the chunk remainders — about 12 minutes for the whole pass, measured at a 4,096-token chunk size on a four-GPU node
fast Skips the 128-token length classes and keeps the rest of the pass (the staircase, the bucket grid with its one-above lengths and second pass, the capture sizes), finishing in seconds. On a multi-process TokenSpeed engine it also skips the chunk remainders and leaves their first-use hazard open, which the start log warns about
off No planned warm-up: the worker reports SERVING once the engine is up and answering
A number (120) The pass's time budget in seconds, at the full level
<level>:<seconds> (fast:30) Level and budget together

The budget defaults to 300 seconds — 900 for TokenSpeed, whose plan can include the chunk remainders. When it runs out, the pass ends between shapes (the end line names the shape it stopped before), and each request's timeout is clamped to what is left of the budget (never below one second), so a shape that hangs cannot hold readiness past it. A multi-process TokenSpeed worker with no chunk size set plans about 23 minutes of remainders at its default 8,192-token step, and the budget then cuts the pass about halfway through them (evenly, thanks to the spread order): set a chunk size or a larger budget to cover every length.

A value the knob does not take fails a Rust-path worker at startup with an error naming the variable; a Python servicer logs a warning and serves without the warm-up.

Whether the full level plans TokenSpeed's chunk remainders has its own knob, SMG_TOKENSPEED_SERVICER_WARMUP_REMAINDERS. auto, the default, keeps the rule above: the remainders are planned on an engine of more than one process — or one whose layout the server arguments do not state — and not on a one-process engine. on plans them whatever the layout, so even a one-process engine's start pays for the remainders — ten minutes or more instead of about a minute. off never plans them, for an engine that loads those kernels itself before it reports ready; on an engine of more than one process (or of an unknown layout) the start log then warns that the first-use hazard stays open. That the engine captures prefill graphs is no reason to set off: the library GEMMs that the remainders warm run eagerly, outside those graphs, at each forward's real token count.

on and off take the usual boolean spellings (1, true, yes; 0, false, no, none). Unlike the warm-up knob above, a value this knob does not take fails startup on the Python servicer as on the Rust path — one error naming the variable and exit code 2, before the engine launches — whatever the warm-up level, and on a disaggregation role too, though that role plans no warm-up.

Under data parallelism, a vLLM worker — and, on the Rust path, an SGLang worker — runs the staircase once per rank and every prefill shape on every rank at once, each request pinned to its rank, so the log's step count is per rank. The Python SGLang servicer sends no rank pin (the engine's own load balancing places each request), and a TokenSpeed worker routes each warm-up request to the least-loaded rank on both paths; either way each prefill shape warms one rank, the other ranks pay its first-time cost on their first request of that shape, and a logged warning says so.

Rust vLLM Servicer

vLLM gRPC workers serve the gRPC contract from a Rust implementation by default; the deprecated Python implementation serves the same contract and runs only when selected explicitly. The switch lives in the smg-grpc-servicer package and needs no vLLM change: vLLM's gRPC launcher imports the package's servicer classes before it defines serve_grpc, and that import installs the switch over serve_grpc.

The selection requires SMG v1.12.0 or newer wheels and engine images.

Select an implementation explicitly with --servicer-impl on vllm serve --grpc — a flag the package adds to vLLM's parser as a vllm.general_plugins plugin — or with the SMG_VLLM_SERVICER_IMPL environment variable. rust names the default; selecting python runs the deprecated Python servicer, and the launcher logs a deprecation warning:

vllm serve meta-llama/Llama-3.1-8B-Instruct \
  --grpc \
  --host 0.0.0.0 \
  --port 50051 \
  --servicer-impl python

# The environment variable selects it for python -m vllm.entrypoints.grpc_server too:
SMG_VLLM_SERVICER_IMPL=python python -m vllm.entrypoints.grpc_server \
  --model meta-llama/Llama-3.1-8B-Instruct \
  --host 0.0.0.0 \
  --port 50051

When both are set, the flag wins: the parsed --servicer-impl is read ahead of the environment, and the decision is written back to SMG_VLLM_SERVICER_IMPL so the worker's own guard agrees with it. A VLLM_PLUGINS setting that leaves out the smg-servicer plugin only removes the flag; the environment variable works regardless.

In Rust mode, the servicer starts vLLM's engine core processes from its own process — the same cores vllm serve --headless would start, built from the launcher's parsed arguments — and talks to them over a same-host ZMQ connection; Python keeps only the process lifecycle. That ZMQ hop is inside the worker — the gateway still connects over grpc://, so this is not the ZMQ direct backend. The gateway cannot tell the two implementations apart.

Two launches run vLLM's headless launcher in a spawned child process instead of starting the cores from the servicer: the worker ranks of a multi-node engine, and the ray data-parallel backend. Otherwise the servicer sets vLLM's VLLM_WORKER_MULTIPROC_METHOD to spawn unless the environment already sets it, so the cores are spawned rather than forked; an explicit other value is kept, with a logged warning. One core's exit ends the engine: the servicer shuts the remaining cores down and the worker exits with code 1.

With smg serve, an unset --servicer-impl leaves the choice to the workers: an SMG_VLLM_SERVICER_IMPL exported in your shell reaches them unchanged, and without one they run the servicer package's own default, the Rust servicer. An explicit --servicer-impl value — rust, or the deprecated python — is valid only with --backend vllm --connection-mode grpc (any other backend or connection mode is rejected at startup) and is authoritative: it is set as SMG_VLLM_SERVICER_IMPL in each worker's environment, overriding an inherited value. A worker on another connection mode (http or zmq) gets no servicer variable: smg serve removes it from that worker's environment.

smg serve \
  --backend vllm \
  --connection-mode grpc \
  --model meta-llama/Llama-3.1-8B-Instruct \
  --data-parallel-size 2

For the Rust servicer to run, the worker's environment needs:

  • the smg wheel, which carries the Rust servicer binding (smg.servicer.VllmGrpcServer)
  • smg-grpc-servicer[vllm], which carries the switch and the Rust request path
  • a vLLM whose gRPC launcher imports the package's servicer classes at module level — the stock shape, so an unmodified vLLM qualifies — or carries the check (smg_grpc_servicer.vllm.resolve_servicer_impl) in its own serve_grpc

Misconfiguration fails loudly instead of silently serving Python. smg serve refuses to start when the installed vLLM's launcher would not be switched; the check runs whenever the Rust servicer is the effective choice — the default, an explicit --servicer-impl rust, or an inherited SMG_VLLM_SERVICER_IMPL=rust — and only a python chosen by the flag or the variable skips it. An explicit or inherited rust also fails startup when smg-grpc-servicer is not importable; on the default, a missing package is left to the worker, whose gRPC entrypoint needs the package for either servicer and says so itself. On a worker where the switch never ran (a launcher file executed directly as __main__, or one that didn't import the package's servicer before defining serve_grpc), the Python servicer itself refuses to start unless python was selected explicitly.

Because the servicer's ZMQ connection to the engine cores bypasses vLLM's own frontend, the Rust servicer applies the frontend's token-ID bounds itself, reading the vocabulary off the engine's model configuration and tokenizer. An out-of-vocabulary token ID is an index past the engine's embedding table or logits tensor — one that reached the engine would fault the GPU and take the engine down — so a request carrying one is refused with gRPC INVALID_ARGUMENT, a 400 through the gateway, before it reaches the engine:

  • Refused: prompt token IDs outside the model's vocabulary (on embedding requests too), and stop_token_ids entries or logit_bias keys outside it. The error message names the offending IDs — for a prompt, the largest one.
  • Dropped instead of refused: out-of-vocabulary IDs the caller never sent. EOS IDs from the model's configuration or tokenizer, and the stop IDs the servicer derives from single-token string stop entries, are dropped when they lie past the vocabulary: the model can never sample them, and a string stop is still matched on the decoded text.
  • Media positions: a prompt position an attached media item fills may hold any ID up to the tokenizer's largest, added tokens included, even past the model's vocabulary — some multimodal models' placeholder token lies there, and the position takes the item's embedding instead of an embedding-table row. Asking for prompt_logprobs removes the allowance: it scores every prompt ID after the first against the model's logits, so such a placeholder is then refused.
  • PD decode leg: in PD disaggregation, a single-sample (n of 1) request claiming do_remote_prefill: true, on a worker whose KV connector pulls the prompt's KV on that claim (NIXL, Mooncake or MoRIIO as kv_consumer or kv_both), has its prompt held to that same tokenizer bound: it carries the prefill side's expanded prompt, and the pulled KV supplies those positions. Only the trailing tokens the engine still computes itself (at least the last; more under a speculative drafter's prefill lookahead) keep the model's bound. On any other connector configuration the claim changes nothing, and prompt_logprobs restores the ordinary bounds here too.

SubscribeKvEvents relays vLLM's ZMQ KV-event publisher, which the servicer turns on by itself — on this path as on the Python one — when the launcher is given no --kv-events-config, at a port found free on the host rather than vLLM's fixed default, so two engines on one host do not collide. An explicit --kv-events-config is kept exactly as given, whether it names an endpoint or turns publishing off; without one, SMG_VLLM_SERVICER_KV_EVENTS=0 in the worker's environment leaves the publisher off. With the publisher off, SubscribeKvEvents answers UNIMPLEMENTED. See KV Events Cache-Aware Routing.

Rust SGLang Servicer

SGLang gRPC workers make the same choice: the Rust servicer is the default, and the deprecated Python servicer serves the same gRPC contract when selected explicitly.

Like the vLLM switch, the selection requires SMG v1.12.0 or newer wheels and engine images.

Select an implementation explicitly with --servicer-impl on python -m sglang.launch_server — a flag the smg-grpc-servicer package adds to SGLang's parser as an sglang.srt.plugins plugin — or with the SMG_SGLANG_SERVICER_IMPL environment variable. rust names the default; selecting python runs the deprecated Python servicer, and the launcher logs a deprecation warning:

python -m sglang.launch_server \
  --model-path meta-llama/Llama-3.1-8B-Instruct \
  --host 0.0.0.0 \
  --port 50051 \
  --grpc-mode \
  --servicer-impl python

# The environment variable selects it on the same entrypoint:
SMG_SGLANG_SERVICER_IMPL=python python -m sglang.launch_server \
  --model-path meta-llama/Llama-3.1-8B-Instruct \
  --host 0.0.0.0 \
  --port 50051 \
  --grpc-mode

When both are set, the flag wins: --servicer-impl python overrides an exported rust. The decision a flag makes is written back to SMG_SGLANG_SERVICER_IMPL, so the processes the worker spawns inherit the same choice. The selection defaults to rust, and a value other than python or rust fails startup. At startup the worker logs which implementation it chose and whether the flag, the environment or the default decided it.

python -m sglang.launch_server --help lists the flag. SGLang's sglang serve wrapper prints its help before plugins load, so the flag is missing from that listing but still accepted. A SGLANG_PLUGINS setting that leaves out the smg-servicer plugin only removes the flag; the environment variable works regardless.

smg serve's --servicer-impl stays scoped to vLLM: it rejects an explicit value for every other backend. An SMG_SGLANG_SERVICER_IMPL exported before smg serve --backend sglang --connection-mode grpc reaches its workers too, since worker environments inherit the shell's, and no smg serve flag overrides an inherited value the way --servicer-impl does for vLLM.

In Rust mode, the entrypoint hands the process to the Rust servicer (smg.servicer.SglangGrpcServer, which needs the smg wheel installed alongside smg-grpc-servicer[sglang]) before any Python gRPC machinery exists: the Rust server speaks the gRPC contract on the worker's host and port, the scheduler runs headless in a spawned child over a same-host msgpack ZMQ connection, and Python keeps only the process lifecycle. As with vLLM, that ZMQ hop is inside the worker — the gateway still connects over grpc://, so this is not the ZMQ direct backend, and the gateway cannot tell the two implementations apart.

What the scheduler's msgpack wire does not carry, the Rust path reports rather than emulates:

  • An encoder-only worker refuses to start on the Rust path (SGLang runs that role on its own encoder server, not on a servicer), as does a language-only worker on the zmq_to_tokenizer encoder transfer backend (the frontend itself receives and processes the embeddings there, which neither servicer runs). A language-only worker on the backends whose scheduler ranks receive the embeddings is served as on the Python servicer.
  • A prefill leg of several plain data-parallel replicas — --dp-size N without attention DP — is served when it follows the bootstrap room, the engine's default placement on a prefill side (--load-balance-method auto or follow_bootstrap_room): each request tells the engine's KV sender which replica it runs on, and the decode leg derives that replica from the room. SGLANG_DISAGGREGATION_FORCE_QUERY_PREFILL_DP_RANK must stay off on both legs; the prefill worker reads its own value at launch in place of the decode side's, which it cannot see. Under any other load-balance method, or with that variable on, the prefill worker refuses to start: run attention DP (--tp-size N --attn-dp-size N) or one rank per leg instead. Any other prefill or decode leg is served as on the Python servicer.
  • A multimodal payload of image, video or audio references without preprocessed tensors — the encoders' input in encode/prefill disaggregation — is refused per request on every worker but a language-only one, whose encode dispatch hands the references to the encoders. Which modalities the encoders take depends on the receiver mode the worker was started in (SGLANG_ENCODER_MM_RECEIVER_MODE, http by default): http encoders take every modality the encoder runtime runs (image, video and audio), while the grpc encoder service takes images only. Under grpc, a request naming video or audio references is refused before any dispatch. A receiver mode other than http or grpc fails the language-only worker's startup. The tensors the gateway preprocesses in gRPC mode reach the scheduler as its own processor's output on every worker, whatever the receiver mode. LoRA loading answers UNIMPLEMENTED (the Python servicer does not serve it either).
  • SGLang's HTTP sidecar is not started: its admin and profiling endpoints stay off. SGLang's scheduler metrics are still served under --enable-metrics (see below).

Embed, FlushCache and profiling answer as on the Python servicer.

Under --enable-metrics, the scheduler ranks record SGLang's scheduler series — running and queued requests, KV cache usage, generation throughput, queue time, cache hit rate — and the worker serves them where the sidecar would: GET /metrics on --host, at --smg-http-sidecar-port when set and --port + 1 otherwise. The series carry SGLang's own metric names, so a scrape set up for the sidecar keeps the scheduler's series. The sidecar's frontend series (requests, aborts, time to first token, inter-token latency) are not recorded on this path; their counterparts are the Rust servicer's own smg_servicer_* families, served on --metrics-port when one is given (see the Servicer Metrics Reference). When the scheduler-metrics listener cannot start — its port taken, for example — the worker logs a warning and serves on without it.

SubscribeKvEvents relays SGLang's ZMQ KV-event publisher, which the servicer turns on by itself — on this path as on the Python one — when the launcher is given no --kv-events-config, at a port found free on the host rather than SGLang's fixed default. An explicit configuration is kept exactly as given, whether it names an endpoint or turns publishing off; without one, SMG_SGLANG_SERVICER_KV_EVENTS=0 leaves the publisher off. With the publisher off, SubscribeKvEvents answers UNIMPLEMENTED.

Rust TokenSpeed Servicer

TokenSpeed gRPC workers make the same choice: the Rust servicer is the default, and the deprecated Python servicer serves the same gRPC contract when selected explicitly.

Like the vLLM and SGLang switches, the selection requires SMG v1.12.0 or newer wheels and engine images.

Select an implementation explicitly with --servicer-impl on python -m smg_grpc_servicer.tokenspeed — this launcher's own flag, which --help lists ahead of TokenSpeed's ServerArgs flags — or with the SMG_TOKENSPEED_SERVICER_IMPL environment variable. rust names the default; selecting python runs the deprecated Python servicer, and the launcher logs a deprecation warning:

python -m smg_grpc_servicer.tokenspeed \
  --model meta-llama/Llama-3.1-8B-Instruct \
  --host 0.0.0.0 \
  --port 50051 \
  --servicer-impl python

# The environment variable selects it on the same entrypoint:
SMG_TOKENSPEED_SERVICER_IMPL=python python -m smg_grpc_servicer.tokenspeed \
  --model meta-llama/Llama-3.1-8B-Instruct \
  --host 0.0.0.0 \
  --port 50051

When both are set, the flag wins: --servicer-impl python overrides an exported rust. The decision a flag makes is written back to SMG_TOKENSPEED_SERVICER_IMPL, so the processes the worker spawns inherit the same choice. The selection defaults to rust, and a value other than python or rust fails startup. At startup the worker logs which implementation it chose and whether the flag, the environment or the default decided it.

This launcher is also the process ts serve spawns for its gRPC worker. smg serve offers no path here: its --servicer-impl stays scoped to vLLM, and it drives TokenSpeed workers over --connection-mode zmq only — start the worker directly and connect it with smg launch.

In Rust mode, the entrypoint hands the process to the Rust servicer (smg.servicer.TokenSpeedGrpcServer, which needs the smg wheel installed alongside smg-grpc-servicer) before any TokenSpeed engine or Python gRPC machinery exists: the Rust server speaks the gRPC contract on the worker's host and port, the scheduler(s) run headless in a spawned child — TokenSpeed's own headless launch, what ts serve --headless runs — over a same-host msgpack ZMQ connection, and Python keeps only the process lifecycle. As with vLLM and SGLang, that ZMQ hop is inside the worker: the gateway still connects over grpc://, so this is not the ZMQ direct backend, and the gateway cannot tell the two implementations apart.

What the scheduler's msgpack wire does not carry, the Rust path reports rather than emulates:

  • FlushCache and profiling answer UNIMPLEMENTED on a TokenSpeed whose handshake declares no control reply; one that declares it gets them as control calls, each scheduler rank's own handler answering.
  • Ranked top_logprobs and prompt logprobs are refused per request.
  • The msgpack wire bypasses the engine's input processor, which computes a multimodal item's MRoPE position table on the Python path. Items of the Qwen3.5 lineage (Qwen3.5, Qwen3.5-MoE, Qwen4-Exp) and of Qwen3-Omni are served anyway: the Rust servicer computes each family's table itself, as the engine would. The Qwen3.5 lineage's rule reads the checkpoint's vision_config.spatial_merge_size, image_token_id, and video_token_id. Qwen3-Omni's rule reads its facts under the checkpoint's thinker_config: vision_config.spatial_merge_size, plus the clock facts position_id_per_seconds and seconds_per_chunk, which take the engine's defaults (13 and 2.0) when the thinker config leaves them unsaid. On a checkpoint missing a fact its family's rule needs, every multimodal request is refused with an error naming the facts. Items of other MRoPE families (for example Qwen3-VL) are refused per request; the Python servicer serves those models through the engine's own input processor.
  • PD and EPD disaggregation stay with the Python servicer.
  • The RL control plane extras stay with the Python servicer: the rl.* capability advertisement, the live weight_version on generate responses, and is_paused.

Credentials are redacted from the server_args the worker reports exactly as on the Python servicer.

SubscribeKvEvents relays TokenSpeed's ZMQ KV-event publisher, which the servicer turns on by itself — on this path as on the Python one — when the launcher is given no --kv-events-config, at a port found free on the host rather than TokenSpeed's fixed default. An explicit configuration is kept exactly as given, whether it names an endpoint or turns publishing off; without one, SMG_TOKENSPEED_SERVICER_KV_EVENTS=0 leaves the publisher off. With the publisher off, SubscribeKvEvents answers UNIMPLEMENTED.

A hybrid model (Gated DeltaNet, Mamba or KDA layers) keeps its recurrent state in State groups of TokenSpeed's cache, and whether the publisher turns on by itself for such a model depends on the engine installed beside the servicer. An engine whose KV events name their cache group — its KVEvent.BlockStored carries group_idx — publishes the model's history chain beside its State checkpoints, and the publisher turns on as for any other model. An engine whose events carry no group publishes a boundary only while every group holds it, so the model's history chain would never reach the router: on such an engine the servicer leaves the publisher off and logs why once (KV event publishing left off: ..., naming the model's State layers). An explicit --kv-events-config turns the publisher on anyway.

Tuning environment variables: SMG_TOKENSPEED_SERVICER_HANDSHAKE_PORT (default: a free port) pins the port the headless scheduler dials, and SMG_TOKENSPEED_SERVICER_DRAIN_SECS (default 30) is the most a shutdown signal waits for in-flight streams to finish; the drain ends as soon as none is left, so an idle worker does not wait the bound out.

Two bounds cover startup. SMG_TOKENSPEED_SERVICER_STARTUP_TIMEOUT_SECS (default 1800) bounds the wait for a sign of life from the scheduler during the handshake: the launcher reports the scheduler process alive each time it polls it, and the handshake's own messages count too, so a slow but living start — model load and kernel JIT compilation on a cold cache — can outlast this bound and still complete, while a scheduler process that died fails fast instead of waiting it out. SMG_TOKENSPEED_SERVICER_STARTUP_CEILING_SECS (default 14400, four hours) is the most a start may take however alive the scheduler is; 0 lifts the ceiling.

Once the scheduler is connected, SMG_TOKENSPEED_SERVICER_SILENCE_TIMEOUT_SECS (default 300) is how long the scheduler may hold requests in flight, in total since its last sign of life, with nothing pending prefill, before the servicer treats it as dead, fails them and closes the link for the launcher to restart the pair. An output of any kind is a sign of life, and so is a KV-event batch the scheduler's publisher sends: storing or freeing KV blocks is the scheduler's own work, so a chunked prefill that publishes its blocks chunk by chunk is not read as a dead scheduler, even though this wire carries token batches only and says nothing for a prompt until its first token. Only a batch read live off the publisher, in the publisher's sequence, counts — a batch filled in from gap replay, a repeat of a sequence already relayed, a state-snapshot chunk and the relay's load-only heartbeats are not the scheduler's current work and end no silence. Prompt tokens pending prefill — those of requests the scheduler has accepted and produced nothing for yet — extend that bound at SMG_TOKENSPEED_SERVICER_PREFILL_TOKENS_PER_SEC (default 2000 tokens per second: 500 s per million pending prompt tokens); that allowance is what keeps a long prefill from reading as a dead scheduler when it publishes no KV events. The rate is a bound on how slowly a healthy scheduler may prefill, not an estimate of how fast it does; 0 allows nothing.

The vLLM and SGLang Rust servicers take the same drain, startup and silence knobs under their SMG_VLLM_SERVICER_* and SMG_SGLANG_SERVICER_* names.

After the handshake, the planned warm-up runs before the worker reports SERVING; SMG_TOKENSPEED_SERVICER_WARMUP tunes or disables it.


Connect SMG

Point SMG at the gRPC worker with a grpc:// URL. SMG detects the engine on its own by probing for SGLang, vLLM, TensorRT-LLM, TokenSpeed and MLX in turn:

smg launch \
  --worker-urls grpc://localhost:50051 \
  --model-path meta-llama/Llama-3.1-8B-Instruct \
  --host 0.0.0.0 \
  --port 30000

The API is still OpenAI-compatible, so clients send the same requests as with HTTP workers:

curl http://localhost:30000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "meta-llama/Llama-3.1-8B-Instruct",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

Multiple gRPC Workers

smg launch \
  --worker-urls grpc://worker1:50051 grpc://worker2:50052 \
  --model-path meta-llama/Llama-3.1-8B-Instruct \
  --policy round_robin

Reasoning Extraction

For thinking models (DeepSeek-R1, Qwen3, and others), SMG moves chain-of-thought content into a separate field:

smg launch \
  --worker-urls grpc://worker:50051 \
  --model-path deepseek-ai/DeepSeek-R1 \
  --reasoning-parser deepseek_r1

SMG picks the parser from the model name by default; --reasoning-parser overrides that for every model. Separation is on by default, so a plain request is enough:

curl http://localhost:30000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-ai/DeepSeek-R1",
    "messages": [{"role": "user", "content": "What is 25 * 37?"}]
  }'

The response includes both fields:

{
  "choices": [{
    "message": {
      "role": "assistant",
      "content": "925",
      "reasoning_content": "Let me calculate 25 * 37 step by step..."
    }
  }]
}

Send "separate_reasoning": false to keep the reasoning in content.

Supported Reasoning Parsers

Parser Models
deepseek_r1 DeepSeek-R1
deepseek_v31 DeepSeek-V3.1
deepseek_v4 DeepSeek-V4
deepseek_v41 DeepSeek-V4.1
qwen3 Qwen3 and later hybrid-thinking Qwen models
qwen3_thinking Qwen3 -Thinking checkpoints
glm45 GLM-4.5, GLM-4.7, GLM-5.x
kimi Kimi-K2 (Instruct)
kimi_thinking Kimi-K2-Thinking
kimi_k25 Kimi-K2.5
kimi_k3 Kimi-K3
minimax MiniMax-M2
minimax_m3 MiniMax-M3
nano_v3 Nemotron Nano, Nemotron Super, Nemotron-3 family
cohere_cmd Command-R, Command-A
step3 Step-3
inkling Inkling

base and passthrough are also registered, but only for explicit use. The gRPC Pipeline page lists the name patterns each parser is auto-detected from.


Tool Calling

In gRPC mode, SMG parses function calls from model output:

smg launch \
  --worker-urls grpc://worker:50051 \
  --model-path meta-llama/Llama-3.2-3B-Instruct \
  --tool-call-parser llama

To have the gateway execute MCP tools on /v1/responses, add --mcp-config-path; see MCP in Responses API.

Supported Tool Call Parsers

Parser Models
json GPT, Claude, Gemini, Gemma, and other Llama and GLM models that emit plain JSON
llama Llama 3.2
pythonic Llama 4
mistral Mistral, Mixtral
qwen Qwen2.5, Qwen3
qwen_xml Qwen3-Coder, Qwen3.5, Qwen3.6, Qwen3.8, Nemotron-3 family (aliases qwen_coder, nemotron)
deepseek DeepSeek-V3
deepseek31 DeepSeek-V3.1
deepseek32 DeepSeek-V3.2, DeepSeek-V3.2-Exp
deepseek_v4 DeepSeek-V4
deepseek_v41 DeepSeek-V4.1
glm45_moe GLM-4.5, GLM-4.6
glm47_moe GLM-4.7, GLM-5.x
kimik2 Kimi-K2
kimi_k3 Kimi-K3
minimax_m2 MiniMax-M2
minimax_m3 MiniMax-M3
cohere Command-R, Command-A
step3 Step-3
sarashina Sarashina
inkling Inkling

passthrough (no parsing) is also registered. Formats and name patterns are in the gRPC Pipeline reference.

Per-Model Parsers

--tool-call-parser and --reasoning-parser apply to every model. When one gateway serves several model families, set parsers per model through the worker API instead. Labels on the worker registration override the flags for that worker's model:

curl -X POST http://localhost:30000/workers \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${ADMIN_TOKEN}" \
  -d '{
    "url": "grpc://glm-worker:50051",
    "labels": {"tool_parser": "glm47_moe", "reasoning_parser": "glm45"}
  }'

An unknown parser name fails the registration. See Parser Selection for the full precedence rules.


gpt-oss (Harmony) Vocab

Serving gpt-oss models over gRPC uses the Harmony encoding, whose vocab (o200k_base.tiktoken) is fetched when a gpt-oss worker registers — from a local directory if TIKTOKEN_ENCODINGS_BASE is set, otherwise downloaded and cached (TIKTOKEN_RS_CACHE_DIR, default $TMPDIR/tiktoken-rs-cache). If the vocab can't be loaded, that worker's registration fails and retries; other models are unaffected.

For air-gapped deployments, pre-seed the file and point SMG at it:

export TIKTOKEN_ENCODINGS_BASE=/opt/tiktoken   # contains o200k_base.tiktoken

HTTP vs gRPC: When to Use Which

Use Case Recommended Mode
Workers already run OpenAI-compatible HTTP servers HTTP
You need gateway-level tool parsing, reasoning extraction, or Responses MCP gRPC
You serve several model families and want parsers chosen per model gRPC
You want cache-aware routing on token IDs gRPC
Simplest possible setup HTTP

Troubleshooting

Symptom Cause Solution
404 model_not_found No registered worker serves the requested model name Check GET /v1/models and send a served model name or alias
503 no_available_workers Every worker for the model is unhealthy or has an open circuit breaker Check worker health and logs
A grpcs:// worker never registers; the log repeats grpc health check failed ... gRPC connection failed: transport error The gateway's gRPC channel has no TLS Use grpc://, and a service mesh when the hop must be encrypted (Gateway to gRPC Workers)
A worker's gRPC health stays NOT_SERVING after the engine loaded; on the Rust path requests get UNAVAILABLE servicer is warming up The planned warm-up is still running — about a minute by default, ten minutes or more on a multi-process TokenSpeed engine Wait for the worker's Planned warm-up over log line, or set its warm-up variable to fast or off
503 tokenizer_not_ready The model's tokenizer is still loading (the gateway loads it after the worker registers) Retry; the response carries Retry-After: 1, and /readiness reports the same state
503 tokenizer_load_failed The model's tokenizer won't load on its own — no tokenizer_path or model_path to load from, the load failed, or the tokenizer was removed; the message names the reason, and the gateway log has the details Pass --model-path or set a tokenizer_path label and re-register the worker, or register a tokenizer with POST /v1/tokenizers; retrying the request changes nothing until a tokenizer registers
500 tokenizer_not_found The model has no tokenizer and --disable-tokenizer-autoload is set, so the gateway won't load one itself Register a tokenizer with POST /v1/tokenizers
Tool calls or reasoning left in content No parser matched the model name Set --tool-call-parser / --reasoning-parser or a per-model label

Next Steps