Inside SGLang-Omni (4): The Data Plane — ZMQ, CUDA IPC, and KV Page Transfer
Series:
- Architecture, traced through one transcription request
- Streaming: SSE token deltas vs. realtime re-decoding
- Keeping audio off the LLM’s critical path
- The data plane: ZMQ, CUDA IPC, and KV page transfer (this post)
- Making it fast: radix cache, CUDA graphs, torch.compile, speculative decoding
- Running Qwen3-ASR on a 12 GB RTX 5070
Code links point at upstream commit 8f07378. The project’s own communication doc is a good companion to this post.
A multi-stage pipeline has two kinds of traffic: small messages (“request X is ready for you”, “abort X”) and large tensors (hidden states, audio codes, embeddings). SGLang-Omni keeps them apart. The small messages go over ZMQ as msgpack; call that the control plane. Tensors take the cheapest path the topology allows, and ZMQ only carries a reference to where they are; that’s the data plane.
The control plane: brokerless ZMQ
ZeroMQ is a library, not a server. There’s no daemon. Each process links libzmq, one side calls bind() on an endpoint, the other calls connect(), and messages go directly from process to process. Socket types provide queuing, reconnection, and patterns such as load-balancing and fan-out.
The wiring is in pipeline/control_plane.py:
| Socket | Binds | Connects |
|---|---|---|
stage inbox, PULL on ipc://…/stage_<name>.sock | each stage | coordinator and upstream stages (PUSH) |
coordinator completions, PULL | coordinator | every stage |
aborts, PUB | coordinator | every stage (SUB, subscribed to everything) |
On one node, the endpoints are Unix-domain ipc:// sockets with paths generated per pipeline run (runtime_config.py). Messages are msgpack with binary support. Raw bytes such as uploaded audio cross as bytes, with no base64.
Why not Redis, or another broker?
I wondered about this, and I think ZMQ is the better fit here.
This traffic is on the hot path. A broker puts an extra process between every sender and receiver, so each message takes two hops instead of one. Streaming sends a message every few decode steps per request, and that extra hop shows up directly in time-to-first-token and time-to-first-audio.
A broker would also be a shared point of failure. Today a dead stage fails only its own requests; a slow or unavailable broker would stall every stage at once. And the things a broker is good at don’t help much. Requests are short-lived and fail fast, so persistence and replay buy nothing, and ZMQ’s high-water marks on direct sockets already let a slow consumer push back on its producer. Tensors would still need CUDA IPC or shared memory either way.
Redis does fit well next to the pipeline, for cluster-level state such as session affinity for a router, rate limits, or shared caches. For a multi-node control plane, NATS or gRPC would be more natural candidates than Redis.
The data plane: four transports
CommRouter picks the transport for each edge from where the two stages run. There’s no user-facing backend selector.
| Path | When | Cost |
|---|---|---|
| LOCAL_OBJECT | both stages in one OS process | a Python reference; zero copies |
| Direct PyTorch CUDA IPC | separate processes, same placement, provably compatible device numbering | zero copies; the receiver maps the producer’s memory |
| Pooled CUDA IPC relay | any other same-node GPU edge, including across GPUs | two on-GPU copies through a sender-owned pool |
| SHM | CPU tensors on the same node | copy in and out of shared memory |
| Mooncake | across nodes | network transfer |
Before any relay path, stage_io.write_payload walks the payload, takes out every tensor, pickles the remaining tensor-free payload as a header, and packs the tensors into one flat uint8 buffer. Backends only ever move a block of bytes.
How CUDA IPC works
Normally, GPU memory belongs to the process that allocated it. CUDA IPC is the driver feature that lets other processes share it:
- Export: process A calls
cudaIpcGetMemHandle(ptr)and gets a small opaque handle. - Send: the handle is just bytes, so it can go over any channel. Here, ZMQ.
- Import: process B calls
cudaIpcOpenMemHandle(handle), and the driver maps the same physical memory into B. No data is copied. - Synchronize: A records a CUDA event created with the interprocess flag and exports its handle as well. B makes its stream wait on that event before reading.
- Lifetime: A must not free the memory while B is using it.
There are limits. IPC works on the same node only, the processes need a compatible IPC namespace (--ipc=host in Docker), and reading another GPU’s memory needs peer-to-peer (P2P) access. PyTorch wraps the mechanism as storage._share_cuda_() and rebuild_cuda_tensor(), including a shared-memory reference counter. The relay calls those directly (dump_cuda_storage_handle).
Mode 1: direct (zero-copy)
The sender serializes each CUDA tensor with PyTorch’s reducer and sends the handles plus the header in one message. The receiver maps the producer’s allocations. There’s no copy and no acknowledgement: PyTorch’s IPC reference counting keeps the producer’s block alive until the consumer releases it. The router uses this mode only when it can prove both processes number their CUDA devices the same way. Otherwise, a different CUDA_VISIBLE_DEVICES in each process could make the same device index mean different GPUs.
Mode 2: the pooled relay
Opening an IPC handle for every new tensor is expensive, and zero-copy keeps producer memory allocated until the consumer lets go. The pooled relay (relay/cuda_ipc.py) exports and imports once and then reuses the mapping:
- Setup: each sender allocates one large GPU buffer (1 GiB by default) split into 64 KiB slots. The pool’s handle is exported once per receiver, and the receiver caches its import.
- Put: reserve contiguous slots, waiting if the pool is full. That wait is the backpressure. Copy the tensor into those slots on the GPU, record an interprocess event, and send
{pool_id, offset, size, event}. - Get:
stream.wait_event(ready)makes the receiver’s stream wait on the GPU, without blocking a CPU thread. Then copy out into the receiver’s buffer. Across GPUs, that copy is a P2P copy over NVLink or PCIe. - Ack: a single
DataAckMessagefrees the slots.
flowchart TD
subgraph SND["Sender GPU"]
direction TB
PT["producer tensor"] -->|"copy_ (device to device)"| POOL["sender-owned pool<br/>64 KiB slots"]
EV["ready_event (interprocess)"]
end
subgraph RCV["Receiver GPU (same GPU or a peer)"]
DST["destination buffer"]
end
POOL -->|"pool mapped once by IPC handle,<br/>copy_ after wait_event (P2P across GPUs)"| DST
SND -. "ZMQ DataReadyMessage: pool_id, offset, size, event" .-> RCV
RCV -. "ZMQ DataAckMessage: free the slots" .-> SND
There’s one ordering rule: the sender publishes the ready message before waiting on its own put. For credit-based backends such as NIXL, waiting first would deadlock, because the receiver’s read is what returns the sender’s credit.
| Direct | Pooled | |
|---|---|---|
| Copies | 0 | 2 |
| IPC handle open | for each new allocation | once per sender–receiver pair |
| Memory | producer tensors stay pinned | a fixed pool, with backpressure |
| Release | PyTorch reference count | explicit acknowledgement |
| Cross-GPU | no | yes, with P2P |
One practical note: GeForce cards usually have P2P disabled. A pipeline split across two consumer GPUs can’t use the CUDA IPC relay between them. The relay logs a warning suggesting the SHM relay, which copies through host memory.
KV page transfer: prefill/decode disaggregation
The same CUDA IPC machinery also supports prefill/decode (PD) disaggregation. A Prefill engine processes the prompt, then hands its KV cache to a Decode engine, which generates the remaining tokens. Splitting the two keeps long prefills from stalling every running decode. The cost is one KV transfer per request.
As of this commit it’s framework infrastructure. OmniPrefillScheduler, OmniDecodeScheduler, the handshake, and the copy are all implemented and unit-tested, but no shipped model config uses them yet.
A three-message handshake
sequenceDiagram
participant P as Prefill (sender)
participant D as Decode (receiver)
P->>D: KVTransferPrepareMessage (source pages, layout, decode continuation)
D->>D: reserve(): check the layout, allocate slots
D-->>P: KVTransferReadyMessage (destination pages)
P->>P: record an interprocess event, export pool handles (cached)
P->>D: DataReadyMessage (kind = KV_PAGES)
D->>D: wait_event, gather/scatter copy, commit()
D-->>P: DataAckMessage
P->>P: release the lease, free the source pages
Prefill stops each request right after sampling its first token (handoff_prefilled_requests). It doesn’t apply stop rules to that token; Decode does. Everything except the KV gets packed into a serialized DecodeContinuation (prompt IDs, the first token, sampling parameters, the payload), and a lease keeps the request’s KV slots allocated after it leaves the batch.
The receiver allocates before any bytes move (DecodeKVReceiver.reserve). The two layouts must match exactly (same model, same KV dtype, one page per token), and if Decode’s pool is full, the transfer is rejected here, before anything is copied.
The copy itself goes straight from one KV pool into the other, with no staging pool in between. For each layer’s K and V buffers, one sgl_kernel.transfer_kv_per_layer_mla launch gathers the scattered source slots and scatters them into the scattered destination slots (get_kv_pages). Decode then rebuilds an SGLang Req from the continuation, pointing at the newly filled slots, and runs it in SGLang’s DisaggregationMode.DECODE.
Freeing is the fiddly part. Only the scheduler thread may free KV, because SGLang’s request table and radix cache belong to it, so the comm thread just puts released requests on a queue for the scheduler to pick up.
The constraints at this commit: same node only (CUDA IPC), identical KV layouts, identical TP sizes (rank i sends to rank i), P2P access between the GPUs, and no re-prefill if Decode retracts a request.
Try it: watch tensors move on one GPU
Single-stage Qwen3-ASR never uses the data plane, so this section uses a multi-stage model that fits in 12 GB: Qwen3-TTS 0.6B Base, which clones a voice from a reference clip. Its pipeline is preprocessing → tts_engine → vocoder, and tts_engine streams codec frames into the vocoder (stream_to=["vocoder"]). By default all three stages run in one process (process: pipeline). Moving the vocoder into its own process shows the data plane switching transports.
Same RTX 5070 as before, but Qwen3-TTS’s defaults don’t fit in 12 GB. At startup the vocoder captures a lot of CUDA graphs (decoder graphs plus incremental codec graphs for batch sizes up to 64), and they ran out of memory before the KV pool was even sized. Capping the vocoder batch at 4 wasn’t enough either, so for this section I turned the vocoder graphs off. That changes how fast the vocoder runs, not how data moves.
To see the transfers, set SGLANG_OMNI_COMM_TRACE=1. Every relay or IPC transfer then logs one JSON line (COMM_TRACE {...}).
1. One process: nothing to trace
SGLANG_OMNI_COMM_TRACE=1 sgl-omni serve --model-path Qwen/Qwen3-TTS-12Hz-0.6B-Base --model-name qwen3-tts --port 8000 \
--vocoder.factory.initial_cuda_graph false --vocoder.factory.followup_cuda_graph false \
--vocoder.factory.incremental_codec_cuda_graph false \
--tts_engine.engine.max_running_requests 8 --mem-fraction-static 0.5
The ZMQ endpoints are Unix sockets in a per-run directory under /tmp/sglang_omni/:
$ ls /tmp/sglang_omni/<run>/
abort.sock completion.sock
comm_preprocessing_rank0.sock stage_preprocessing.sock
comm_tts_engine_rank0.sock stage_tts_engine.sock
comm_vocoder_rank0.sock stage_vocoder.sock
That’s the control plane from the table above: one stage_* inbox per stage, the coordinator’s completion and abort sockets, and per-rank comm_* sockets that the comm engine uses for transfer handshakes.
Then stream some speech. This request uses the cookbook’s reference clip and transcript:
curl -N -X POST http://localhost:8000/v1/audio/speech -H "Content-Type: application/json" -d '{
"model": "qwen3-tts", "voice": "default", "stream": true, "response_format": "pcm",
"input": "Streaming this sentence sends codes to the vocoder chunk by chunk.",
"references": [{"audio_path": "ref.wav",
"text": "We asked over twenty different people, and they all said it was his."}]
}' --output out.pcm
grep -c COMM_TRACE server.log
0
There are no trace lines, because every hand-off is a LOCAL_OBJECT: a Python reference passed within one process. The whole server uses one GPU process, holding 7.6 GB.
2. Split the vocoder into its own process
SGLANG_OMNI_COMM_TRACE=1 sgl-omni serve ... --vocoder.process vocoder \
--tts_engine.gpu_memory_fraction 0.6 --vocoder.gpu_memory_fraction 0.3
The two gpu_memory_fraction flags are required. Without them, startup refuses with GPU 0 is shared by multiple process groups without a declared total footprint. When two processes share a card, each one has to declare its share, so the runtime can check the total before anything allocates.
nvidia-smi now shows two GPU processes, 9.9 GB and 1.5 GB. The same streaming request produces trace lines. Here’s the first of each kind:
{"event": "comm_transport_selected", "stage": "tts_engine", "peer_stage": "vocoder", "direction": "stream", "transport": "torch_cuda_ipc"}
{"event": "comm_stream_send", "from_stage": "tts_engine", "to_stage": "vocoder", "chunk_id": 0, "bytes": 1792, "transport": "torch_cuda_ipc"}
{"event": "comm_stream_read", "from_stage": "tts_engine", "to_stage": "vocoder", "chunk_id": 0, "bytes": 1792, "transport": "torch_cuda_ipc"}
The router chose direct PyTorch CUDA IPC, the zero-copy mode. Both processes are on the same placement, so it can prove they number the GPU the same way. Pairing each send with its read by chunk_id, for one 3.6-second sentence:
chunks per request: 45
chunk sizes (bytes: count): {6400: 1, 128: 44}
send->read ms: p50=0.355 p90=0.423 max=5.597
Each 128-byte chunk is one codec frame: 16 codebook IDs × 8 bytes. The first chunk is larger and carries the opening frames. A chunk reaches the other process in about a third of a millisecond. Only the IPC handles and a small header go over ZMQ; the receiver maps the producer’s GPU memory directly.
One thing tripped me up: only streaming requests produce comm_stream_* lines. Non-streaming requests also completed fine in the split layout, but logged nothing. Non-streaming responses go to the vocoder as one payload over direct CUDA IPC, and that branch records a profiler event (stage_hop_sent) but no comm trace. The startup warmup request is a streaming one, which is why it showed up in the trace when my first non-streaming tests didn’t.
3. What the extra process costs
Time to first audio byte for five fresh sentences in each layout:
| run 1 | run 2 | run 3 | run 4 | run 5 | |
|---|---|---|---|---|---|
| one process | 63.8 ms | 23.6 ms | 20.8 ms | 20.5 ms | 20.2 ms |
| vocoder in its own process | 53.1 ms | 90.6 ms | 39.3 ms | 39.0 ms | 38.8 ms |
Once warm, the split layout delivers first audio ~19 ms later (≈39 vs. ≈20 ms), even though each chunk’s IPC hop takes only 0.36 ms. The extra time is spent elsewhere on the first chunk’s path, such as the cross-process payload hand-off and process scheduling. I didn’t profile further. Total synthesis time was similar in both layouts, at 0.8–1.0 s per sentence.
Running the vocoder in its own process isolates it (its own memory budget, its own crash domain) and is the first step toward running it on another GPU. On a single card, it’s mostly overhead. In the split run, the vocoder’s 30% budget was also tight: the allocator logged three failed allocations that it recovered from, without failing any request.
What a single GeForce card can’t show is the pooled relay across GPUs and KV page transfer. Both need two GPUs with peer-to-peer access, and no shipped model config uses PD yet.
Next: part 5 covers the performance features: the radix cache, CUDA graphs, torch.compile, and speculative decoding.