Repository navigation
Description
Summary
When the KV pool fills, requests that resume from the prefix cache start failing with prepared model reported device error 6. The cause is stale snapshot bytes in reused KV pages:
- Snapshot rows borrow KV page bytes (
runtime_package/cache_memory.rs). - When the last owner releases a snapshot,
release_snapshotreturns its pages to the free list. Nothing clears the row bytes still in them. - A request then receives one of those pages as its partly filled tail page. Positions past the request's last token keep the old row bytes, and in the KV format some of them decode as NaN.
- Attention masks those positions, but a masked position still contributes
0 × NaN = NaNto P·V. The target logits come out non-finite. PreparedStochasticVerificationmarks the row invalid, and the commit reportsINVALID_SPECULATION(6).
It only shows up once pages cycle between snapshot rows and KV use, which is why it needs a full pool. That makes it hit long multi-turn and agent workloads, the ones the prefix cache is for.
This may also explain #61. That issue fails the same way (verification rejects the row, then the commit reports INVALID_SPECULATION), and its failing target column sits in a newly granted page. We haven't tested Gemma 4.
Environment
- DGX Spark (GB10, SM121), single GPU, CUDA 13.0
nvidia/Qwen3.8-27B-NVFP4, exported with theqwen38_denserecipe defaults: 32 requests, MTP up to 5 drafts, FP8 KV- Flare
ca1f960eplus the scratch-copy fix from 317c1ec. The code involved is unchanged onmain(6256cf08). flare run PACKAGE --gpus 0with default flags (adaptive MTP verification on)
Reproduction
The repro runs on a fresh server. It sends alternating distinct ~16k- and ~32k-token prompts. Each prompt is sent once with max_tokens=1 to cache it, then again with max_tokens=64. Requests run one at a time. We used the low-entropy prompts from SPEED-Bench's throughput split.
| Server | First failure |
|---|---|
--memory-limit 50G (3,760 KV pages, 101 snapshot slots) |
prompt 15–17, every run, about 5 minutes in |
| Default memory | prompt 67, nine prompts after the pool first filled |
The failing request is always the second (cached) send. Under --memory-limit 50G, the 101 snapshot slots' alias ranges overlap and together cover every KV page.
Repro script
"""Feed a fresh Flare server distinct long prompts (prime with 1 token, then resend with 64) until the first failure.
Usage: repro.py OUT.csv DATA_DIR (DATA_DIR holds SPEED-Bench throughput_16k.jsonl / throughput_32k.jsonl)"""
import csv, json, re, sys, time, urllib.error, urllib.request
out, data = sys.argv[1], sys.argv[2]
prompts = [[(ctx, r["messages"]) for r in map(json.loads, open(f"{data}/throughput_{ctx}.jsonl"))
if r["category"] == "low_entropy"] for ctx in ("16k", "32k")]
order = [p for pair in zip(*prompts) for p in pair]
KEYS = ("flare_free_kv_tokens", "flare_cached_kv_tokens", "flare_free_snapshots", "flare_requests_failed_total")
def metrics():
text = urllib.request.urlopen("http://127.0.0.1:8000/metrics", timeout=10).read().decode()
return {k: float(m.group(1)) for k in KEYS for m in [re.search(rf"^{k} (\S+)$", text, re.M)] if m}
def ask(messages, max_tokens):
body = {"model": "Qwen3.8-27B", "messages": messages, "max_tokens": max_tokens, "temperature": 1.0}
req = urllib.request.Request("http://127.0.0.1:8000/v1/chat/completions", json.dumps(body).encode(),
{"Content-Type": "application/json"})
try:
urllib.request.urlopen(req, timeout=900).read()
return "ok"
except urllib.error.HTTPError as e:
return "fail: " + e.read().decode()[:120]
with open(out, "w", newline="") as f:
w = csv.writer(f)
w.writerow(["i", "context", "prime", "warm", "seconds", *KEYS])
for i, (ctx, messages) in enumerate(order):
t = time.time()
prime, warm = ask(messages, 1), ask(messages, 64)
m = metrics()
w.writerow([i, ctx, prime, warm, round(time.time() - t, 1), *[m.get(k) for k in KEYS]]); f.flush()
print(i, ctx, prime[:40], warm[:40], m, flush=True)
if prime != "ok" or warm != "ok":
breakNarrowing
We collected these with temporary logging in Helios and a re-exported package. None of the logging is part of this issue.
Which check fails. We made the commit report a bitmask of its shape checks in place of a bare 6. The failing round reports proposed >= 1 and accepted == proposed - 1 as failed. Verification set proposed_count = 0, so it rejected the row (speculation.py L329, L355). The first round after the restore already fails at width 1, with no drafts. That leaves the target distribution as the cause: it is non-finite, and the drafts play no part.
What we ruled out.
- Page ownership. Before every submit we checked that each page id has exactly one owner: free list, checkpoint, retirement, request, retired request, inbound ticket or snapshot alias. There were no conflicts.
- Reuse while in flight. We tracked, per page, the last fence that used it as KV and as snapshot backing. No page was used in one role while work in the other role was still in flight.
- Alias range rounding. Widening every alias range by 8 pages on each side still fails.
- Snapshot exhaustion. Free snapshots stayed above 60 throughout.
- The row index. See the dedicated-pages rows in the table below.
What fixes it.
--memory-limit 50G, default MTP |
Result |
|---|---|
| As is | fails at prompt 15–17 |
| Snapshots 0–47 on dedicated pages, never handed to KV | no failures through the 25-minute cap (89 prompts) |
| Snapshots 53–100 on dedicated pages | no failures through the 25-minute cap (87 prompts) |
| Released alias pages zeroed before reuse | no failures in 143 of 143 prompts. Default memory also passes 143 of 143, where it failed at prompt 67 before |
With zeroing on, warm-request latency and benchmark throughput are unchanged. At 8k, N=1 to 32: 27.6 / 50.4 / 93.0 / 159 / 242 / 305 tok/s, against 28.2 / 49.0 / 92.8 / 154 / 244 / 308 tok/s without it.
Why only the tail page matters. _copy_pages (state_transfer.py L153) saves and restores the request's whole tail page, including positions past the endpoint. Startup zeroes every cache byte once (runtime_package/cache_memory.rs L478, "before any graph or transfer can read an alias"). After that, nothing clears a page when it goes from row storage back to the KV pool (scheduler/cache_memory.rs L153–165).
Potential fix
These are three options. The first is the one we tested.
- Zero pages leaving alias use. When
release_snapshotdrops a page's alias count to zero, queue the page. The executor then zeroes it on the model stream before the next graph launch, so the clear happens after the snapshot's last reader and before any KV writer. A single-GPU version of this is on a fork branch: shadowpa0327/flare-local-inference@b83d347a. It uses a global page list and host-to-device copies from pinned zeros, and doesn't cover the multi-process tensor-parallel executor. Treat it as a reference, not a proposed patch. - Clear only the dead tail. When a page is granted to a request, or a tail page is restored, zero the positions past the endpoint. This moves less data than option 1, but every writer of a partial page has to honor it.
- Make masked positions inert in attention. Skip or zero masked K/V positions in the paged kernels, instead of relying on
0 × valuestaying finite. This also protects any other path that leaves undefined bytes in a page.
Separately, as #61 also notes, a row the verifier rejects reaches the commit as INVALID_SPECULATION. Reporting it as INVALID_DISTRIBUTION would have pointed at the cause much sooner. The state-transfer validator also uses 6, for an unmapped page, which sent us looking at page tables first.
Found and written up with Claude Code (Claude Opus 5.5) while benchmarking Flare on DGX Spark.
Activity
fahrenhe1t commentedon Nov 3, 2026
Second data point: Qwen3.8-27B NVFP4 + DFlash2 on SM120 (RTX PRO 6000 Blackwell), agentic traffic
Same signature as this issue, on a different GPU class and with the DFlash2 speculative path. Filing as a data point per the issue's request for more reproductions.
Environment
cc696a6b(2026-11-02, currentmain), release buildlocal-inference-lab/flashinfer@f5f5341(as locked in the repo at that commit)qwen38_dense, DFlash2 draft (incoai/Qwen3.8-27B-DFlash2), 7 draft tokens, adaptive packed verification, FP8 KV (reports under themtpproposal-source label in metrics)flare run PACKAGE --gpus 0 --host 0.0.0.0 --port 8080 --memory-limit 0.56 --max-concurrency 3(systemd unit)Workload
An OpenClaw agentic session against
/v1/chat/completions(streaming, tool calls, multi-turn). Long growing contexts with heavy prefix-cache reuse — the same "long multi-turn / agent" profile the issue identifies. No benchmark harness; organic traffic.Observed
prepared model reported device error 6over ~15 minutes of agentic use (07:19–07:33 UTC on 2026-11-03), in bursts of several consecutive failures separated by quiet periods — consistent with pool-fill / page-cycling conditions rather than a per-request deterministic trigger.flare_requests_failed_total= 32, matching the log exactly.flare_cached_kv_tokens≈ 208,768 (prefix cache heavily populated),flare_free_kv_tokens≈ 8,320,flare_free_snapshots= 43 — i.e. the KV pool was under real pressure with snapshot aliasing active, matching the issue's trigger conditions.Notes
/metrics, cumulative since process start — the failure window is contained in these):batch=1,width=8: 5,382 rounds;batch=2,width=8: 54;batch=1,width=1: 88;batch=2,width=1: 1. No batch-4 rounds at all — the agentic traffic is effectively sequential (one request in flight), so the failures occurred almost entirely in single-request width-8 packed rounds with up to 7 drafts. That matches the issue's finding that the first round after a restore fails even at width 1 with no drafts: the trigger is the target distribution, not draft content.mtpproposal-source label in metrics (flare_speculative_drafts_total{source="mtp"}).cc696a6bpredates Paged attention decode propagates NaNs from unused V-cache tails into live outputs (intermittent invalid-distribution errors on main) #14's paged-attention tail fix (local-inference-lab/flashinfer#43), so a re-export will be needed regardless once that lands.Clear released snapshot-alias pages before their first KV use
mark-yong commentedon Nov 4, 2026
Which attention kernels read past the valid length (poison test)
Instead of zeroing released pages (#181), we looked for every attention kernel that lets cache bytes it should not read reach the output. For each component, every slot a request must not read (past its length, outside its window, unselected, unreferenced pages) was filled with zeros, then NaN bytes, and the outputs were compared with each other and with a reference. K and V were poisoned separately.
Setup: RTX PRO 6000 (SM120), FlashInfer
3c2729e7, Flareb4196955. Components were built as the recipes build them, throughPreparedPagedAttentionand the other component constructors, with representative geometries.Result
Score masking is correct everywhere: poisoning K alone never changed an output. Four kernels let masked V (or MLA latent) rows into P·V, where
0 × NaN = NaN:paged_decodelen % 16 != 0); with a sliding window, also V before the window startpaged_tma)len % 128 != 0)pagedselected-block prefill (msa_union_tile)sparse_mlaThe first two are the qwen38_dense paths in this issue's reproduction, which matches the mechanism described above.
Safe as tested (no NaN and an exact match between the zero and poison runs):
paged: plain decode, verify and extend, sliding window, sinks, selected-block decode and verify.window_attention(selected-position kernel), MSA indexer and packed prepare.dense_mla(kimi3) andcompressed_mla(deepseek4/41).compressed_sparse_mlaalready zeroes masked V explicitly ("Mask V itself: MMA still propagates NaNs when P is zero"), which is the pattern the kernel fixes need.Next steps
Not covered
paged_tmakernel is built for SM120 and SM121, andpaged_decoderuns on both, but neither was run on SM121.sm103_sparse_attention(QSA).Poison scripts are available for each component.
jwnand commentedon Nov 5, 2026
Data point: DeepSeek-V4.1-Flash on GB10/SM121, TP4 across four Sparks, two engine builds
Same surface symptom as this issue, on a model and topology the poison table above does not cover.
Environment
--roce-ring)585159c9(flashinfer42ba2f16) and Flare0009b89d(flashinfer1f8ed8a3), source buildslocal-inference-lab/DeepSeek-V4.1-Flash-1017-FLARE@gb10revisionef5c848b(deploymentdb20209d), TP4, prefill 8192, C=32gb10-tp4-202611050533, deploymente8e692d6), same flags--max-concurrency 32 --mtp-draft-tokens 5 --mtp-adaptive-verification --embedding-table-storage disk --host 0.0.0.0 --port 8015Workload
One-hour steady soak, OpenAI-compatible
/v1/chat/completions, streaming, one short prompt repeated (57 prompt tokens, 256 max output tokens), so the prefix cache is heavily reused and pages cycle between snapshot aliases and KV use. Concurrency mixed under the C=32 ceiling.Observed
HTTP 200, stream starts, then ends with a
server_errorchunk instead of the final usage/finish chunk:585159c9, package A, 1 failure in 694 samples over 1,322 s (soak aborted at the first error).0009b89d, package B, 1 failure in 951 samples over 2,040 s.Why I am adding it here
The poison table above lists
compressed_mla(deepseek4/41) as safe, and the "not covered" section lists SM121 and TP4-on-Spark. So either DeepSeek V4.1 reaches the same stale-page condition through a kernel/path not in the table, or there is a separate leaking path on SM121. Two questions:I can provide the full request bodies, raw client logs and
/metricsscrapes around each failure.original-el8 commentedon Nov 5, 2026
The original dense-Qwen cache-pressure failure now has integrated fix evidence. Flare 5a1640c8 pins FlashInfer 1f8ed8a3. That dependency commit reports an exported Qwen3.8-27B package passing 143 paired 16k/32k prompts (286 requests), with a 50 GiB budget, 409 evictions, 285 restores and no failures; the unpatched package failed at pair 22.
This ticket is partially addressed. The later DeepSeek/SM121 TP4 failure needs its own reproduction and failing-check diagnosis before it can be attributed to the same mechanism. Record the preparation revision, package/deployment identity, runtime revision and effective sampling controls. Packages retain their prepared kernels and sampling ranges until re-export.
Draft PR #181 has not established that its page-clearing change is required after the kernel fixes. Validate any remaining failure against the pinned kernels before choosing that mitigation. The measurements above are from the commit report; no additional soak was run for this triage.
feat(#12): Feat(helios): expose snapshot_exclusive_pages for pages le…
jwnand commentedon Nov 6, 2026
The DeepSeek/SM121 case below was measured on the pinned kernels: runtime
0009b89d(contains
5a1640c8), FlashInfer1f8ed8a3. So the Qwen fix is in that build and this failureremains after it. Records you asked for:
Preparation and package identity
local-inference-lab/DeepSeek-V4.1-Flash-1017-FLARE@gb10, revisionef5c848b3894f38d13c5a4b3fe6719c696435c96deepseek-ai/DeepSeek-V4.1-Flash-1017@1bae0e108899plus thejcartu/WARMIND-1017derivative (revision4fbce630)db20209d361f473b8452f24ad517fa0de8e692d63b4846dfbafb12477b861db30009b89d+ FlashInfer1f8ed8a3, exported 2026-11-05T05:33ZRuntime for both:
0009b89de948e6b06c47252c777890c0a071c45c, FlashInfer1f8ed8a3c46e27d03cff54e08f23e9bc50476d57. Four DGX Spark GB10 (SM121), driver 580.173.02,one rank per host over a closed RoCE ring.
Effective sampling
Package metadata from
/v1/models:temperaturedefault 1.0 with no request range (fixed at1.0),
top_p1.0 with range [0.95, 1.0],top_k-1 fixed,min_p0 fixed,repetition_penalty1.0 with range [1.0, 1.1],seedrequest-controlled. So this is not greedy:the soak sent
temperature: 1.0,seed: 0,max_tokens: 256,reasoning_effort: high.The failure
HTTP 200, content 89 chars and reasoning 146 chars already streamed, then the stream ended with no
usage/final chunk. Sample 950 of 951 in a 2,040 s soak at mixed concurrency under C=32, on the
short (58-token) heavily prefix-cached soak prompt. The same package/runtime completed a full
3,600 s soak (1,696 samples) on retry, and an earlier soak on the previous runtime (
585159c9,FlashInfer
42ba2f16) failed the same way once in 694 samples. It has never appeared at C1–C8 orin 16-minute benchmarks.
Diagnosis
I do not have your bitmask build. If you point me at the branch/commit that replaces code 6 with
the failing check (
ignition/components/speculation.py), I can build it on this SM121 TP4 setup,reproduce under the same soak, and report which shape/probability check fails — with and without
#181 if you want the comparison. The full request bodies, raw client logs and
/metricsaround thefailure are available.
yatesdr commentedon Nov 19, 2026
@mark-yong, could you share the scripts you used for
compressed_mla, and for the MXFP4 indexer if you covered it? The DeepSeek V4.1 failure @jwnand reports runs on SM121 under CUDA graph replay, which your run above did not cover. We have GB10 (SM121) hardware this week and will run them on current main, eager and under graph replay, and post the results here.@jwnand, on a build that reports the failing check: main has none. Verification marks a row invalid when it is not live, a draft or target distribution is flagged invalid, a draft token is outside the vocabulary, its token limit is out of range, or its probabilities are non-finite, negative or off by more than 1e-4 in total mass (
ignition/components/speculation.py:412-428). The commit then reports code 6 for every invalid row (:674-703), and no metric or log records which condition fired.mark-yong commentedon Nov 19, 2026
Both below.
poison_compressed_mla.pyimportspoison_common.py.They ran eager on SM120 with FlashInfer
3c2729e7and Flareb4196955; neither has been run on SM121 or under graph replay.In the MXFP4 indexer, selection sets differ between identical runs at the top-512 cutoff, so compare scores rather than sets on a rerun.
poison_compressed_mla.py
poison_common.py
poison_indexer.py
yatesdr commentedon Nov 19, 2026
Results of the scripts above on one DGX Spark GB10 (SM121), eager, at Flare main eb8a062 with its pinned FlashInfer 2cce3e67 (b12x from the FlashInfer package):
poison_compressed_mla.py, all groups: 2,836 poisoned cases (SWA, indexed and both; NaN, largest-finite and zero fills;-1and stale index padding) gave no non-finite output and a maximum difference of 0.0 from the zero-filled run. All 1,848 positive controls produced NaN, so the poison reaches a slot when a row reads it.poison_indexer.py glmandds4: 18 cases each, with no changed index set, no changed score, no NaN score and no index at or past a row's length.poison_indexer.py ds41: no NaN score and no out-of-range index. Index sets changed in 12 of 18 cases, but clean reruns without poison changed as many rows or more (1 decode row; 32 prefill rows in group 1), and no index present in both runs changed its score. That matches the top-512 nondeterminism noted above.So on SM121, eager, the compressed sparse MLA and DSA indexer read no unreferenced or tail slot. Not run: CUDA graph replay, and the four kernels listed as leaking in the 2026-11-04 comment.