Serving & Batching

CKE is a C-first compiler, kernel library and runtime; serving is a layer on top of the generated model, not a redefinition of the project. This page documents how HTTP serving actually executes today, what the merged two-slot batch decode does and does not do, and what true continuous batching still requires.

Default path: shipped, verified batch2: merged, experimental opt-in Continuous batching: planned, not implemented

Want to run a client against CKE? The local harness quickstart maps tested model artifacts to Qwen Code, Antigravity SDK and experimental clients, with server and client configuration. It distinguishes a working HTTP connection from a completed tool task.

Terms that must not be conflated

Four related but distinct capabilities. Claims about CKE serving should name exactly which one is meant:

Today CKE ships the first and an experimental two-row form of the second and third. The opt-in owner can admit and retire a request at a decode boundary, but a joining request's synchronous prefill stalls the other stream by default. An explicit decode-replay option now yields after a bounded prompt-token chunk; its numerical behavior needs artifact-specific certification. Mixed-row prefill and broader batch capacity remain planned. Concurrent HTTP requests, multi-threaded kernels and serial request multiplexing are not, by themselves, batched decode.

Capability status

CapabilityStatusSource evidenceTest evidence
HTTP serving (OpenAI-style /responses, SSE streaming) Shipped server/live.py, version/v8/scripts/ck_serve_v8.py test_live_streaming.py, lifecycle hardening tests
Bounded admission (single-flight + FIFO queue, HTTP 429 overflow) Shipped server/live.py _FlightAdmission (8 waiters, 30 s) test_serving_lifecycle_hardening.py
Cancellation & cleanup (POST /v1/responses/{id}/cancel, disconnect watcher, step-boundary cancel) Shipped server/live.py, ck_cli_v8.c cancel flag lifecycle hardening + streaming socket tests
Native progress snapshot for an ordinary request Diagnostic GET /v1/cke/native-progress, ck_session_v8_get_progress test_native_progress.py, generated prefill layer test
Per-request KV isolation in default mode (reset per request, shared weights) Shipped ck_session_v8_generate → kv_reset; one process-wide libmodel.so serving lifecycle tests; A→B→A smoke runs
Two-slot batched decode (ck_model_decode_batch2, M=2 projection GEMMs) Experimental server/batch_decode.py, batch_decode_codegen_v8.py, ck_model_abi_v8.h test_batch_decode_loop.py, test_v8_two_row_batch_decode.py
Two-slot HTTP decode (opt-in --batch-http-extra-bytes) Experimental server/batch_http.py, ck_serve_v8.py test_batch_http.py (19 tests, incl. real-socket SSE)
Opt-in staged decode-replay prefill (two slots) Experimental server/batch_http.py, ck_session_v8_batch2_prefill_append test_batch_http.py, test_batch_decode_loop.py
Scalable continuous batching (mixed rows, N>2) Planned——
Mixed / interruptible prefill inside a decode step Planned——
Batched attention / KV across rows Planned——
Continuous-batching performance benchmarks Planned——

Passing scheduler unit tests are not proof of batched model execution or end-to-end serving throughput; those require separate evidence. This table is the claim boundary for the whole page.

Observing a long prefill

On a rebuilt ordinary-session server, GET /v1/cke/native-progress returns the server instance, a request serial and its current phase. During generated prefill it reports completed and total decoder layers for the current chunk, plus that chunk's token count and absolute starting position. The count advances only after a layer's generated operations return; it does not count tokens completed inside a layer or prove numerical correctness. A bundled model without the progress callback reports zero total layers. The endpoint contains no prompt or generated text. It is unavailable in the opt-in batch HTTP mode.

Use the request serial and chunk position when comparing samples. A steady counter within one expensive layer is not evidence of a stalled server. SSE heartbeats and CPU activity remain separate from completed native work. Cancellation is cooperative and may wait for the current kernel to return.

Who owns what — where scheduling ends and generated C begins

ComponentOwns
Model compiler + code generationCircuit lowering, provider resolution, memory plan, emitted C
Generated model runtime (libmodel.so)Actual model execution: prefill, decode steps, KV/state storage inside its arena
Kernel executionArithmetic over supplied pointers; one process-global threadpool
Serving layer (server/live.py, batch_http.py)HTTP, admission, request lifecycle, streaming, cancellation, slot policy
Session bridge (session_v8.py / ck_cli_v8.c)ctypes/native boundary, session state, batch2 slot ownership

The serving layer never computes logits, and the generated runtime never sees HTTP. The boundary is the session ABI: the host passes token ids in and receives logits (or decode steps) out. One process loads the model once; every request shares the mapped weights, while per-request state occupies separate native-session-owned slot arenas.

Default: serialized single-flight serving

Without batch flags, one request owns the loaded model end to end. A bounded FIFO queue (8 waiters, 30 s timeout) absorbs bursts and returns HTTP 429 beyond that. This is deliberate: each in-flight request already dispatches kernels across the whole threadpool, so a second concurrent generation would oversubscribe cores and contend for DRAM bandwidth rather than speed anyone up.

Diagram of the v8 HTTP serving path: clients, bounded FIFO admission, one SessionV8 over a generated libmodel.so, synchronous prefill, per-token decode, SSE streaming, and KV reset on release. A timeline shows a second request queued until the first finishes.
Request lifecycle and two-request timeline for the default path. Every transition shown exists in code today; sources in the diagram footer.

Experimental: two-slot batched decode (batch2)

Merged in PR #709 (native/host loop) and PR #715 (HTTP wiring). When enabled, two requests can share one generated-C decode call per tick: projection GEMMs run batched at M=2 with weights loaded once, while attention, KV writes and positions stay sequence-local. A host-side loop keeps sampling, stop rules and budgets strictly per request.

# master switch plus required caps (see runbook for the exact, current invocation)
cks-v8-serve … --batch-http-extra-bytes BYTES \
               --batch-http-prompt-cap TOKENS \
               --request-output-cap TOKENS
Diagram of the batch2 decode loop: two request-owned slots with per-request sampling feed one ck_model_decode_batch2 call per tick. Inside the generated C, shared stages run M=2 batched projection GEMMs and local stages run per-row sequential attention and KV with sequence-state switching.
batch2 internals. Enablement, limits and the exact claim boundary are in the v8 runbook, Experimental batch HTTP.

What you get

  • Two token rows can enter one generated-C step: either two decode rows or, with the mixed option, one decode and one prompt row. The owner records all such calls as shared steps and tracks mixed calls separately.
  • Compatible projections reuse weight tiles across both rows; a throughput benefit must be measured for the loaded artifact.
  • Per-request isolation: separate KV arenas, RNG, stop rules, output caps, cancellation and failure recovery.
  • Bounded admission: a third concurrent request receives HTTP 429; delivery queues are bounded so a slow consumer cannot stall the owner.

What you do not get

  • Not every layer operation is batched: attention and KV updates remain sequence-local inside the call.
  • Whole-prompt prefill remains the default. The explicit --batch-http-decode-replay-chunk-tokens option yields between bounded prompt chunks. The additional experimental --batch-http-mixed-one-row option can pair one prompt token with one decode token in a shared generated call. One token operation can still be slow.
  • Fixed at two slots, KV-cache-only generated models (recurrent-state models are outside this capability).
  • Not yet certified for sustained/overnight concurrency — treat as experimental.

Planned: continuous batching

Batch2 already admits and retires requests at decode boundaries within two fixed slots. The optional staged path can pause between generated decode-replay prompt chunks. An additional one-row mixed step has local generated-model parity evidence and resolved-bundle, chat-only HTTP acceptance on Gemma3. An artifact-bound check also finds that staged and ordinary Gemma3 prefill diverge from 10 tested tokens onward; the correct path has not yet been established against a publisher reference. Two real tool-harness tasks on a batch-capable artifact remain the next practical certification step. Measured expansion beyond two slots and multirow prompt chunks follow. Batched attention and paged KV may improve later scaling, but neither is required to establish the first correct continuous-admission scheduler. A general batch-N ABI, memory pool and paged KV do not exist yet.

Three-lane roadmap: shipped serialized HTTP serving, experimental two-slot decode with limited dynamic admission, and a planned scheduler with bounded prefill, fair admission and broader batch capacity.
Roadmap and target scheduler shape. Grey elements are design direction with no implementation claims.

Memory behavior under concurrency

Weights are mapped once per server process and shared by every request. Per-request cost is KV cache (and, for hybrid models, recurrent state) plus delivery buffers:

KV bytes ≈ 2 × KV-owning layers × KV heads × head dim × tokens × bytes/element

That approximation hides important detail: distinct KV storage owners (not layer count), grouped-query geometry, sliding-window layers, hybrid/recurrent state, alignment and cache layout. Use the Model Sizing Lab for an architecture-aware estimate. Also distinguish maximum resident requests by memory, active sequence slots (2 in batch mode), token rows per generated step (2 in this path), queued responses, and the sustainable concurrent workload. A queued request is not an active sequence; these limits are not interchangeable.

Performance: what to expect, and what not to claim

On CPUs, decode is usually memory-bandwidth-bound. Batching two rows shares each weight read across both sequences, so aggregate tokens/s can rise — while per-request rate can fall, and prefill interference adds latency for a joining request. Whether batch2 helps a given deployment depends on model size, quantization, context distribution and thread count. There are no published continuous-batching benchmarks for CKE yet; do not cite throughput claims without them. Measure prefill and decode separately, at fixed threads, with warm-up, and report aggregate throughput and per-request latency as distinct numbers.

Model-specific boundaries

Serving behavior is per generated artifact, not per server. The batch2 path currently requires a generated KV-only batch-capable model layout, and enable_batch2 fails at startup otherwise — the server refuses to boot in batch mode rather than silently degrading. Recurrent-state models (e.g. DeltaNet-style layers), vision-language bridges and audio pipelines have different state ownership and are outside the batch2 capability today; their single-flight serving follows the default path. For the per-circuit record of which models carry serving declarations and certification evidence, see the v8 Serving Coverage Inventory.

Evidence and sources

Page audited against origin/main 4a4be7279 by source inspection; runtime claims rest on the cited tests, not on new benchmarks run for this page.

Local speech performance regression

Whisper latency depends on the loaded generated bundle, not only server source. On P3 (Intel i7-14700T), switching the resident HTTP service from the older whisper-base-current bundle to the retained attention-cross-head-parallel-v3 bundle reduced one identical 20-second recording from 35.155 seconds to a 2.057-second median (three trials, 2026-11-07). Text and EOS termination matched. Both services used four native threads and a four-core quota. This is a deployment correction, not a new kernel optimization or an independent accuracy certification.

scripts/whisper_service_benchmark.py accepts a private JSON configuration with endpoint, exact CPU model, repeat count (3–20), expected worker environment, and encoder/decoder library, manifest and weight SHA-256 identities. Each case specifies name, WAV path, WAV SHA-256, expected text and maximum median latency. Inputs must be mono 16 kHz PCM16. Keep recordings and transcripts private.

python3 scripts/whisper_service_benchmark.py   --config /private/speech-baseline.json --output /private/current-attempt.json
python3 scripts/local_harness_nightly.py   --config /private/harness.json --state-dir /private/nightly   --speech-perf-config /private/speech-baseline.json

The existing nightly lock and PAUSE control apply. PAUSE prevents lane startup; it does not interrupt a running request. The helper retains warm-up and every measured response, worker identity, host load, queue, inference and client wall timing. It replaces stale PASS before reading configuration. Wrong transcripts, changed artifacts, worker restarts and exceeded latency budgets fail; unavailable or busy endpoints are incomplete. A different CPU cannot reuse this timing baseline. Native environment is verified through local /proc worker records, so run this lane on the service host.

The initial P3 guard uses five seconds per clip, intentionally detecting a return to the obsolete 26–35 second path rather than claiming sensitivity to small regressions. Do not apply it across different machines or workloads. Short clips and one 20-second sample do not certify all speech. Warm request timing excludes cold model startup; loaded identity retains model initialization time separately. Kokoro currently has separate profiling evidence and no equivalent performance gate. First HTTP audio is not first audible headset output. Qwen TTS was not tested.

Image
100% | |
Scroll to zoom | Drag to pan | W/H to fit | 0 to reset | ESC to close