Repository navigation
perf(helios): alias null continuation row zero onto a single zeroed VMM granule - #659
Conversation
|
A case file has been opened for 659. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe core design and arithmetic are sound, model-agnostic, and well-scoped to shared cache-planning and VMM-allocation code (
Walkthrough
Merge Risk: Medium · up to
|
…MM granule
Models with continuation-state storage (`sizing.capacity == 0`, `state_pool`)
reserve row zero as a permanent null row that is never assigned to any live
request or snapshot (`StateSlotId` allocations start at `1`, offload transfers
reject slot `0`, and inactive lanes must perform no state mutation). Previously,
`NativeResources::allocate_shared_cache` (`helios/src/runtime_core/cache_memory.rs`)
and cache-capacity planning (`helios/src/runtime_core/memory.rs`) backed row
zero with dedicated physical GPU memory across its full row stride. On models
whose continuation row spans multiple `2 MiB` CUDA VMM granules (for example
`35 MiB` on DCP16 layouts, `82 MiB` on hybrid Mamba models, or `184.88 MiB` on
Qwen3.8-27B), that consumed tens to hundreds of MiB of physical VRAM per rank
solely to store zeros.
Because CUDA VMM `cuMemMap` maps one physical allocation handle at multiple
aligned virtual offsets—the same mechanism `allocate_shared_cache` uses for
snapshot-to-KV aliasing—aliasing row zero's `floor(row_bytes / alignment)` full
leading granules onto one zeroed physical granule reclaims
`(floor(row_bytes / alignment) - 1) * alignment` bytes per rank while
preserving row zero's virtual span, its uniquely backed partial tail (which
shares a boundary granule with row one), and distinct backing for every live
and snapshot row.
What changed:
- `helios/src/runtime_core/cache_memory.rs`:
- Before: `Layout` tracked only `fixed_bytes`, `handle_charge` charged
`1 + row_readers` for the fixed continuation chunk, and
`allocate_shared_cache` created and zeroed one physical chunk of
`fixed_bytes`.
- After: added `sentinel_saved_bytes(row_bytes, alignment)`,
`Layout::sentinel_granules` (`row_bytes / row_alignment` when
`execution > 0` and `row_bytes / row_alignment > 1`, else `0`), and
`Layout::fixed_segments()` describing `(mapping_count, chunk_bytes,
tail_bytes)` once for `handle_charge`, `allocate_shared_cache` mapping and
zeroing, and `verify_physical_invariants`. When `sentinel_granules > 1`,
`allocate_shared_cache` maps one `alignment`-sized physical chunk at
`sentinel_granules` aligned offsets of row zero, maps the remaining tail
separately when `tail > 0`, and zeroes each physical chunk once before
replay. `handle_charge` accounts for the extra per-granule mappings
(`+17` handles per rank on the 16-rank DCP16 layout, moving the 3,103-page
fixture from `518,232` to `518,504` handles and RM-handle headroom from
`1.2%` to `1.1%`, scaling by `row_readers` if `state_pool` has peer
readers).
- Added CPU coverage in `sentinel_row_aliases_full_granules_onto_one_page`
(including `tail == 0` and `execution == 0` cases), updated
`cuda_aliases_preserve_rows_while_unowned_pages_are_rewritten` (`rows = 8`
so chunk packing merges after midpoint-ordered grouping, keeping row zero
zeroed and probing hardware aliasing across granules `0..3` plus isolation
of row zero's partial tail from granule zero and row one), and added
`cuda_sentinel_row_with_exact_granule_stride_maps_without_tail` covering
the `tail == 0` GPU path.
- `helios/src/runtime_core/memory.rs`:
- Before: `capacities`, minimum-footprint validation, and `gpu_bytes`
accounting priced continuation rows with `bytes(core, 0, units)`.
- After: added `row_backing_bytes(core, units)` wrapping `bytes(core, 0,
units)` and subtracting `sentinel_saved_bytes` when `units > 0` for
physical-backing checks and `gpu_bytes` reporting, while keeping virtual
span calculations on `bytes(core, 0, ...)`. Added
`sentinel_row_savings_increase_kv_page_capacity`.
- `helios/src/offload/transfer.rs`, `helios/src/offload/transfer/codec.rs`,
`helios/src/offload/gpu_tests.rs`:
- Before: offload transfer expansion (`transfer::expand`) and codec span
resolution (`codec::device_spans`) accepted `StateSlotId(0)`, and
`staged_store_round_trips_records_through_files_and_a_restart` plus two
synthetic codec GPU tests wrote or read through `StateSlotId(0)`.
- After: `transfer::expand` and `codec::device_spans` reject `StateSlotId(0)`
for both inbound and outbound transfers, CPU tests verify rejection of slot
zero, `staged_store_round_trips_records_through_files_and_a_restart` uses
`StateSlotId(4)` with `row_capacity >= 5`, and the two codec GPU tests use
a 3-row geometry with `StateSlotId(1)` and `StateSlotId(2)`.
- `docs/runtime-core-design.md`:
- Documented null-row sentinel granule aliasing in cache sizing and updated
the DCP16 RM-handle example (`518,504` handles, `5,784` / `1.1%` headroom).
- Compatibility: No core wire format, Protobuf, CLI, or metric schema changes;
existing prepared cores load and serve without re-export. Pure KV models and
models with `row_bytes < 2 * alignment` are unaffected (`sentinel_granules = 0`).
Claimed benefit and result:
- Reclaims `(floor(row_bytes / alignment) - 1) * alignment` bytes of physical
VRAM per rank for KV pages, shared snapshots, or reduced footprint on every
continuation-state model with `row_bytes >= 2 * alignment`.
- Measured on an RTX PRO 6000 Blackwell (SM120) GPU loading an existing
`Qwen3.8-27B-NVIDIA-NVFP4-QAD-MXFP8` TP1 core (`row_bytes = 193,865,984`,
`alignment = 2 MiB`, `sentinel_granules = 92`) compared against `origin/main`
(`cb191a93`) with `--max-concurrency 2`:
- Cap-limited (`--kv-cache-limit context`): `nvidia-smi` GPU 0 VRAM dropped
from `39,709 MiB` to `39,527 MiB` (`-182 MiB` exact, matching `(92 - 1) *
2 MiB`; `Allocate cache` `8.5 GiB -> 8.4 GiB`, identical `2,048` KV pages
and `44` shared snapshot slots).
- Memory-limited (`--memory-limit 40G`): KV capacity increased from `2,352`
to `2,400` KV pages (`+48` pages / `+6,144` KV tokens, `301,056 -> 307,200`)
and shared snapshots increased from `50` to `51` within the same `9.77 GiB`
cache budget.
Supporting evidence and limitations:
- Rust crate release suites (`--locked --release --target-dir flare-cli/target`):
- `eos`: 12 passed, 0 failed.
- `selene` (`--features test-support`): 585 lib + 1 integration passed, 0 failed.
- `selene-manager` (`--features test-support`): 205 lib + 243 integration passed, 0 failed, 1 ignored.
- `helios` (`--features runtime-core,server`, with prepared public templates):
1,881 lib + 62 integration passed, 0 failed, 49 lib / 36 integration ignored.
- `flare`: 247 lib + 8 integration passed, 0 failed, 4 ignored.
- `flare-cli`: 220 bin + 26 integration passed, 0 failed, 3 ignored.
- SM120 GPU tests (RTX PRO 6000 Blackwell):
- `runtime_core::cache_memory::tests::cuda_aliases_preserve_rows_while_unowned_pages_are_rewritten`
and `cuda_sentinel_row_with_exact_granule_stride_maps_without_tail`: 2 passed, 0 failed.
- `offload::transfer::codec::tests::` (all 4 GPU tests with SM120 `kv_codec_gpu.cubin`):
4 passed, 0 failed.
- `offload::transfer::tests::split_pools_cost_each_device_its_part_and_round_trip_units`
(2 GPUs): 1 passed, 0 failed.
- Live serving and NVMe disk offload + restart restore on
`Qwen3.8-27B-NVIDIA-NVFP4-QAD-MXFP8` (`--prefix-cache-memory 0 --prefix-cache-disk`):
cold turn (`4,228` prompt tokens) stored `312.89 MiB` to disk and returned
`42`; fresh restarted process restored `312.89 MiB` from NVMe (`4,221`
reused tokens) and returned `42`.
- Formal verification:
- `python3 verification/helios-lifecycle/check.py` (TLC 1.7.4 / Java 21):
all 8 TLA+ models and all observed Rust transition checks passed (Lifecycle
1,710, RankProtocol 1,291, DispatchRing 7,940, OffloadTransfer 8,490,
CacheOwnership 222,817, Speculation 13,566, ResponseLifecycle 365,508,
CheckpointReservation 68).
- `cargo kani --manifest-path helios/Cargo.toml --features runtime-core --lib`
(Kani 0.68.0 / CBMC 6.11.0): 13 verified harnesses, 0 failures.
- Limitations: `offload::gpu_tests::disk_store::staged_store_round_trips_records_through_files_and_a_restart`
and sibling `FLARE_OFFLOAD_TEST_CORE` Rust unit tests require a core signed
with the synthetic `flare-tests` test key and were not run directly against
production-signed local cores (the disk offload/restart path was exercised
live through `flare run` instead). Aliasing row zero onto one writable
granule relies on the model contract that inactive lanes perform no state
mutation.
Design-Signed-Off-By: Antigravity (Gemini); design-review=2e5b
Signed-off-by: Luke Alonso <lalonso@gmail.com>
16e2247 to
c9bb433
Compare
|
Rebased onto
|
Models with continuation-state storage (
sizing.capacity == 0,state_pool) reserve row zero as a permanent null row that is never assigned to any live request or snapshot (StateSlotIdallocations start at1, offload transfers reject slot0, and inactive lanes must perform no state mutation). Previously,NativeResources::allocate_shared_cache(helios/src/runtime_core/cache_memory.rs) and cache-capacity planning (helios/src/runtime_core/memory.rs) backed row zero with dedicated physical GPU memory across its full row stride. On models whose continuation row spans multiple2 MiBCUDA VMM granules (for example35 MiBon DCP16 layouts,82 MiBon hybrid Mamba models, or184.88 MiBon Qwen3.8-27B), that consumed tens to hundreds of MiB of physical VRAM per rank solely to hold zeros.Because CUDA VMM
cuMemMapmaps one physical allocation handle at multiple aligned virtual offsets—the same mechanismallocate_shared_cacheuses for snapshot-to-KV aliasing—aliasing row zero'sfloor(row_bytes / alignment)full leading granules onto one shared zeroed physical granule reclaims(floor(row_bytes / alignment) - 1) * alignmentbytes per rank while preserving row zero's full virtual span, its uniquely backed partial tail (which shares a boundary granule with row one), and distinct backing for every live and snapshot row.What changed
helios/src/runtime_core/cache_memory.rs:Layouttracked onlyfixed_bytes,handle_chargecharged1 + row_readersfor the fixed continuation chunk, andallocate_shared_cacheallocated and zeroed one physical chunk offixed_bytes.sentinel_saved_bytes(row_bytes, alignment),Layout::sentinel_granules(row_bytes / row_alignmentwhenexecution > 0 && row_bytes / row_alignment > 1, else0), andLayout::fixed_segments()describing(mapping_count, chunk_bytes, tail_bytes)once acrosshandle_charge,allocate_shared_cachemapping and zeroing, andverify_physical_invariants. Whensentinel_granules > 1,allocate_shared_cachemaps onealignment-sized physical handle acrosssentinel_granulesaligned offsets of row zero, maps any remaining tail separately whentail > 0, and zeroes each physical chunk once before replay.(sentinel_granules - 1) * row_readersper-device mappings plus1 + row_readershandles when a non-empty tail chunk exists. On the 16-rank DCP16 fixture (35 MiBrows,row_readers == 1), handle usage rises by+17per rank (518,232 -> 518,504total handles, shrinkingRS_UNIQUE_HANDLE_RANGEheadroom from1.2%to1.1%), scaling withrow_readersifstate_poolhas peer readers.sentinel_row_aliases_full_granules_onto_one_page(standard partial-tail,tail == 0, andexecution == 0geometries), updatedcuda_aliases_preserve_rows_while_unowned_pages_are_rewritten(rows = 8, keeping row zero zeroed and probing hardware aliasing across granules0..3plus isolation of row zero's partial tail from granule zero and row one), and addedcuda_sentinel_row_with_exact_granule_stride_maps_without_tailfor thetail == 0GPU path.helios/src/runtime_core/memory.rs:capacities, minimum-footprint validation, andgpu_bytesaccounting priced continuation rows withbytes(core, 0, units).row_backing_bytes(core, units)delegating validation and aligned span calculation tobytes(core, 0, units)and subtractingsentinel_saved_byteswhenunits > 0for physical-backing checks andgpu_bytesreporting, while keeping virtual-span calculations (mapped = bytes(core, 0, execution) + borrowed) on full virtual sizes. Addedsentinel_row_savings_increase_kv_page_capacity.helios/src/offload/transfer.rs,helios/src/offload/transfer/codec.rs,helios/src/offload/gpu_tests.rs:transfer::expand) and codec span resolution (codec::device_spans) acceptedStateSlotId(0), andstaged_store_round_trips_records_through_files_and_a_restartplus two synthetic codec GPU tests read or wrote throughStateSlotId(0).transfer::expandandcodec::device_spansrejectStateSlotId(0)for both inbound and outbound transfers, CPU tests verify slot-zero rejection,staged_store_round_trips_records_through_files_and_a_restartusesStateSlotId(4)(row_capacity >= 5), and the two codec GPU tests use a 3-row geometry withStateSlotId(1)andStateSlotId(2).docs/runtime-core-design.md:518,504handles, leaving5,784/1.1%headroom).row_bytes < 2 * alignmentare unaffected (sentinel_granules = 0).Claimed benefit and result
(floor(row_bytes / alignment) - 1) * alignmentbytes of physical VRAM per rank for KV pages, shared snapshots, or reduced footprint across every continuation-state model whose row spans at least two VMM granules (for example32 MiB/rankon a35 MiBrow,76 MiB/rankon an82 MiBrow, and182 MiB/rankon a184.88 MiBrow).Qwen3.8-27B-NVIDIA-NVFP4-QAD-MXFP8TP1 core (row_bytes = 193,865,984,alignment = 2 MiB,sentinel_granules = 92) with--gpus 0 --max-concurrency 2, compared directly againstorigin/main(cb191a93):--kv-cache-limit context):nvidia-smiGPU 0 VRAM used dropped from39,709 MiB(57,604 MiBfree) to39,527 MiB(57,786 MiBfree) —-182 MiBexact, matching(92 - 1) * 2 MiB;Allocate cachedropped8.5 GiB -> 8.4 GiBwith identical2,048KV pages (262,144tokens) and44shared snapshot slots.--memory-limit 40G,30.23 GiBloaded,9.77 GiBcache budget): KV capacity increased from2,352to2,400KV pages (+48pages /+6,144KV tokens,301,056 -> 307,200) and shared snapshot slots increased from50to51.Supporting evidence and limitations
c9bb4333(--locked --release --target-dir flare-cli/target):eos:12 passed, 0 failedselene(--features test-support):585 lib + 1 integration passed, 0 failedselene-manager(--features test-support):205 lib + 243 integration passed, 0 failed, 1 ignoredhelios(--features runtime-core,server, with prepared public templates fromtests/frontend/prepare_templates.pyexcluding gatedmuse_spark):1,881 lib + 62 integration passed, 0 failed(49lib /36integration ignored)flare:247 lib + 8 integration passed, 0 failed, 4 ignoredflare-cli:220 bin + 26 integration passed, 0 failed, 3 ignoredCUDA_VISIBLE_DEVICES=0 cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib runtime_core::cache_memory::tests::cuda_ -- --ignored --test-threads=1:2 passed, 0 failed(cuda_aliases_preserve_rows_while_unowned_pages_are_rewrittenandcuda_sentinel_row_with_exact_granule_stride_maps_without_tail), verifying multi-offsetcuMemMapaliasing across granules, splitcuMemsetD8_v2zeroing, partial-tail isolation from granule zero and row one, and thetail == 0path.CUDA_VISIBLE_DEVICES=1 FLARE_TEST_KV_CODEC_CUBIN=... cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib offload::transfer::codec::tests:: -- --ignored --test-threads=1:4 passed, 0 failed.CUDA_VISIBLE_DEVICES=0,1 cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib offload::transfer::tests::split_pools_cost_each_device_its_part_and_round_trip_units -- --ignored --exact:1 passed, 0 failed.flare runserving and NVMe disk offload + restart restore onQwen3.8-27B-NVIDIA-NVFP4-QAD-MXFP8(--memory-limit 40G --prefix-cache-memory 0 --prefix-cache-disk): cold4,228-token prompt stored312.89 MiB(328,093,696bytes) to NVMe and returned42; fresh restarted process restored312.89 MiB(328,085,504bytes,4,221reused tokens) from NVMe and returned42.python3 verification/helios-lifecycle/check.py(TLC1.7.4/ Java 21): all 8 TLA+ models and all observed Rust transition checks passed (Lifecycle1,710, RankProtocol1,291, DispatchRing7,940, OffloadTransfer8,490, CacheOwnership222,817, Speculation13,566, ResponseLifecycle365,508, CheckpointReservation68).cargo kani --manifest-path helios/Cargo.toml --features runtime-core --lib(Kani0.68.0/ CBMC6.11.0):13 verified harnesses, 0 failures.offload::gpu_tests::disk_store::staged_store_round_trips_records_through_files_and_a_restartand siblingFLARE_OFFLOAD_TEST_CORERust unit tests require a core signed with the syntheticflare-testsfixture key (seed = [42; 32]) and were not run directly against production-signed local cores (live disk offload and restart restore were verified throughflare runinstead).prepare_templates.pyreturned403 Forbiddenfor the gatedmeta-models/Muse-Spark-Open-816B-A42B-NVFP4template; all 9 public template recipes were prepared and all1,881helioslib tests passed.Discord: lukealonso