ReplaySSM: Rethinking State Storage for Faster Hybrid-Model Decoding
https://developer.nvidia.com/blog/replayssm-rethinking-state-storage-for-faster-hybrid-model-decoding/📌 【NVIDIA 新研究】SSM 解碼卡在記憶體頻寬?ReplaySSM 重寫 state 儲存法
TL;DR:NVIDIA 與 Princeton Dao AI Lab 合作提出 ReplaySSM,把 state 拆成 checkpoint 加 buffer,讓混合模型的 SSM 層解碼重新變快。
🎣 想像一個混合式 LLM 推理服務,真正拖慢速度的居然不是 attention 層,而是原本該又快又省的 SSM 層——這正是 NVIDIA 在服務端 batch size 下觀察到的現象。
🤔 SSM 層為什麼反而變成瓶頸
混合架構(hybrid model)把少量 attention 層與多個 state space model(SSM)層交錯排列,NVIDIA Nemotron 3、Qwen3.5 到 Qwen3.8、Kimi-K3、GLM-5.3-Flash 都是這樣設計,SSM 層採用 Mamba-2、Gated DeltaNet(GDN)或 Kimi Delta Attention(KDA)。SSM 層的設計初衷是加速解碼:用固定大小的 state 取代隨 context 長度成長的 KV cache。但在實際服務的 batch size 下,SSM 層而非 attention,才是最高達 100K token context 下的延遲瓶頸。SSM 層還讓兩個原本能穩定加速 attention 解碼的技巧——speculative decoding 與量化——變得複雜。
原因出在 SSM 每個解碼步驟同時做兩件事:讀取 state 產出這個 token 的輸出,以及更新 state 成為下一個 token 的 state。傳統解碼把這兩件事綁在一起,三個挑戰都由此而生:
- state 記憶體傳輸量:每一步都要讀出、寫回完整的 state,但實際算術量很小,等於是被 HBM 頻寬卡住而非算力。在 Nemotron-3-Super-NVFP4、batch size 256、單張 NVIDIA Blackwell Ultra B300 GPU 的測試中,SSM 層在長達 100K context 以內都是解碼步驟中最大的開銷來源,原因是層數多了五倍,加上單層 FP32 state 就要 4 MiB,相當於一個 FP8 KV cache entry(每 token 0.5 KiB)累積 8K token 的大小。
- speculative decoding 的回滾問題:drafter 先提出 T 個候選 token,驗證後若要回滾,attention 只需移動 KV cache 指標即可,但 SSM 一旦把草稿資訊摘要進 state,就沒有簡單的逆運算。vLLM 的變通做法是每個草稿 token 後都存一次 state 快照,等於每步一次讀、T 次寫,還會限制 GPU 記憶體能同時服務多少請求,導致 speculative decoding 在服務規模下對 SSM 幾乎沒有幫助。
- state 量化誤差累積:量化後的 state 既是輸出來源,也是下一次更新的輸入,捨入誤差會隨每一步重新進入遞迴;KV cache 則只是被多次讀取,不會寫回自己,因此能承受比 SSM state 更低的精度。
🧩 把 state 拆成 checkpoint 加輸入 buffer
ReplaySSM 把 SSM 的遞迴公式展開成一個長度為 h 的視窗:目前的 state 等於「衰減過的 checkpoint」加上「視窗內每個輸入所貢獻的加權外積總和」。傳統解碼是逐步計算左式,ReplaySSM 則改用右式:把 state 表示成一個 checkpoint,加上一小段最近輸入記錄的 buffer(以 Mamba-2 為例是衰減係數、value、key)。
大部分步驟(非 flush 步驟)只需把當前輸入附加進 buffer,直接從 checkpoint 加 buffer 算出輸出,完全不用存整個 state。等 buffer 累積到設定長度 L 筆記錄時才觸發 flush:把 buffer 裡的輸入折算進 checkpoint,把新的 checkpoint 寫回 HBM 一次,再清空 buffer。輸出結果與傳統解碼相比,差異僅在浮點運算誤差範圍內。
用三個問題概括:ReplaySSM 做了什麼——快取最近的 SSM 輸入,把 state 表示成 checkpoint 加這些輸入;改變了什麼——把輸出計算與 state 更新拆開,輸出每步都算,checkpoint 每個視窗才更新一次;達成什麼——降低 state 記憶體傳輸量、簡化 speculative decoding 的回滾、支援低精度 state 讀取而不讓捨入誤差透過遞迴持續累積。
📊 大 batch 下明顯加速,單一請求則沒有感覺
團隊在四個混合模型上評估:Nemotron-3-Nano-4B、Nemotron-3-Super-120B-A12B(Mamba-2,分別跑在 H100 與 B300),Qwen3.5-4B、Qwen3.5-122B-A10B(GDN,同樣分跑在 H100 與 B300)。ReplaySSM 在 vLLM 中實作,state 維持預設的 FP32 精度,視窗長度設為 L=16(四個模型表現最好的設定),speculative decoding 測試則用各模型自帶的 multi-token prediction(MTP)head 產生草稿 token。
因為非 flush 步驟只寫入少量輸入向量而非整個 state matrix,主要的 state 傳輸量大約減半。在服務規模的 batch size 256 下,解碼速度達到 1.46 倍以上;但在 batch size 1 時,其他延遲來源主導,ReplaySSM 在這些測試中沒有帶來加速效果。
⚠️ 材料明確指出,ReplaySSM 的記憶體傳輸優化在小 batch、互動式低延遲場景下不適用,效益集中在服務端大 batch size 的情境;至於 speculative decoding 回滾與量化誤差兩項好處的具體數字,原文對應段落未完整列出。
🎯 實務啟示
ReplaySSM 已整合進 NVIDIA TensorRT-LLM、vLLM、FlashInfer,並已在 GLM-5.3-Flash 與 Kimi-K3 的生產環境中運行,程式碼公開在 GitHub。對正在服務混合架構模型的團隊來說,這是一個不需要改動模型權重、可直接套用的推理層最佳化,特別適合高 batch size 的服務場景。
🔗 來源
- 標題:ReplaySSM: Rethinking State Storage for Faster Hybrid-Model Decoding
- 作者/機構:Michelle Horton(NVIDIA Developer;研究為 NVIDIA 與 Princeton Dao AI Lab 共同合作)
- 連結:https://developer.nvidia.com/blog/replayssm-rethinking-state-storage-for-faster-hybrid-model-decoding/
#SSM #Mamba2 #GatedDeltaNet #TensorRTLLM #vLLM #LLMInference #NVIDIA #HybridModels #SpeculativeDecoding #Quantization
原始資料 NVIDIA Developer · 收集於 2026-10-12
摘要原文
Hybrid models interleave state-space model (SSM) layers with a few attention layers. NVIDIA Nemotron 3 , Qwen3.5 through Qwen3.8 , Kimi-K3 , and GLM-5.3-Flash are all built this way, with Mamba-2 , Gated DeltaNet (GDN) , or Kimi Delta Attention (KDA) as the SSM layer. SSM layers are designed to make decoding fast: they use a fixed-size state in place of a key-value (KV) cache that grows with context length. At serving batch sizes, however, the SSM layers, not attention, can be the latency bottleneck up to 100K tokens of context. SSM layers also complicate two techniques that reliably speed up attention decoding: speculative decoding and quantization. ReplaySSM makes SSM layers the fast part again. It represents the SSM state as a checkpoint plus a buffer of recent inputs. This separates output computation from state updates and addresses three challenges in current SSM decoding: state traffic, rollback for speculative decoding, and error accumulation in a quantized state. ReplaySSM is joint work between NVIDIA and the Dao AI Lab at Princeton. The paper, ReplaySSM: Cache SSM Inputs, Not State , details all three benefits and presents the full evaluation. It is available on arXiv, with code on GitHub . It is integrated into NVIDIA TensorRT-LLM, vLLM, and FlashInfer, and also runs in production in GLM-5.3-Flash and Kimi-K3. Figure 1. Conventional decoding loads and stores the full state at every step. ReplaySSM caches recent inputs, computes outputs from the checkpoint plus buffer, and writes the checkpoint only when the buffer fills Why SSM layers can become a decoding bottleneck Take the Mamba-2 layer used in NVIDIA Nemotron 3 Ultra as an example. It decodes one token with the following recurrence: S t = α t S t − 1 + v t k t ⊤ , o t = S t q t , S_t = \alpha_t S_{t-1} + v_t k_t^\top, \qquad o_t = S_t q_t, where S t S_t is the state, α t \alpha_t is a data-dependent decay, and v t v_t , k t k_t , and q t q_t are the token’s inputs. Each step loads S t − 1 S_{t-1} from high-bandwidth memory (HBM), applies the decay and a rank-1 update, computes the output with q t q_t , and stores S t S_t back. GDN and KDA add a delta-rule correction, but their updates can be written in the same outer-product form, so what follows applies to them too. During decoding, the state does two jobs. It is read to produce this token’s output, and it is updated to become the next token’s state. Conventional decoding does both at once: each step updates the state, reads the output from it, and stores it for the next step. All three challenges come from this fusion. Figure 2. Three challenges of conventional SSM decoding and the ReplaySSM answer to each. Left: decode-step latency breakdown for Nemotron-3-Super-NVFP4 at batch size 256 on one NVIDIA Blackwell Ultra B300 GPU State memory traffic An SSM decoding step loads and stores the full state while performing little arithmetic on it, so the kernel is bound by HBM bandwidth, not compute. At serving batch sizes, that makes the SSM layers, not attention, the largest component of the decode step up to 100K tokens on Nemotron-3-Super-NVFP4 at batch size 256 on one NVIDIA Blackwell Ultra B300 GPU (Figure 2, left). Two factors drive this: Layer count: The model has five times as many SSM layers as attention layers. State size: One layer’s FP32 state is 4 MiB per sequence, while an FP8 KV entry is 0.5 KiB per token, so an SSM layer’s state is the size of an attention layer’s KV cache for 8K tokens. Rollback for speculative decoding Speculative decoding has a drafter propose T tokens, verifies them in one pass through the target model, and rolls back to the last accepted token. Attention naturally supports rollback by moving the KV cache pointer. But once an SSM has summarized the drafts into its state, the update has no easy inverse, so rollback becomes expensive. Serving engines such as vLLM work around this by storing a state snapshot after every draft token and picking the one that matches the accepted prefix. That is one read and T writes per step on a memory-bound path, and the snapshots cap how many requests fit in GPU memory. As a result, speculative decoding, a reliable speedup for Transformers, barely helps SSMs at serving batch sizes. State quantization The quantized state produces the output and is the input to the next update, so its rounding error re-enters the recurrence at every step. A KV cache has no such loop: a quantized entry is read many times but never written back into itself, which is why KV caches tolerate lower precision than SSM states. Qwen3.5-122B-A10B-NVFP4, for example, uses the NVIDIA NVFP4 4-bit floating-point format for its weights, with an FP8 KV cache and an FP32 SSM state. How ReplaySSM represents the state The SSM recurrence can be unrolled over a window of h tokens: S t = α t S t − 1 + v t k t ⊤ = γ h S c k p t + ∑ j = 1 h γ j + 1 : h v j k j ⊤ , S_t = \alpha_t S_{t-1} + v_t k_t^\top = \gamma_h\, S_{\mathrm{ckpt}} + \sum_{j=1}^{h} \gamma_{j+1:h}\, v_j k_j^\top, where S c k p t S_{\mathrm{ckpt}} is the state before the window and γ \gamma is the cumulative decay. Conventional decoding follows the left side step by step. ReplaySSM uses the right side: it represents the state as a checkpoint plus a small buffer of recent input records ( α j \alpha_j , v j v_j , k j k_j ) for Mamba-2. On most steps, which we call non-flush steps, it appends the current inputs to the buffer and computes the output from the checkpoint and the buffer without storing a state. When the buffer of L records fills, a flush step folds the buffered inputs into the checkpoint, writes the new checkpoint to HBM once, and clears the buffer. The outputs match conventional decoding up to floating-point differences. ReplaySSM’s approach can be summarized in three questions: 1 What does ReplaySSM do? It caches recent SSM inputs and represents the state as a checkpoint plus those inputs. 2 What does this change? It separates output computation from state updates: outputs are computed every step, while the checkpoint is updated once per window. 3 What does this achieve? It reduces state memory traffic, simplifies speculative rollback, and supports low-precision state reads without propagating their rounding error through recurrent updates. How we evaluated ReplaySSM We evaluate four hybrid models from two families, Nemotron 3 with Mamba-2 layers and Qwen3.5 with GDN layers, from 4B dense models on one NVIDIA H100 Tensor Core GPU to 120B-class mixture-of-experts (MoE) models on one NVIDIA Blackwell Ultra B300 GPU (Table 1). We implemented ReplaySSM in vLLM and compared it with vLLM’s own kernels at their best launch configuration. Performance runs keep the SSM state in FP32, the default precision for these models, and use a window of L = 16, the best-performing window size for all four models. Speculative decoding tests use each model’s multi-token prediction (MTP) head to generate draft tokens. Model SSM layer Weights GPU SSM / attention layers Nemotron-3-Nano-4B Mamba-2 BF16 1×H100 21 / 4 Nemotron-3-Super-120B-A12B Mamba-2 NVFP4 1×B300 40 / 8 Qwen3.5-4B GDN BF16 1×H100 24 / 8 Qwen3.5-122B-A10B GDN NVFP4 1×B300 36 / 12 Table 1. Evaluated models and hardware. Each model runs on one GPU without tensor parallelism Benefit 1: Reduce state memory traffic Over a window of L tokens, conventional decoding reads the state L times and writes it L times. ReplaySSM still reads the checkpoint on every step, because the output needs it, but writes it only once, during the flush. A non-flush step has one job—computing the output—and writes only the new input record, a few vectors instead of a full matrix. This roughly halves the dominant state traffic. At serving batch sizes, memory bandwidth limits the conventional kernel’s performance, so reducing state memory traffic speeds up decoding. At batch size 1, other sources of latency dominate, and ReplaySSM provides no speedup in these tests. At batch size 256, the kernel runs 1.46× to 1.
由 claude-code/sonnet 自動生成