Garbled tokens were a KV cache race, not a model problem
- Source
- x.com
- Publisher
- Z.ai
- Date
Scaling laws push model capability forward. But whether that capability becomes reliable in production depends on how we handle Scaling Pain. https://t.co/81QCQw941P In our latest blog, we share how we debugged GLM-5 serving at scale: reproducing rare garbled outputs, repetition, and rare-character generation; tracing and eliminating KV Cache race conditions; fixing HiCache synchronization issues; and introducing LayerSplit for up to 132% throughput improvement. We hope these lessons help the community avoid similar pitfalls and build more robust inference infrastructure.
Context
Z.ai says the garbled text, repetition and stray rare characters that some GLM-5 users saw in coding-agent work came from its serving infrastructure, not from the model. The clue was . Replaying reported bad requests hundreds of times locally produced no failures; the problem appeared only once the team recreated peak-time load, at roughly 3 to 5 bad outputs per 10,000 requests. Failures that track system pressure rather than the content of a request point to how the servers manage state, which is what the Scaling Pain blog linked from Z.ai's post goes on to trace.
The main culprit was a race over the , the stored data for every earlier token that a model reads while generating each new one. Z.ai splits serving between prefill machines, which process the prompt and write its cache, and decode machines, which receive that cache over the network and generate the reply. To keep worst-case latency down, decode aborted any request whose prefill ran past a time budget and freed its cache slots, but the prefill side was not told. A new request could then be given the same memory addresses, finish its own prefill quickly and start generating while the old request's delayed writes were still arriving and overwriting part of its cache. The model was generating from corrupted working state. The fix makes decode wait until prefill confirms that it never started writing or that every write has finished before reusing the slots, and Z.ai reports the abnormal-output rate falling from about 0.1% to below 0.03%.
The blog presents this as one of several independent bugs. A second involved HiCache, which pulls previously computed prompt cache back from CPU memory while the GPU is already computing; one step could start reading before its data had finished loading. Z.ai added an explicit wait, says those anomalies disappeared under the same workload, and submitted the fix to the open-source SGLang inference engine as Pull Request #22811. The same post introduced LayerSplit, which has each GPU hold the cache for only a subset of the model's layers, reporting 10% to 132% higher throughput on 40K- to 120K-token requests; Z.ai later built on it to serve GLM-5.2's million-token context.
- determinism — Whether the same input reliably produces the same output — something LLM systems mostly lack, which changes how you test and debug them.
- KV cache — The memory a model keeps about text it has already read, so generating each new token doesn't require reprocessing the whole conversation.
- attention — The mechanism that lets a model weigh which earlier words matter for the word it's currently processing — the core operation of a transformer.
- Context and context window — Context is the information available for a generation; the context window is the capacity available to hold it.
postWe’re sharing how GLM-5.3 helped build and optimize the inference infrastructure serving GLM-5.3-Flash.- postGLM-5 reaches Coding Plan Pro as Z.ai raises prices
postZ.ai ships GLM-5.3 with big exploit gains and staged weight release
articleGLM-5.3 ships with mandatory reasoning and big coding and cyber gains
- postDense Feedback Let an Infra Agent Serve Its Own Model in Two Weeksjietang
videoKV Cache-Aware Routing and P/D Disaggregation on Kubernetes — Yuchen Fama & Ashish Kamra, Red HatAI Engineer
postWe’re sharing how GLM-5.3 helped build and optimize the inference infrastructure serving GLM-5.3-Flash.Zai_org