---
title: "You are asked to serve a hybrid model with 48 layers: 36 Gated DeltaNet (linear-attention) layers and 12 full-attention…"
url: https://gurkanozkan.ai/learn/questions/recent-a-kvcache-01/
markdown: https://gurkanozkan.ai/learn/questions/recent-a-kvcache-01.md
kind: question
role: Applied LLM
stage: Technical
difficulty: Hard
json: https://gurkanozkan.ai/api/learn/questions/recent-a-kvcache-01.json
robots: noindex
---

# You are asked to serve a hybrid model with 48 layers: 36 Gated DeltaNet (linear-attention) layers and 12 full-attention layers with 2 KV heads of dimension 256. Estimate KV memory per token in bf16, compare it with an all-attention version, and explain what changes for prefix caching.

Applied LLM · Technical · Hard

## Answer

*Model answer, written in a candidate's voice*

### In short

- Only the 12 full-attention layers grow a per-token cache: 2 (K and V) x 12 layers x 2 heads x 256 x 2 bytes = 24,576 B = 24 KiB per token; the 36 linear-attention layers keep a fixed-size recurrent state per sequence.
- All-attention with the same head layout would be 48 layers x 2 x 2 x 256 x 2 B = 98,304 B = 96 KiB per token, about 4x larger, so the hybrid fits roughly 4x the long-context concurrency in the same memory, plus a constant state per sequence.
- The recurrent state summarises the whole prefix, so it cannot be sliced at an arbitrary block boundary; prefix reuse needs state snapshots stored at chosen positions (for example at fixed intervals plus prompt ends), which costs memory and engine support.
- Prefix caching and CUDA-graph paths for hybrid or Mamba-style layers have been experimental, so validate correctness and stability under concurrent load before enabling them.
- The rest of the budget still includes fixed state x concurrent sequences, weights of all experts for a MoE, and activation workspace.

### In full

The core point is that only the full-attention layers pay per-token KV memory, while the 36 Gated DeltaNet layers keep a fixed-size recurrent state per sequence rather than a growing cache.

```calc
hybrid:         2 (K and V) x 12 layers x 2 KV heads x 256 dim x 2 bytes = 24,576 B = 24 KiB per token
all-attention:  2 x 48 layers x 2 x 256 x 2 B                          = 98,304 B = 96 KiB per token
ratio:          98,304 / 24,576 = 4
```

So the hybrid should fit roughly 4x the long-context concurrency in the same memory, plus a constant state per sequence. That also changes prefix caching: full-attention KV can be reused at block boundaries, but the linear-attention state summarises the whole prefix and cannot be sliced at an arbitrary block boundary, so reuse needs state snapshots stored at chosen positions (for example at fixed intervals plus the end of each prompt), which costs memory and engine support. I would not turn prefix caching or CUDA-graph paths on by default, since hybrid and Mamba-style paths have been experimental; I would validate correctness and stability under concurrent load first. Finally, the KV estimate is only part of the budget: fixed state x concurrent sequences, the weights of all experts for a MoE, and activation workspace still have to fit alongside it.

*Corrected by an independent AI reviewer.*

## What a strong answer covers

- Only full-attention layers grow a per-token cache: 2 × 12 layers × 2 heads × 256 × 2 bytes = 24,576 B = 24 KiB per token; the linear-attention layers keep a fixed-size recurrent state per sequence
- All-attention with the same head layout would be 4× larger (96 KiB per token), so the hybrid fits roughly 4× the long-context concurrency in the same memory, plus a constant state per sequence
- Recognises that the recurrent state summarises the whole prefix, so it cannot be sliced at an arbitrary block boundary; prefix reuse needs state snapshots stored at chosen positions (for example at fixed token intervals and at the end of shared prompts), which costs memory and engine support
- Notes engine maturity: prefix caching and CUDA-graph paths for hybrid or Mamba-style layers have been experimental, so validate correctness and stability under concurrent load before enabling them
- Accounts for the rest of the budget: fixed state × concurrent sequences, weights of all experts for a MoE, and activation workspace

## Common mistakes

- Applying the per-token KV formula to every layer including the linear-attention ones
- Assuming block-hash prefix caching works unchanged for recurrent state

## Follow-ups

- Where would you place state snapshots for a chat product with a long shared system prompt?
- What does the hybrid lose relative to full attention on exact long-range retrieval, and how would you test it?

## Topic guides

- [KV cache](https://gurkanozkan.ai/learn/topics/kv-cache.md)
- [LLM inference: decoding, batching, quantisation and speculative decoding](https://gurkanozkan.ai/learn/topics/inference.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
