Anbeeld

Projects Articles Support Contact

KV Cache Precision Tail: Implementation and Benchmarks

Precise recent KV cache recovers low-bit cache fidelity, and KVarN delivers stronger precision at lower VRAM cost, as demonstrated on Qwen 3.6 27B.

  1. Why Keep Recent Tokens Exact
  2. What A Precision Tail Does
  3. How To Read The Results
  4. The Effect Of Tail Size
  5. Standard Quants Versus KVarN
  6. Practical Recommendations
  7. Qwen Performance And Implementation Status
  8. Why Gemma Is Harder
  9. What This Does Not Prove
  10. Method And Full Benchmark Data
    1. Qwen 3.6 27B Q5_K_S 64k
    2. Gemma 4 31B Q5_K_S 16k
    3. Decode Throughput By Context Depth

1. Why Keep Recent Tokens Exact

The earlier KVarN benchmark established a useful one-tier shift: KVarN4 approached ordinary q5 quality at roughly q4 memory, KVarN5 approached q6, and KVarN6 reached the q8 quality ceiling without paying for a q8 cache. This benchmark adds a second control over that tradeoff. Instead of quantizing every cached token, BeeLlama can keep the newest N tokens in BF16 or F16 and quantize only the older body.

That changes the practical question. A 64k context does not always need 64k tokens of full-precision KV. Many conversations and agent workloads need the full history to remain retrievable, but need the latest instructions, tool results, code, or document fragment to remain especially precise. A 1024-token tail targets that case directly: old context keeps the normal quantized-cache memory cost, while the newest 1024 rows remain exact.

On Qwen 3.6 27B, the effect is largest in the low-bit rows. The median Kullback-Leibler divergence (KLD) of q4_0 falls from 0.001846 to 0.001057 with a 1024 tail, a 42.7% reduction, while persistent KV grows from 1156.50 to 1252.50 MiB. At 64k, that is a 96 MiB tail instead of replacing the entire 4112 MiB BF16 cache. Lower-bit caches gain even more; higher-bit caches quickly reach a point where there is little error left for the tail to remove.

2. What A Precision Tail Does

The cache is divided conceptually into an exact recent region and an older quantized body. Attention still sees the whole valid context. The tail does not truncate old tokens, summarize them, or make long-context retrieval local-only. It changes the representation: the newest N K/V rows are read from an exact BF16/F16 store, while older rows are read from the selected standard quant or KVarN records, and the two attention results are combined under one softmax.

Qwen mean KLD plotted against persistent KV-cache size for standard and KVarN caches from two to four bits, with tails of 0, 1024, and 2048 tokens.
At two to four bits, mean KLD already shows the broad result: KVarN and exact tails recover fidelity without approaching BF16 cache size. Lower and farther left is better. Open the full-resolution graph.

Standard quantized caches use a BF16 tail by default in these runs. KVarN uses F16 because its native staging and record path is F16-based. In this article, exact means stored in an unquantized floating-point format; it does not mean that the standard and KVarN tails use the same format. At tail 0, KVarN keeps the currently incomplete part of its 128-token staging group exact, so the exact recent span varies from 0 to 127 rows as that group fills. The non-SWA layout also keeps a permanent exact sink group. A KVarN tail-0 row is therefore not physically identical to a standard cache with no exact rows; explicit 1024- and 2048-token settings provide a fixed exact recent region in addition to the record layout.

This distinction matters for real workloads. Retrieval from 20k or 50k tokens ago still depends on the selected quantizer, so a tail does not cure poor long-range fidelity. What it can do is preserve the latest 1k, 2k, or another user-selected span without multiplying the whole KV budget by two or three. A coding session might keep the current file and latest tool output exact; a document workflow might keep the latest source section exact while older references remain compressed. The tail size is therefore a workload control, not a universal constant.

The low-bit mean-KLD graph shows that basic effect before the finer statistical distinctions matter. At q2-q4, moving from tail 0 to 1024 shifts both standard and KVarN points sharply downward for a modest move to the right: less divergence for a relatively small increase in persistent KV memory.

3. How To Read The Results

The main metric in this article is median KLD, the typical per-token divergence from the matching full-BF16-cache baseline. Mean KLD remains in the full results and in the high-end comparison below, with 90th- and 99th-percentile KLD as additional checks. That is a change from my earlier KVarN article, where mean KLD carried more of the ranking.

The reason is visible in the new logs. Qwen's high-bit median is about 0.0009 and its 99th percentile about 0.019, but isolated maximum values reach 13-22. With roughly 131,000 scored positions, one KLD-20 token contributes about 0.00015 to the mean by itself. That is larger than several complete q5/q6/q8 differences in the chart. The mean is still a valid corpus average, but it is noisy because a few extreme positions can reorder otherwise similar high-bit caches.

Qwen median KLD plotted against persistent KV-cache size for standard and KVarN caches from four to eight bits, with tails of 0, 1024, and 2048 tokens.
The high-bit median graph makes the broad precision progression visible, then shows the more useful result: q6/q8 and KVarN6/KVarN8 converge on the same practical KLD floor. Lower and farther left is better. Open the full-resolution graph.

The KLD +/- field needs a careful reading. llama-perplexity calculates it from the distribution of per-token KLD values in one run. It is not run-to-run variation and not a paired confidence interval between two cache configurations. It quantifies how much the token-level values vary inside that corpus, which is useful context, but overlapping values do not prove that two configurations are statistically tied.

Median KLD is therefore the clearest main signal for relative cache and tail quality: it is stable enough here to show the expected low-bit improvements and high-bit saturation. Mean KLD answers a different, still useful question—the average divergence across all scored tokens—but a handful of extreme positions can move it more than the entire difference between q5, q6, and q8. The p90 and p99 values show whether the typical result extends into the worse parts of the distribution. At p99.9 and maximum KLD, the benchmark is primarily describing rare-event behavior.

High-bit Qwen KLD distribution at tail 2048
Qwen cache, tail 2048Median KLDMean KLDKLD +/-90% KLD99% KLD
q5_00.0009280.0025680.0001620.0043620.019983
q6_00.0009040.0026050.0001780.0042550.019133
q8_00.0008950.0026440.0002100.0042280.019229
kvarn50.0008920.0024740.0001700.0041910.019269
kvarn60.0008760.0025240.0001730.0041540.019227
kvarn80.0008770.0025920.0002050.0041120.018998

Read the last three KVarN rows as saturation, not as proof that five bits are intrinsically more precise than eight. Median, p90 and p99 put KVarN6 and KVarN8 at effectively the same ceiling, while the outlier-sensitive mean changes their order. The standard rows tell the same story: q8 has the best median, q6 has a fractionally better p99, and neither advantage is large enough to matter as much as VRAM or speed.

4. The Effect Of Tail Size

Qwen gives a clean low-bit tail curve. More bits improve median KLD across the standard-cache rows, and larger tails improve every standard cache. KVarN follows the same pattern until the high-bit results reach a plateau. The more aggressive the body quantization, the more useful it is to keep the newest rows out of that body.

Qwen median KLD plotted against persistent KV-cache size for standard and KVarN caches from two to four bits, with tails of 0, 1024, and 2048 tokens.
The median makes the low-bit tail curve clear: 1024 exact tokens produce the largest step, while 2048 adds a smaller gain. KVarN remains below the matching standard quant at each bit width. Lower is better. Open the full-resolution graph.

KVarN8's 0.7% increase from tail 1024 to 2048 is six millionths of KLD, inside the same high-bit plateau seen elsewhere. It does not establish that a larger exact tail damages an 8-bit cache. It establishes that this benchmark cannot rank changes that small reliably from a single corpus run.

The default recommendation is straightforward: start with a 1024-token tail. It captures most of the KLD benefit, costs 48 MiB on Qwen KVarN or 96 MiB on the standard caches tested here, and usually reduces throughput by only a few percent. A 2048 tail is easier to justify with q2/q3, where the second 1024 tokens still produce a visible precision gain, or when the workload itself needs roughly 2k recent tokens protected. At q5 and above, Wikitext KLD has mostly saturated after 1024.

Qwen median KLD by tail size
Cache typeTail 0 medianTail 1024 medianTail 2048 median0 to 10241024 to 2048
q2_00.0193740.0046480.003696-76.0%-20.5%
q3_00.0046960.0015510.001382-67.0%-10.9%
q4_00.0018460.0010570.001019-42.7%-3.6%
q5_00.0011540.0009380.000928-18.7%-1.1%
q6_00.0009600.0009080.000904-5.4%-0.4%
q8_00.0009090.0008970.000895-1.3%-0.2%
kvarn20.0071080.0038110.002820-46.4%-26.0%
kvarn30.0017970.0013160.001158-26.8%-12.0%
kvarn40.0011110.0009940.000952-10.5%-4.2%
kvarn50.0009270.0008970.000892-3.2%-0.6%
kvarn60.0008890.0008790.000876-1.1%-0.3%
kvarn80.0008710.0008710.0008770.0%+0.7%

This is of course just a benchmark result, not a universal limit. KLD evaluates one fixed teacher-forced Wikitext scenario in prefill-sized batches. A support agent that must preserve the latest long customer message, or a coding agent carrying a 3k-token source file, may benefit from a 2048 or 4096 tail even when this aggregate KLD barely moves. Larger sizes are available so the user can match the exact region to the workload. But the cost grows with the tail, and the Qwen measurements show the expected few-percent throughput loss, so there is no reason to allocate a larger exact region without a use case for it.

5. Standard Quants Versus KVarN

At tail 0, KVarN beats the corresponding standard cache at every tested bit width on Qwen median KLD. The KVarN allocation is about 32 MiB larger because its structured records and exact staging region carry fixed overhead, but the precision gain is large at 2-4 bits and gradually shrinks as both families approach the high-bit floor.

Same-bit Qwen standard and KVarN caches at tail 0
BitsStandard cacheStandard MiBStandard medianKVarN MiBKVarN medianMedian reduction
2q2_0642.500.019374674.380.00710863.3%
3q3_0899.500.004696931.380.00179761.7%
4q4_01156.500.0018461188.380.00111139.8%
5q5_01413.500.0011541445.380.00092719.7%
6q6_01670.500.0009601702.380.0008897.4%
8q8_02184.500.0009092216.380.0008714.2%

The more useful comparison is precision per VRAM. KVarN4 at 1188.38 MiB slightly beats q5_0 at 1413.50 MiB on median KLD. KVarN5 at 1445.38 MiB beats q6_0 at 1670.50 MiB. KVarN6 at 1702.38 MiB slightly beats q8_0 at 2184.50 MiB. This reproduces the recommendation ladder from the previous KVarN article with a cleaner typical-token metric.

Qwen KVarN precision-per-VRAM ladder at tail 0
Qwen tail-0 KVarN tierMiBMedian KLDComparable standard tierMiBMedian KLD
kvarn41188.380.001111q5_01413.500.001154
kvarn51445.380.000927q6_01670.500.000960
kvarn61702.380.000889q8_02184.500.000909

This is not a renamed standard quantizer. BeeLlama keeps KVarN in a separate structured cache backend with 128-token records, Hadamard rotation, iterative variance normalization, dedicated scale metadata, F16 staging, custom CUDA store kernels, and native KVarN FlashAttention dispatch. Supporting it means integrating allocation, cache updates, attention, rollback, save/restore, and architecture-specific cache layouts. The current implementation targets Qwen 3.6 and Gemma 4 rather than claiming universal model support; broader architecture coverage will need explicit work in future versions.

6. Practical Recommendations

For Qwen, these symmetric results can be combined with the earlier asymmetric recommendation ladders. They do not replace those ladders because K/V pairs such as 5/4 and 6/5 were not retested with tails here, but they make the main decision points clearer.

Recommended Qwen starting points from the symmetric-cache results
GoalQwen starting pointKV MiBMedian KLDWhy
Efficient high fidelitykvarn6 + tail 10241750.380.000879At the q8 median ceiling with much less VRAM
Balancedkvarn5 + tail 10241493.380.000897High-end median at 36.3% of BF16 KV
Valuekvarn4 + tail 10241236.380.000994Near-q5 typical quality around q4 memory
Compactkvarn3 + tail 1024979.380.001316Strong step below the q4 memory tier
Aggressive 2-bitkvarn2 + tail 2048786.380.002820Tail rescues much of the typical-token 2-bit loss
Standard-only valueq4_0 + tail 10241252.500.001057Simple standard path with a large tail gain

KVarN8 is mainly a ceiling check. Its median is excellent, but KVarN6 is already at the same practical KLD level for 514 MiB less at tail 1024. The same logic applies to ordinary q8_0 versus q6_0: if VRAM matters, the tiny high-end median difference is hard to justify. If compatibility or maximum conservatism matters more than memory, q5_0/q6_0 with a 1024 tail remain sensible standard-cache choices.

Asymmetric pairs may improve several of these rows. Earlier work found that keeping K one step above V often produced a better allocation, but this article does not assume the old ranking automatically survives the new tail path. That is the next benchmark rather than a claim hidden inside this one.

7. Qwen Performance And Implementation Status

The v0.3.2 preview established KVarN's precision but used a raw integration whose speed numbers were not ready to recommend. The current Qwen path is materially different: dedicated CUDA FlashAttention kernels consume KVarN records directly, and exact-tail attention has kernel coverage for various geometries.

On the tested Qwen 3.6 27B, RTX 3090, and CUDA configuration, the benchmark behavior now looks like a usable optimization rather than a precision-only prototype. Standard Qwen prefill stays around 856-884 tok/s across the tested q4 tail sizes. KVarN4 prefill is slower at 808-821 tok/s, but decode at 64k is competitive: 25.30 tok/s at tail 0 versus 24.63 for q4_0, and 25.00 versus 24.10 at tail 1024. Larger tails carry the expected cost rather than causing a collapse.

Qwen q4 prefill and 64k decode performance
Qwen cacheTailPrefill tok/s64k decode tok/sKV MiB
q4_00884.2224.631156.50
q4_01024865.5024.101252.50
q4_02048856.4723.581316.50
kvarn40820.9525.301188.38
kvarn41024814.2925.001236.38
kvarn42048808.3124.331300.38

The prefill and decode measurements come from different benchmark builds, so the two tok/s columns should not be compared to each other. Within each column, however, they show the intended pattern. A 1024 tail costs about 0.8-2.2% on these q4 rows; a 2048 tail costs about 1.5-4.3%. That is a real performance price, but a controlled one.

8. Why Gemma Is Harder

Gemma 4 uses a materially different cache layout from Qwen. The tested 31B model has 60 cache-bearing attention layers: 50 use a 1024-token interleaved sliding-window-attention (iSWA) ring and 10 use full attention. With n_swa=1024 and ub=512, BeeLlama (and upstream llama.cpp) allocates a 1536-row physical SWA ring so the 1024 visible rows and in-flight ubatch rows can coexist safely.

A requested 1024 tail therefore covers the complete visible SWA window. For standard caches, BeeLlama promotes that entire 50-layer ring to BF16 instead of keeping a quantized body plus an equally large overlay. For KVarN it uses a full F16 SWA ring. This is why the VRAM numbers jump toward the same point regardless of the original bit width: q4_0 grows from 703.12 to 1685.62 MiB, while KVarN4 moves from 1563.59 to 1695.47 MiB. At KVarN8, replacing the records and staging allocation with the plain F16 ring is actually smaller, so the total falls from 2188.59 to 2020.47 MiB.

That behavior is correct for the current representation, but it largely erases the memory ladder that makes KVarN plus a tail attractive on Qwen. It also makes performance inconsistent. Gemma KVarN4 prefill is 692.34 tok/s at tail 0 and 738.67 with the exact SWA ring, well below the 898.58 tok/s standard q4_0 tail-1024 run. I do not recommend KVarN or precision tails for Gemma 4 as a general optimization in this version.

Selected Gemma precision, memory, and prefill results
Gemma cacheTail 0 MiBTail 0 medianTail 1024 MiBTail 1024 medianPrefill tok/s, tail 1024
q4_0703.120.1340911685.620.045341898.58
kvarn41563.590.0581851695.470.037166738.67
q6_01015.620.0426361848.120.037500898.21
kvarn61876.090.0365281857.970.035381737.68
q8_01328.120.0371002010.620.036159898.18
kvarn82188.590.0356822020.470.035390735.44

Tail 1024 is the only obvious Gemma preset to test first because it matches the SWA visibility window exactly. Larger requested tails cannot make those 50 SWA layers see more than 1024 tokens; they can only extend the tail on the 10 full-attention layers. That may help a specialized workload, but it no longer has the simple Qwen cost/benefit curve.

The precision results are still valuable as an independent check. Gemma's standard-cache medians improve with bit width, KVarN beats the matching standard quant, and a 1024 tail strongly rescues q2-q4. KVarN6 and KVarN8 with tail 1024 are effectively tied rather than strictly ordered. For example, q4_0 falls from 0.134091 to 0.045341 median KLD, while KVarN4 falls from 0.058185 to 0.037166. The quality mechanism works; the current SWA storage and kernel economics do not yet make it a good general recommendation. I will continue looking for a representation that keeps the exact visible ring without losing most of the VRAM and throughput advantage in future BeeLlama versions.

9. What This Does Not Prove

KLD is a sensitive distribution-fidelity benchmark, not a 1:1 simulation of generation. It teacher-forces Wikitext tokens and evaluates prompt-sized batches against stored BF16-cache baseline logits. Real generation normally adds one token at a time, sampling can make two runs diverge after the first changed choice, and user-visible quality depends on what those choices mean. These tables establish local cache fidelity and expose large regressions; they do not replace retrieval tests, reasoning tasks, coding workloads, or human evaluation.

The high-bit mean graph has a second limitation. Its q5-q8 points are close enough that a few extreme token positions can change their order, so it is not a reliable picture of the underlying precision ladder. In particular, q8 sharing or exceeding q6's mean KLD, and some tail-2048 points moving upward, should be read as outlier sensitivity in this run rather than evidence that more bits or more exact rows reduce general cache fidelity.

Qwen mean KLD plotted against persistent KV-cache size for standard and KVarN caches from four to eight bits, with tails of 0, 1024, and 2048 tokens.
Above four bits, mean KLD becomes non-monotonic because rare high-divergence tokens can outweigh the small differences between otherwise similar caches. This graph illustrates the limitation of the mean. Open the full-resolution graph.

The exact tail also does not make the full context exact. A fact retrieved from the quantized body is still subject to the selected cache format. The tail is useful when a workload has a privileged recent region, and its value will vary with attention patterns, prompt structure, and the amount of recent material that must remain precise. The Wikitext result places the broad efficiency knee at 1024 tokens on Qwen; other workloads may put it elsewhere.

Finally, this is not the complete precision-per-VRAM ladder. The symmetric rows make the tail and KVarN effects easy to see, but asymmetric K/V pairs may offer better final presets. Model support is also not exhaustive because KVarN is a separate structured cache implementation with custom kernels, not a generic extension automatically inherited by every llama.cpp architecture. The Qwen results demonstrate that the design works on this non-SWA cache layout. Gemma shows why each new cache layout still needs its own engineering and validation.

10. Method And Full Benchmark Data

The compact tables above carry the analysis. The complete KLD, percentile, VRAM, same-top-p, prefill, and decode results follow for reproducibility and for readers who want a different tradeoff than the recommendations.

The KLD and prefill runs used BeeLlama v0.4.0 commit 41d41b0ce5 on one power limited RTX 3090 (24 GB). The corpus was wiki.test.raw from Wikitext-2 raw. The seed was fixed to 1. Every candidate was compared with a baseline generated by the same executable, model, corpus, context, -b 2048, and -ub 512. The baseline used BF16 K and V and llama.cpp's standard v1 KLD-baseline format.

The candidate command followed this template; MODEL, CONTEXT, CACHE, BASELINE, and TAIL identify the row:

llama-perplexity -m MODEL.gguf -ngl all -b 2048 -ub 512 \
  --ctx-size CONTEXT --cache-type-k CACHE --cache-type-v CACHE \
  --flash-attn on --seed 1 --no-mmap --mlock --no-host --kv-unified \
  -f wiki.test.raw --kl-divergence-base BASELINE.kld --kl-divergence \
  --kv-tail-tokens TAIL

The baseline used the same template with bf16 K/V, tail 0, and without --kl-divergence, causing llama-perplexity to write the reference logits. The percentage columns labelled exp(-ΔKLD) are derived similarity proxies, not task accuracy or a probability that the quantized cache is correct. KLD +/- is the standard error calculated over per-token KLD values within a run; it is not repeat-run variance.

10.1 Qwen 3.6 27B Q5_K_S 64k

Each row uses the symmetric K/V cache type and tail size shown. The default tail representation is bf16 for standard quantized caches and f16 for KVarN; the bf16 cache appears at tail 0 only. Tok/s is prompt-processing throughput from the same runs. KV cache (MiB) is persistent KV VRAM from llama-bench --kv-memory on the same BeeLlama CUDA build; tail rows show combined (tail-0 base + tail delta).

Complete Qwen 3.6 27B 64k KLD, memory, and prefill results
CacheTailKV cache (MiB)Size vs bf16Median KLDMean KLDKLD +/-90% KLD95% KLD99% KLD99.9% KLDMean exp(-ΔKLD)99.9% exp(-ΔKLD)Maximum KLDSame top pTok/sElapsed (s)
bf1604112.00100.0%0.0000000.0000000.0000000.0000160.0000230.0000370.000050100.00%100.00%0.00006599.995% +/- 0.002%883.40334.83
q8_002184.5053.1%0.0009090.0027540.0002470.0042620.0067750.0199070.09302999.72%91.12%22.25903997.930% +/- 0.039%884.17334.69
q8_010242280.50 (2184.50 + 96.00)55.5%0.0008970.0027180.0002350.0042190.0066650.0195250.08769999.73%91.60%16.63963997.936% +/- 0.039%865.98340.90
q8_020482344.50 (2184.50 + 160.00)57.0%0.0008950.0026440.0002100.0042280.0066280.0192290.08711399.74%91.66%17.80119397.998% +/- 0.039%856.80344.38
kvarn802216.3853.9%0.0008710.0024720.0001600.0040990.0064770.0184420.08865299.75%91.52%11.74124698.039% +/- 0.038%814.87360.15
kvarn810242264.38 (2216.38 + 48.00)55.1%0.0008710.0024010.0001800.0041050.0064140.0187720.08763999.76%91.61%17.57006598.036% +/- 0.038%810.24362.09
kvarn820482328.38 (2216.38 + 112.00)56.6%0.0008770.0025920.0002050.0041120.0065140.0189980.08885799.74%91.50%14.82525398.026% +/- 0.038%802.13365.24
q6_001670.5040.6%0.0009600.0027710.0002280.0044620.0070870.0201300.09113499.72%91.29%20.71210797.906% +/- 0.040%882.67335.12
q6_010241766.50 (1670.50 + 96.00)43.0%0.0009080.0026930.0002290.0042720.0066790.0192390.08519799.73%91.83%19.61150097.970% +/- 0.039%863.53341.85
q6_020481830.50 (1670.50 + 160.00)44.5%0.0009040.0026050.0001780.0042550.0067330.0191330.08987299.74%91.40%14.91594597.929% +/- 0.039%854.91344.70
kvarn601702.3841.4%0.0008890.0026880.0002160.0041770.0065600.0190390.08899399.73%91.49%15.31993698.034% +/- 0.038%817.80359.07
kvarn610241750.38 (1702.38 + 48.00)42.6%0.0008790.0024400.0001930.0040990.0064820.0189720.08462999.76%91.89%17.96243598.020% +/- 0.038%812.54360.92
kvarn620481814.38 (1702.38 + 112.00)44.1%0.0008760.0025240.0001730.0041540.0065020.0192270.08602799.75%91.76%13.38409898.010% +/- 0.039%805.21364.04
q5_001413.5034.4%0.0011540.0032690.0002410.0053670.0083460.0234670.09707099.67%90.75%20.07867897.755% +/- 0.041%882.32335.37
q5_010241509.50 (1413.50 + 96.00)36.7%0.0009380.0027150.0002030.0044020.0069710.0202750.08813299.73%91.56%17.62565497.968% +/- 0.039%863.69341.67
q5_020481573.50 (1413.50 + 160.00)38.3%0.0009280.0025680.0001620.0043620.0068770.0199830.08966899.74%91.42%13.54478597.940% +/- 0.039%855.29344.75
kvarn501445.3835.2%0.0009270.0027290.0002200.0043960.0069680.0202410.08653799.73%91.71%17.65052697.941% +/- 0.039%819.95357.95
kvarn510241493.38 (1445.38 + 48.00)36.3%0.0008970.0028510.0002590.0042400.0067300.0192420.08766699.72%91.61%20.33749098.009% +/- 0.039%814.13360.62
kvarn520481557.38 (1445.38 + 112.00)37.9%0.0008920.0024740.0001700.0041910.0066020.0192690.08807499.75%91.57%15.33561198.010% +/- 0.039%808.51362.70
q4_001156.5028.1%0.0018460.0046730.0002310.0084830.0129580.0345320.15440899.53%85.69%20.69981097.199% +/- 0.046%884.22334.64
q4_010241252.50 (1156.50 + 96.00)30.5%0.0010570.0028810.0001430.0051010.0080560.0231550.10448699.71%90.08%11.47137497.861% +/- 0.040%865.50341.06
q4_020481316.50 (1156.50 + 160.00)32.0%0.0010190.0028820.0001820.0048750.0077180.0220270.09249999.71%91.17%13.58936797.861% +/- 0.040%856.47344.23
kvarn401188.3828.9%0.0011110.0032440.0002460.0054240.0085680.0239390.11278199.68%89.33%21.76760797.771% +/- 0.041%820.95357.72
kvarn410241236.38 (1188.38 + 48.00)30.1%0.0009940.0030590.0002730.0047510.0075580.0215710.09039199.69%91.36%19.71802997.878% +/- 0.040%814.29360.28
kvarn420481300.38 (1188.38 + 112.00)31.6%0.0009520.0027330.0001840.0045340.0072090.0210610.09727099.73%90.73%15.36698097.871% +/- 0.040%808.31363.04
q3_00899.5021.9%0.0046960.0110040.0003580.0218180.0331810.0814590.30418698.91%73.77%22.70572395.605% +/- 0.057%883.98334.80
q3_01024995.50 (899.50 + 96.00)24.2%0.0015510.0047000.0002920.0082170.0131940.0363160.16738699.53%84.59%20.20378997.305% +/- 0.045%865.27341.35
q3_020481059.50 (899.50 + 160.00)25.8%0.0013820.0041170.0002800.0071930.0114640.0313560.13524999.59%87.35%28.13641997.544% +/- 0.043%856.53344.24
kvarn30931.3822.7%0.0017970.0054340.0002730.0100390.0161110.0435500.18025499.46%83.51%20.40145997.050% +/- 0.047%821.71357.45
kvarn31024979.38 (931.38 + 48.00)23.8%0.0013160.0039780.0002060.0070840.0114600.0314180.13955899.60%86.97%15.25178997.472% +/- 0.043%814.71360.21
kvarn320481043.38 (931.38 + 112.00)25.4%0.0011580.0034830.0001770.0060780.0097780.0272410.13260599.65%87.58%13.85255997.656% +/- 0.042%810.03361.86
q2_00642.5015.6%0.0193740.0421070.0005890.0904400.1364940.3170801.19890295.88%30.15%25.11748191.176% +/- 0.078%887.60333.60
q2_01024738.50 (642.50 + 96.00)18.0%0.0046480.0155110.0003900.0318960.0539000.1513910.56371398.46%56.91%25.55878495.065% +/- 0.060%868.46340.21
q2_02048802.50 (642.50 + 160.00)19.5%0.0036960.0129200.0004190.0242130.0418820.1228220.53996798.72%58.28%24.47283795.620% +/- 0.057%859.53343.22
kvarn20674.3816.4%0.0071080.0208490.0003880.0455610.0723730.1806870.69359797.94%49.98%21.17305094.234% +/- 0.064%824.87355.97
kvarn21024722.38 (674.38 + 48.00)17.6%0.0038110.0130400.0004010.0267070.0433820.1152580.45049698.70%63.73%24.74597495.608% +/- 0.057%816.70359.48
kvarn22048786.38 (674.38 + 112.00)19.1%0.0028200.0097500.0003050.0197240.0332020.0900670.34790699.03%70.62%25.21200896.214% +/- 0.053%810.33362.18

10.2 Gemma 4 31B Q5_K_S 16k

Gemma's iSWA layers cap the visible precision tail at n_swa=1024, so a requested 2048 tail resolves to 1024 on those layers and only tail 0 and 1024 are shown. The default tail representation is bf16 for standard caches and f16 for KVarN; the bf16 cache appears at tail 0 only. Tok/s is prefill throughput; KV cache (MiB) is persistent KV VRAM from llama-bench --kv-memory, with tail rows shown as combined (tail-0 base + tail delta).

Complete Gemma 4 31B 16k KLD, memory, and prefill results
CacheTailKV cache (MiB)Size vs bf16Median KLDMean KLDKLD +/-90% KLD95% KLD99% KLD99.9% KLDMean exp(-ΔKLD)90% exp(-ΔKLD)Maximum KLDSame top pTok/sElapsed (s)
bf1602500.00100.0%0.0000000.0000000.0000000.0000070.0000130.0000290.000047100.00%100.00%0.00006399.995% +/- 0.002%945.15406.90
q8_001328.1253.1%0.0371000.4559880.0037821.0653462.3406817.32269416.81392963.38%34.46%34.11612780.445% +/- 0.103%928.84354.40
q8_010242010.62 (1328.12 + 682.50)80.4%0.0361590.4487170.0037901.0467292.2671847.25552416.82499963.84%35.11%35.13803980.635% +/- 0.103%898.18423.19
kvarn802188.5987.5%0.0356820.4364570.0037111.0044782.2179237.06682316.55668664.63%36.62%42.16725280.779% +/- 0.103%657.17543.61
kvarn810242020.47 (2188.59 − 168.12)80.8%0.0353900.4407200.0037051.0160392.2459977.18110316.31069664.36%36.20%35.16386480.629% +/- 0.103%735.44495.73
q6_001015.6240.6%0.0426360.5062650.0040371.2349862.6089247.88078217.30599060.27%29.08%34.82060279.496% +/- 0.105%925.47413.22
q6_010241848.12 (1015.62 + 832.50)73.9%0.0375000.4552120.0037741.0733802.3112967.26298016.39249463.43%34.19%34.16420480.337% +/- 0.104%898.21422.93
kvarn601876.0975.0%0.0365280.4524310.0037671.0572522.3199347.19800816.54286063.61%34.74%37.14139280.560% +/- 0.103%674.57531.93
kvarn610241857.97 (1876.09 − 18.12)74.3%0.0353810.4413190.0037231.0112522.2490537.27242816.38921064.32%36.38%40.91284280.734% +/- 0.103%737.68494.92
q5_00859.3834.4%0.0617470.6263470.0046211.6104243.2394719.08410118.73164753.45%19.98%36.82685976.802% +/- 0.110%928.36412.33
q5_010241766.88 (859.38 + 907.50)70.7%0.0385690.4699980.0038871.1054672.4068737.54249916.97893762.50%33.11%39.99062779.989% +/- 0.104%898.15422.94
kvarn501719.8468.8%0.0412620.4830870.0038961.1521292.4773637.59482516.60036361.69%31.60%33.92879979.609% +/- 0.105%681.90527.72
kvarn510241776.72 (1719.84 + 56.88)71.1%0.0362610.4442010.0037441.0182572.2635037.32512516.38131364.13%36.12%38.84048880.622% +/- 0.103%739.05494.58
q4_00703.1228.1%0.1340910.9016540.0055452.5062184.58185110.90931620.44223440.59%8.16%34.09912571.347% +/- 0.118%933.86410.37
q4_010241685.62 (703.12 + 982.50)67.4%0.0453410.5330800.0041061.3221232.8158787.95960617.26155558.68%26.66%40.72185578.833% +/- 0.106%898.58423.33
kvarn401563.5962.5%0.0581850.6029120.0044571.5514303.1389058.61516417.85656754.72%21.19%36.17074277.281% +/- 0.109%692.34520.61
kvarn410241695.47 (1563.59 + 131.88)67.8%0.0371660.4606370.0038231.0749922.3650787.43443916.56862463.09%34.13%37.09007680.385% +/- 0.103%738.67494.02
q3_00546.8821.9%0.5040751.6232580.0073184.6278617.14323613.66795923.15744019.73%0.98%40.13804661.353% +/- 0.127%929.79412.10
q3_010241604.38 (546.88 + 1057.50)64.2%0.1055450.8227000.0053082.2765684.27430710.49342119.81056843.92%10.26%36.65496472.851% +/- 0.116%899.01422.42
kvarn301407.3456.3%0.2504451.0505180.0056752.8902644.90785211.20455620.02510334.98%5.56%37.64443267.647% +/- 0.122%699.84516.17
kvarn310241614.22 (1407.34 + 206.88)64.6%0.0441920.5376320.0041811.3286772.8513818.19908517.03215458.41%26.48%37.53318878.876% +/- 0.106%738.54494.26
q2_00390.6215.6%2.9575804.1679100.0112649.85496313.00825619.66532527.8349611.55%0.01%40.67254631.667% +/- 0.121%933.80410.56
q2_010241523.12 (390.62 + 1132.50)60.9%0.3831171.4205910.0067854.0485046.49310712.94620621.76851524.16%1.74%45.30615661.591% +/- 0.127%900.32421.94
kvarn201251.0950.0%2.0916973.0676900.0089417.2217049.81379816.24517623.6452144.65%0.07%39.49303440.932% +/- 0.128%704.09513.62
kvarn210241532.97 (1251.09 + 281.88)61.3%0.1919891.0079260.0057612.7937214.90528511.47501819.76525536.50%6.12%35.40013168.674% +/- 0.121%740.28493.21

10.3 Decode Throughput By Context Depth

Decode (token generation) throughput comes from separate decode benchmark runs with BeeLlama build 44ac8f800 on one power limited RTX 3090. Each cell is average tokens per second over 128 generated tokens and five repetitions from llama-bench at the given context depth, with -b 2048 -ub 512 and symmetric K/V. Tail representation is bf16 for q4_0 and f16 for KVarN; bf16 is measured at tail 0 only. Gemma was measured through 16k and Qwen through 64k.

Decode throughput by model, cache, tail, and context depth
ModelCacheTail10244096163843276865536
Qwen 3.6 27Bbf16036.1534.8830.9526.9321.50
Qwen 3.6 27Bq4_0036.4035.4932.6329.4624.63
Qwen 3.6 27Bq4_0102434.3834.0131.5128.5724.10
Qwen 3.6 27Bq4_0204834.1832.3130.1427.8323.58
Qwen 3.6 27Bkvarn4032.8132.0930.4228.5225.30
Qwen 3.6 27Bkvarn4102432.1831.7030.0628.1425.00
Qwen 3.6 27Bkvarn4204832.0530.2428.8527.3224.33
Gemma 4 31Bbf16028.3827.2323.76
Gemma 4 31Bq4_0030.9330.1626.90
Gemma 4 31Bq4_0102426.6426.2524.03
Gemma 4 31Bq4_0204826.4625.6723.55
Gemma 4 31Bkvarn4021.3820.7520.13
Gemma 4 31Bkvarn4102428.5828.0026.36
Gemma 4 31Bkvarn4204828.6127.5926.03