Repository navigation
Conversation
Why. Continuation snapshot rows share physical pages with KV cache rows through
CUDA VMM aliasing (share_snapshot_pages). Before this change, evicting a snapshot
returned those pages to free_pages without clearing them, so a request that later
allocated one inherited the evicted snapshot's bytes wherever the KV write kernels
did not reach, meaning any tail beyond seq_len % page_size. On SM103 those bytes
are read as FP8 E4M3FN, where 0x7F and 0xFF both decode as NaN, and TRT-LLM FP8
FMHA BMM2 multiplies zero attention weights by them (0.0 * NaN), so one stale
tail poisons the attention output and sampling fails with INVALID_DISTRIBUTION
(device error 1). Zeroing at reclaim was chosen over zeroing at allocation
because reclaim is the one point every cache scheme passes through and it keeps
the cost off the allocation fast path.
What changed. RequestScheduler now records pages whose page_snapshot_refs falls
1 -> 0 and zeroes them with coalesced cuMemsetD8Async on a dedicated
CU_STREAM_NON_BLOCKING stream, strictly before any kernel submission or
host-to-GPU prefix-cache DMA restore (store.fetch) can observe them. The same
reclaim path is wired through the local, threaded-TP and multi-process TP
executors, plus the page-id wire encoding exchanged between ranks. Eleven files:
cuda.rs, execution/{parallel,parallel/tests,parallel/wire,ranks,threaded,
transport}.rs, scheduler.rs, scheduler/cache_memory.rs, server/runtime.rs and
server/runtime/phase_tests.rs.
Benefit. Expected: removes a class of nondeterministic sampling failure on SM103
long-context continuation snapshots, at the cost of one asynchronous memset per
reclaimed page. Measured: the four new regression tests pass and the targeted
suite moves from 798 to 802 passing tests with zero failures.
Evidence. cargo check exits 0 for the default, runtime-core and
server,runtime-core feature sets with warning counts identical to clean HEAD
(5 / 7 / 2), so the change adds no warnings. The targeted lib suite reports
"802 passed; 0 failed; 10 ignored". The PR carries the GPU isolation evidence
from a GB300: a poisoned v_cache tail yields 100% NaN while a poisoned k_cache
tail yields none, and evicted BF16 bytes produced 8.2M NaN against 0 in the
control.
Limitations. The full lib suite is not green on the authoring host: 6 failures
both before and after the patch, all from a missing fixture
(FLARE_TEST_TEMPLATE_DIR), none in touched files. The GPU measurements come from
one GB300 and were not re-run for this submission.
Signed-off-by: ebfio <ebfio@users.noreply.github.com>
Design-Signed-Off-By: Iris (deepseek-v4.1-unlimited via litellm); design-review=2e5b
|
A case file has been opened for 736. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe core mechanism—recording VMM-aliased KV pages on the
Walkthrough
Merge Risk: Medium · up to
|
…lure Bumps the rank-control layout version 6 -> 7 so a patched rank cannot pass HELLO against an unpatched peer and then fail mid-serving with an unexpected rank command on the first snapshot eviction, and records poison on coalesce, memset and sync failures in enqueue_zero_kv_pages/zero_kv_pages so close() reports the cause instead of a clean shutdown.
Adds the two tests the review asked for: a CPU test that drives the ZEROED_KV_PAGES wait with interleaved READY/COMPLETE control frames and asserts they survive into the pending queue, and an ignored CUDA test that fills two planes with 0x7F, zeroes one page through enqueue_zero_cache_pages, and asserts the reclaimed page is zero while the live page stays byte-identical.
…mission test The rebase onto main carried a call written against the pre-NVIDIA#729 signature. Host admission is a non-speculative path, matching runtime.rs:3758, so the test passes false. cargo check never caught this because #[cfg(test)] code is only built by cargo test.
flare_selene re-exports CacheGeometry and Plane at the crate root but not KvCompression, so the new CUDA test must name flare_selene::offload::KvCompression. Found by building the test target, which cargo check does not cover.
… the CUDA test under server tests The interleaving test fed a READY for a fence rank 0 had never submitted, so record_ready rejected it with 'unexpected rank readiness fence'; it now seeds the pending queue with the draining frame and a committed frame that the COMPLETE belongs to. The CUDA zero-page test lived in the runtime-core-gated confidence_tests module, which the gate's --features server build never compiles; it now sits in its own #[cfg(test)] module so it is compiled and listed as ignored.
The test drives Driver::load and Stream directly, and Driver lives in runtime_core, which the server feature does not enable. check.py builds --features server, so an ungated module broke that build; the lifecycle workflow builds runtime-core,server, where the test is now compiled and listed as ignored.
record_peer_completion selects the first frame with a free completion slot for that rank and only then validates committed/fence/graph, so a COMPLETE for the committed frame is rejected when an uncommitted frame sits ahead of it in the queue. The fixture now orders the committed frame first; READY stays fence-addressed and lands on the draining frame.
Summary
When continuation snapshot rows share physical GPU memory with KV cache pages via CUDA VMM aliasing (
share_snapshot_pages), evicting a snapshot returns its backing pages tofree_pageswithout clearing them. If those snapshots stored non-FP8 state (such as BF16 draft-model rings or recurrent state), raw bytes matching0x7For0xFFremain in unwritten KV page tails and are interpreted as FP8 E4M3FN NaN by SM103 FP8 paged attention (0.0 * NaN = NaNin BMM2), poisoning attention outputs and failing sampling withINVALID_DISTRIBUTION(device error 1).This PR tracks reclaimed snapshot-backing KV pages whenever
page_snapshot_refstransitions1 -> 0and zeros them via coalescedcuMemsetD8Asyncon a dedicatedCU_STREAM_NON_BLOCKINGstream across all cache-owning ranks before any kernel submission or host-to-GPU prefix-cache DMA restore (store.fetch) touches them.Root Cause (Blackwell SM103 FP8 V-Cache Tail NaN Isolation)
allocate_shared_cachemaps continuation snapshot virtual rows onto physical pages shared with KV cache pages, andRequestScheduler::share_snapshot_pages/release_snapshotrefcount those pages inpage_snapshot_refs.0x7Fand0xFFbytes. When the snapshot is evicted (page_snapshot_refsdrops1 -> 0) and a new request allocates one of those pages, KV-write kernels only populate tokens0..seq_len. Any unwritten tail slots in a partial page (seq_len % page_size != 0) retain stale snapshot bytes.0.0 * NaN = NaNin SM103 TRT-LLM FP8 FMHA BMM2: Under FP8 E4M3FN, both0x7Fand0xFFencode NaN. On Blackwell SM103 (NVIDIA GB300, compute capability 10.3), FlashInfer's TRT-LLM FP8 FMHA kernels mask out-of-range K-cache scores to-infbefore softmax (exp(-inf) = 0.0), so NaN bytes in unwrittenk_cachetails do not propagate. In BMM2 (P @ V), however,0.0attention weights still multiply unwritten tail elements ofv_cacheacross the tile, producing0.0 * NaN = NaNand cascading intoINVALID_DISTRIBUTION(device error 1) during sampling.Standalone SM103 GPU Isolation Matrix
Device: NVIDIA GB300 (
CC 10.3),batch=1, Hq=64, Hkv=8, D=128, page_size=128, NHD, FP8 E4M3FN KV, swept acrosswindow_left ∈ {-1, 511},seq_len ∈ {17, 64, 127, 129, 202, 536},packed ∈ {1, 4, 9}, eager and CUDA graph:A_zero(virgin zeroed tail):0NaN,0Inf across all combinations.B_k_nan(k_cachetail =0x7Fonly):0NaN,0Inf across all combinations (softmax masks out-of-range K scores to-inf→0.0).B_v_nan(v_cachetail =0x7Fonly): 100% NaN across every backend, mode, window, andseq_len(0Inf).B_kv_nan(k_cache=0x7F,v_cache=0xFF): 100% NaN across every backend, mode, window, andseq_len(0Inf).C_bf16_bytes(evicted BF16randn * 10.0raw bytes in K+V tail): NaN > 0 on every combination (8,215,432total poison NaNs vs0total control NaNs;0Inf).Representative rows (all
inf_count = 0):window_leftpackedseq_lennan_countA_zerotrtllm_decode_ragA_zerotrtllm_decode_ragA_zerotrtllm_contextB_k_nantrtllm_decode_ragB_k_nantrtllm_contextB_v_nantrtllm_decode_ragB_v_nantrtllm_decode_ragB_v_nantrtllm_decode_uniB_v_nantrtllm_contextB_v_nantrtllm_decode_ragC_bf16_bytestrtllm_decode_ragC_bf16_bytestrtllm_decode_ragC_bf16_bytestrtllm_decode_uniC_bf16_bytestrtllm_contextC_bf16_bytestrtllm_decode_ragFix Design & Race-Free Selene DMA Ordering
helios/src/scheduler.rs,helios/src/scheduler/cache_memory.rs):reclaimed_snapshot_pages: Vec<u32>onRequestScheduler.pageinrelease_snapshotstrictly whenpage_snapshot_refs[page]drops1 -> 0(shared pages with refcount>= 1are not queued until their last snapshot reference releases them).RequestScheduler::take_reclaimed_snapshot_pages(&mut self) -> Vec<u32>.helios/src/cuda.rs,helios/src/execution/{transport,threaded,parallel,parallel/wire,ranks}.rs):Stream::with_contextwrappingDriver::with_context(fast-path no-op when the context is already current; save/restore otherwise).CU_STREAM_NON_BLOCKINGzero: StreamperGraphExecutor(drained inclose()) and per cache-owning peer rank inThreadedExecutor(guarded byWatchdogCallGuard, drained on cleanclose(), and forgotten on poisoned teardown socuStreamDestroy_v2is never called on a wedged context).(start, count)runs (coalesce_page_runs), issuecuMemsetD8Async(dst, 0, nbytes)across all cache planes (overlapped across local and peer GPUs inThreadedExecutor), and synchronize each enqueuedzerostream before returning.ZERO_KV_PAGES/ZEROED_KV_PAGEScontrol packets inTensorParallelExecutor(parallel.rs/parallel/wire.rs/serve_rank) so multi-process / multi-node TP peers also zero reclaimed KV pages concurrently with rank zero while preserving in-flightREADY/COMPLETEpeer message ordering.Worker(helios/src/server/runtime.rs):Worker::zero_reclaimed_kv_pagesand flush after active cancels, at the end ofadmit_with_executor, aftercomplete,publish,service_store, andplan, and insubmitimmediately afterreserve_and_packbeforeexecutor.submit.admit_with_host_store, drainscheduler.take_reclaimed_snapshot_pages()and executezero_kv_pages(&reclaimed)strictly beforestore.fetch(hit, ticket). This guarantees reclaimed pages are zeroed and synchronized before Selene initiates any asynchronous host-to-GPU DMA restore into those pages. Any executor failure fromzero_kv_pagespropagates out ofadmit_with_executoras a fatal worker error rather than being swallowed as a per-request admission rejection.Overhead
1 -> 0— never during steady-state KV page allocation or reuse between requests.cuMemsetD8Asynccalls executing on a dedicated non-blocking stream at HBM3e bandwidth (~8 TB/s on GB300), completing in ~27 µs.Verification
be4092d7e1f0efe8a16049568c12ec7b841a2e8e):git diff --checkand clean-checkoutgit apply --check+git apply: passed with zero warnings.cargo check --locked --manifest-path helios/Cargo.toml(default features),--features runtime-core, and--features server,runtime-core: 0 new warnings, 0 errors.CUDA_VISIBLE_DEVICES=""):scheduler::cache_memory::tests::release_snapshot_records_only_reclaimed_pages_and_drainsexecution::transport::confidence_tests::coalesce_page_runs_sorts_dedups_merges_and_bounds_checksexecution::parallel::tests::zero_kv_pages_wire_roundtrip_and_truncationserver::runtime::phase_tests::admit_with_host_store_zeros_reclaimed_snapshot_pages_before_fetch(proveszero_kv_pagesruns strictly beforestore.fetchon evicted aliased snapshot pages and suppressesstore.fetchon error)cargo test --locked --manifest-path helios/Cargo.toml --features server,runtime-core --lib -- cuda:: scheduler:: execution:: server::runtime::): 802 passed, 0 failed, 10 ignored (CUDA-device-gated).75/75HTTP 200 requests (0failed,0device errors), driving98snapshot evictions (154snapshot publications), peak3,008 / 3,184snapshot-backing pages, minimum10free KV pages, and4,579speculative graph launches across batch sizes1..16and widths{1, 9}(5,493verification request rounds,30,157offered /10,976accepted drafts).152/152completed requests (0failed,0cancelled,0runtime errors),280snapshot evictions,100,108generated tokens,402,718prefill tokens,258host-cache stores (0store failures), and4DRAM host-cache restores (0fetch failures,4,805reused tokens).Validation limits
The targeted lib suite is green (
802 passed; 0 failed; 10 ignored), but the fullcargo test --librun is not: 6 tests fail both before and after this patch, allfrom a missing fixture that is generated separately (
FLARE_TEST_TEMPLATE_DIR,via
python tests/frontend/prepare_templates.py), none in files this patchtouches. Feature-matrix
cargo checkwarning counts are identical to cleanmain(5 / 7 / 2). The SM103 isolation and soak numbers above come from oneGB300 and were not re-run for this submission.
Discord: ebfio
Review follow-up (2026-12-05)
The automated review requested changes; all four code items are addressed and the
mandated gate now runs and passes.
ZERO_KV_PAGES(14) andZEROED_KV_PAGES(15) were added without changingwire::layout(), so a patchedrank and an unpatched peer passed
HELLOand then failed mid-serving with"unexpected rank command" on the first snapshot eviction.
GraphExecutoris poisoned when zeroing fails.enqueue_zero_kv_pagesandzero_kv_pagescheckedself.poisonon entry but never set it, unlikesubmitand
poll; on the local rank a failed memset left the executor usable anddropped the cause from
Shutdown.error.ZEROED_KV_PAGESwait nowprovably consumes interleaved
READY/COMPLETEframes into the pending queue.0x7F,zeroes one page through
enqueue_zero_cache_pages, asserts the reclaimed page iszero and the live page byte-identical. Gated on
runtime-core, becauseDriverdoes not exist under
serveralone.Verification (Linux,
py check.py --mutations, exit 0):Model checking completed. No error has been found.identical transition counts.
A defect found while running the gate, worth flagging for anyone rebasing this
branch:
cargo checkdoes not compile#[cfg(test)]code, so a test target can bebroken while
checkis green. Two such errors were present after rebasing ontocfb72093(a call toRequestSpec::specwritten against its pre-#729 signature,and a
KvCompressionpath) and only surfaced when the test target was built.