Skip to content

selene,helios: bound pool-only capture buffer to max_sequence_pages - #742

Open
fakoli wants to merge 1 commit into
NVIDIA:mainfrom
fakoli:fix/bound-pool-only-capture-slab
Open

fakoli wants to merge 1 commit into
NVIDIA:mainfrom
fakoli:fix/bound-pool-only-capture-slab

Conversation

@fakoli

@fakoli fakoli commented Dec 5, 2026 •

Copy link
Copy Markdown

Why

PR #455 added a CPU-readable capture buffer for single-process pool-only offload (--prefix-cache-pool with --prefix-cache-memory 0 and no local disk tier) so instances without a local memory or disk tier can still export checkpoints to selene-manager. Review of #455 flagged that sizing the capture slab to full GPU page capacity plus one row reserves nearly the entire GPU KV cache in registered host memory and fails startup with host budget cannot hold a full pool capture if the host budget cannot accommodate it.

When a GPU holds multiple full-context sequences of KV pages (for example, quantized models or large-VRAM workstation cards serving 1M-context cores), sizing the capture chain to total GPU page capacity inflates the host buffer proportionally. Because no single captured sequence chain can exceed the core's max_sequence_tokens, bounding the capture chain length to min(GPU page capacity, ceil(max_sequence_tokens / page_tokens)) prevents multi-sequence oversizing and avoids throttling GPU KV allocation or exceeding container memory limits. Meanwhile intake_slots(layout, inputs.max_active) remains intentionally uncapped so concurrent active transfers are not starved on wide TP deployments.

What changed

  1. Selene offload interface and headroom sizing (selene/src/offload.rs):
    • Added pub max_sequence_pages: Option<NonZeroU64> to PrepareInputs (encoding non-zero sequence bounds at the type level and keeping None uncapped for callers that omit a bound).
    • Bounded headroom_inner's chain_pages via inputs.max_sequence_pages.map_or(pages, |limit| pages.min(limit.get())).
    • Updated prepare_with_inputs_budget_with_progress destructuring with .. for forward compatibility.
  2. Helios runtime memory planning and model attachment (helios/src/runtime_core/memory.rs, helios/src/runtime_core/model.rs):
    • Enforced both max_sequence_tokens > 0 (NonZeroU64 parsed once) and contract.cache.page_tokens > 0 inside max_sequence_pages(context, page_tokens) -> Result<NonZeroU64> before div_ceil (since page_ceiling returns early under the default --kv-cache-limit memory mode).
    • Passed max_sequence_pages into headroom_with_inputs_for_budget (where headroom_inner clamps minimum_pages), shared capture_chain_pages(pages, max_sequence_pages) across capture_growth and planned_offload_host, and threaded PlannedHostBudgets::max_sequence_pages directly into private NativeModel::prepare_offload (NonZeroU64) so planning and attach cannot diverge.
  3. Documentation (docs/prefix-cache-offload.md):
    • Updated the pool-only capture buffer sizing section to document the min(GPU page capacity, ceil(max_sequence_tokens / page_tokens)) chain ceiling alongside the existing GLM-5.3-Flash TP4 (11.0 GiB / 7.1 GiB floor) example and startup failure behavior.
  4. Tests (selene/src/offload/tests.rs, helios/src/runtime_core/memory.rs, and existing test fixtures):
    • Folded capped (512, NonZeroU64::new(64)) vs uncapped None checks into pool_only_sizes_registered_capture_and_headroom_for_local_ranks.
    • Added pool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages covering max_sequence_pages zero-input rejection, ceiling division, capture exhaustion (capture_growth returning None above max_pages), shared capture_chain_pages clamping, and exact parity (pages == uncapped_pages) when host_free == 0 past max_sequence_pages.
    • Added max_sequence_pages: None to existing PrepareInputs fixtures across helios, selene, and selene-manager, and NonZeroU64::MIN to early-returning prepare_offload unit tests in model.rs.

Claimed benefit

In pool-only mode (--prefix-cache-memory 0), host capture chain sizing stays bounded to one max_sequence_tokens chain (with the intake_slots floor preserved for transfer bursts) instead of growing with total GPU KV page capacity. When cap + row exceeds intake_slots, shrinking the capture buffer only bounds concurrent multi-sequence capture capacity (parallel captures remain retry-safe and evictable via Retry(StoreReason::Slabs)):

Metric (Qwen4-35B-A3B, 1,048,576 max sequence tokens, 64 tok/page, 96 GiB SM120 GPU, 24 GiB container limit) Unbounded formula on main Bounded (max_sequence_pages = 16,384)
Allocated GPU KV capacity 99,008 pages (70.9 GiB, 6,336,512 KV tokens = 6.04x max sequence) 99,008 pages (70.9 GiB, unchanged)
Capture chain formula (chain_pages + 91 row slots, ~748 KiB/page record) 99,008 + 91 = 99,099 slots (~70.7 GiB) 16,384 + 91 = 16,475 slots (11.8 GiB)
Startup under 24 GiB container memory limit Exceeds 24 GiB container memory limit (or fails admission / throttles GPU pages when host budget < ~70.7 GiB) Succeeds (pool only: capture buffer 11.8 GiB (16475 slots, populate 1.9s, register 0.4s))

Per-process host memory accounting (live two-worker comparison on identical Qwen4-35B-A3B hardware, 24 GiB container cgroup limit, 4,096 MiB embedding row cache, 22.0 GiB shared selene pool mapping):

  • Worker with --prefix-cache-memory 0 (pool_only(), 11.8 GiB capture slab + 4,096 MiB row cache + runtime/pool/CUDA overhead): 18.74–19.06 GiB container RSS (docker stats).
  • Peer worker with --prefix-cache-memory 1G (0.9 GiB memory slab + 4,096 MiB row cache + runtime/pool/CUDA overhead): 7.83–8.04 GiB container RSS (docker stats).
  • Observed per-process delta (10.91–11.02 GiB) matches the configured slab delta (11.8 GiB - 0.9 GiB = 10.9 GiB), confirming the bounded buffer reserves and faults only its single-sequence size.

Supersedes the bundled pool_only() change previously included in closed #718.

Evidence

Executed on PR head (5021b7a, identical tree to 2f151f9, base NVIDIA/hyperflare-inference:main f46a99220a)

All six Rust crates passed in release mode inside rust:1.94.1-slim-trixie (--shm-size=4g, --ulimit memlock=67108864:67108864, non-root UID, --security-opt seccomp=unconfined, XFS FLARE_OFFLOAD_TEST_DIR, RUSTFLAGS="-D warnings", CARGO_TARGET_DIR):

  • cargo test --locked --release --manifest-path eos/Cargo.toml -- --test-threads=1 — 12 passed, 0 failed, 0 ignored (run single-threaded because multi-threaded container load hit the adaptive_mid_mapping_fallback_merges_into_single_vma compaction-stall timing threshold under concurrent host traffic).
  • cargo test --locked --release --manifest-path selene/Cargo.toml --features test-support — 649 passed (648 unit + 1 doctest), 0 failed, 0 ignored (includes pool_only_sizes_registered_capture_and_headroom_for_local_ranks with bounded and unbounded cases).
  • cargo test --locked --release --manifest-path selene-manager/Cargo.toml --features test-support — 448 passed, 0 failed, 1 ignored across 15 binaries (includes rank_processes: 3 passed, 0 failed).
  • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server (with FLARE_TEST_TEMPLATE_DIR prepared for gemma4, glm53, mimo_v2, minimax_m3, nemotron_h, qwen38, and step5 per CI) — 2,041 passed, 0 failed, 88 ignored across 16 binaries (includes pool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages).
  • cargo test --locked --release --manifest-path flare/Cargo.toml — 255 passed, 0 failed, 4 ignored across 4 binaries.
  • cargo test --locked --release --manifest-path flare-cli/Cargo.toml — 254 passed, 0 failed, 3 ignored across 5 binaries.

Live startup and memory telemetry provenance

The 11.8 GiB (16,475 slots) Prepare host prefix cache. log line and 18.74–19.06 GiB vs 7.83–8.04 GiB container RSS measurements were observed on a v0.6.0 (f705086) build running the same max_sequence_pages sizing rule rather than re-measured via an A/B restart on f46a99220a.

Unrun checks

  • Hardware CUDA tests (FLARE_RUN_CUDA_TESTS=1), tests/server/test_prefix_cache_offload.py, and qualify/host_cache.py on head commit 5021b7a.
  • Integrated/unified-memory hosts, multi-host sharded / RoCE suites, and native Windows builds/tests.
  • Kani and TLA+ model checks (not re-run because this PR does not modify scheduler/cache_memory, lifecycle state machines, or Kani-proven validators).

Discord: fakoli

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 742.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added area:memory Memory budgets, allocation lifetimes, scratch sharing, and capacity. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. area:selene Selene shared prefix-cache pool, protocol, manager, and transfers. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness. labels Dec 5, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The pool-only capture-buffer bound is sound — planning, binary-search growth charging, planned_offload_host, and final slab allocation all agree on min(GPU page capacity, ceil(max_sequence_tokens / page_tokens)), and docs and tests match the implementation. One verified defect warrants a small fix before merge: the new div_ceil(contract.cache.page_tokens as u64) calls in memory.rs:996 and model.rs:1155-1157 are unguarded against zero page_tokens (turning a clean Err(invalid(...)) into a divide-by-zero panic under the default KvCacheLimit::Memory) and against context == 0 (a 0-vs-uncapped mismatch with selene).

  • Blockers: 0 · Should fix: 1 · Subtract/Simplify: 3 · Nits: 4
Walkthrough
  • selene/src/offload.rs: Adds pub max_sequence_pages: Option<u64> to PrepareInputs (:340-347), clamps chain_pages in headroom_inner to pages.min(limit) when Some(limit) with limit > 0 (:165-169), and updates the destructure in prepare_with_inputs_budget_with_progress (:628) while forwarding inputs into headroom_inner (:704-710).
  • helios/src/runtime_core/memory.rs: Computes max_sequence_pages = context.div_ceil(contract.cache.page_tokens as u64) (:996), passes Some(max_sequence_pages) and minimum_pages.min(max_sequence_pages) into initial headroom_with_inputs_for_budget (:1130-1132), and clamps pages.min(max_sequence_pages) in both capture_growth (:1486) and planned_offload_host (:1553).
  • helios/src/runtime_core/model.rs: Derives max_sequence_pages from self.server_config["max_sequence_tokens"] and contract.cache.page_tokens (:1155-1157) and passes it to prepare_with_inputs_budget_with_progress (:1168), where local_pages is the actual allocated GPU page_capacity.
  • docs/prefix-cache-offload.md: Updates the pool-only capture buffer section (:1593-1603) to document the single-sequence chain cap and capped minimum-capacity startup failure behavior.
  • Tests (selene/src/offload/tests.rs, helios/src/runtime_core/memory.rs, and existing PrepareInputs test fixtures): Adds pool_only_caps_capture_buffer_to_max_sequence_pages and pool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages, and sets max_sequence_pages: None across existing test fixtures.
Merge Risk: Low · up to 02990da
Pre-merge checks: ✅ 3 passed · ⚠️ 1 warnings

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@fakoli
fakoli force-pushed the fix/bound-pool-only-capture-slab branch from 02990da to 66d6af3 Compare December 5, 2026 09:19
@fakoli

fakoli commented Dec 5, 2026

Copy link
Copy Markdown
Author

Updated the branch (66d6af3) with the code and simplicity cleanups from the case file:

  1. Threaded PlannedHostBudgets::max_sequence_pages (helios/src/runtime_core/{memory,model}.rs): Removed the duplicate server_config["max_sequence_tokens"] lookup from prepare_offload, eliminating the asymmetric None fallback.
  2. Type-enforced positive bound (Option<std::num::NonZeroU64> in selene/src/offload.rs): Checking memory.rs showed that page_ceiling returns early under the default --kv-cache-limit memory mode before enforcing context > 0. Rejecting max_sequence_tokens == 0 in memory.rs and typing max_sequence_pages as Option<NonZeroU64> eliminates the dead Some(0) branch at compile time while keeping None uncapped.
  3. Single-point clamping & test cleanup: Removed the redundant .min(...) on minimum_pages at the headroom_with_inputs_for_budget call, folded the selene/src/offload/tests.rs bounded case into pool_only_sizes_registered_capture_and_headroom_for_local_ranks, tightened pool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages to assert pages == uncapped_pages, replaced max_sequence_pages: _, with .. in offload.rs, and reflowed docs/prefix-cache-offload.md to 79 columns.
  4. Clarifications on remaining report items:

@flare-autobot

@fakoli
fakoli force-pushed the fix/bound-pool-only-capture-slab branch from 66d6af3 to f26d8a8 Compare December 5, 2026 09:49
@fakoli

fakoli commented Dec 5, 2026

Copy link
Copy Markdown
Author

Updated the branch (f26d8a8) to resolve the remaining Should Fix item from the 02990da review:

  • Guarded contract.cache.page_tokens == 0 alongside max_sequence_tokens == 0 in helios/src/runtime_core/memory.rs via a dedicated max_sequence_pages(context, page_tokens) -> Result<NonZeroU64> helper before calling div_ceil, avoiding a divide-by-zero panic under the default --kv-cache-limit memory mode (where page_ceiling returns early).
  • Added unit assertions covering context == 0, page_tokens == 0, and ceiling rounding inside pool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages.
  • Re-verified all six workspace crates in --locked --release under RUSTFLAGS="-D warnings" on f26d8a8 (see updated PR Evidence).

@flare-autobot

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

Commit 66d6af3 cleanly resolves most of Round 1 — NonZeroU64 is threaded end-to-end and the duplicate max_sequence_tokens lookup is gone — but one half of the Round 1 Should Fix remains: memory.rs:999 still calls div_ceil(contract.cache.page_tokens as u64) unguarded, so a zero page_tokens panics on every model load before PreparedContract::validate runs. A 2-line non-zero check (and an .expect(...) in place of the dead .ok_or_else) makes this ready to merge.

  • Blockers: 0 · Should fix: 1 · Subtract/Simplify: 1 · Nits: 2
Walkthrough
  • selene/src/offload.rs: Adds pub max_sequence_pages: Option<std::num::NonZeroU64> to PrepareInputs (:342-345), clamps chain_pages in headroom_inner via inputs.max_sequence_pages.map_or(pages, |limit| pages.min(limit.get())) (:165-167), and destructures with .. in prepare_with_inputs_budget_with_progress (:627) while forwarding inputs into headroom_inner (:703-709).
  • helios/src/runtime_core/memory.rs: Adds max_sequence_pages: std::num::NonZeroU64 to PlannedHostBudgets (:34, :1595), rejects max_sequence_tokens == 0 (:993-996), computes max_sequence_pages (:998-1000), passes Some(max_sequence_pages) into initial headroom_with_inputs_for_budget (:1134) without double-clamping minimum_pages (:1136), and clamps pages.min(max_sequence_pages.get()) in capture_growth (:1490) and planned_offload_host (:1556-1560).
  • helios/src/runtime_core/model.rs: Threads Some(planned.max_sequence_pages) from allocate_caches into prepare_offload (:1047-1053, :1125) and directly into PrepareInputs (:1167-1173), removing the duplicated server_config["max_sequence_tokens"] derivation.
  • docs/prefix-cache-offload.md: Updates the pool-only capture buffer section (:1593-1609) to document the single-sequence ceiling min(GPU page capacity, ceil(max_sequence_tokens / page_tokens)) and capped minimum-capacity startup failure behavior, reflowed to ~79 columns.
  • Tests (selene/src/offload/tests.rs, helios/src/runtime_core/memory.rs, and existing test fixtures): Folds (512, NonZeroU64::new(64)) into pool_only_sizes_registered_capture_and_headroom_for_local_ranks (selene/src/offload/tests.rs:531-576), adds pool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages asserting pages == uncapped_pages (memory.rs:2446-2465), and adds max_sequence_pages: None across existing PrepareInputs / prepare_offload test fixtures.
Merge Risk: Low · up to 66d6af3
Pre-merge checks: ✅ 3 passed · ⚠️ 1 warning

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

Commit f26d8a8 closes out the sole remaining Should Fix: a dedicated max_sequence_pages helper rejects zero page_tokens/max_sequence_tokens before div_ceil, so the divide-by-zero panic under default KvCacheLimit::Memory is gone and all production sizing paths agree on one threaded cap. No correctness, hot-path, or contract defects remain.

  • Blockers: 0 · Should fix: 0 · Subtract/Simplify: 1 · Nits: 1
Walkthrough
  • selene/src/offload.rs: Adds pub max_sequence_pages: Option<std::num::NonZeroU64> to PrepareInputs (:342-345), clamps chain_pages in headroom_inner via inputs.max_sequence_pages.map_or(pages, |limit| pages.min(limit.get())) (:165-167), and destructures with .. in prepare_with_inputs_budget_with_progress (:627) while forwarding inputs intact to headroom_inner (:706).
  • helios/src/runtime_core/memory.rs: Adds max_sequence_pages: std::num::NonZeroU64 to PlannedHostBudgets (:34, :1602), guards both page_tokens == 0 and context == 0 inside fn max_sequence_pages (:562-569, called at :1007 after the > 0 filter at :1004), passes Some(max_sequence_pages) to initial headroom_with_inputs_for_budget without double-clamping minimum_pages (:1141-1143), and clamps pages.min(max_sequence_pages.get()) in capture_growth (:1497) and planned_offload_host (:1563-1566).
  • helios/src/runtime_core/model.rs: Threads Some(planned.max_sequence_pages) from allocate_caches into prepare_offload (:1047-1053, :1125) and directly into PrepareInputs (:1172), removing duplicate server_config["max_sequence_tokens"] parsing.
  • docs/prefix-cache-offload.md: Updates the pool-only capture buffer section (:1593-1609) to document the min(GPU page capacity, ceil(max_sequence_tokens / page_tokens)) chain cap and capped minimum-capacity startup failure behavior.
  • Tests (selene/src/offload/tests.rs, helios/src/runtime_core/memory.rs, and existing fixtures): Folds (512, NonZeroU64::new(64)) into pool_only_sizes_registered_capture_and_headroom_for_local_ranks (selene/src/offload/tests.rs:531-574), adds pool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages covering zero-input errors, ceiling division, and pages == uncapped_pages parity (memory.rs:2452-2476), and sets max_sequence_pages: None across existing PrepareInputs / prepare_offload test fixtures.
Merge Risk: Low · up to f26d8a8
Pre-merge checks: ✅ 3 passed · ⚠️ 1 warnings

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

Why
Pool-only prefix-cache offload (`--prefix-cache-pool` with zero `--prefix-cache-memory` and no local disk tier, added in PR NVIDIA#455) registers a CPU-readable capture buffer sized to hold one full checkpoint chain plus one row of slots. Currently `headroom_inner`, `capture_growth`, and `planned_offload_host` pass the entire GPU KV page capacity as that chain length. On large-VRAM GPUs or long-context quantized models where the GPU cache holds several full-context sequences, sizing the capture buffer to total GPU page capacity multiplies host RAM demand by the KV-to-context ratio and either throttles allocated GPU KV pages or triggers the startup error `host budget cannot hold a full pool capture` noted in PR NVIDIA#455's review. Because no single captured sequence chain can exceed `max_sequence_tokens`, bounding the chain to `min(GPU page capacity, ceil(max_sequence_tokens / page_tokens))` suffices while preserving the existing `intake_slots` floor for concurrent transfer bursts.

What changed
1. Add `pub max_sequence_pages: Option<NonZeroU64>` to `PrepareInputs` in `selene/src/offload.rs` (keeping `None` uncapped for callers that omit a sequence limit) and clamp `headroom_inner`'s `chain_pages` via `max_sequence_pages.map_or(pages, |limit| pages.min(limit.get()))`.
2. In `helios/src/runtime_core/memory.rs`, enforce both a positive `max_sequence_tokens` ceiling and a positive `contract.cache.page_tokens` size (via `max_sequence_pages(context, page_tokens)`) before dividing under all `--kv-cache-limit` modes (including `memory`, where `page_ceiling` returns early), compute `max_sequence_pages: NonZeroU64`, pass it into `headroom_with_inputs_for_budget`, share `capture_chain_pages(pages, max_sequence_pages)` between `capture_growth` and `planned_offload_host`, and return `max_sequence_pages` through `PlannedHostBudgets`.
3. Accept `max_sequence_pages: NonZeroU64` in private `NativeModel::prepare_offload` (`helios/src/runtime_core/model.rs`) from `PlannedHostBudgets` instead of recomputing from `server_config`, keeping planning and attach paths consistent.
4. Update the pool-only sizing specification in `docs/prefix-cache-offload.md` to document the single-sequence ceiling.
5. Thread `max_sequence_pages: None` through existing `PrepareInputs` test fixtures and `NonZeroU64::MIN` through `prepare_offload` test callers, add capped coverage inside `pool_only_sizes_registered_capture_and_headroom_for_local_ranks` (`selene`), and add `pool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages` (`helios`) covering zero-input validation, ceiling rounding, capture exhaustion without clamping, shared `capture_chain_pages` clamping, and exact parity with uncapped `capacities`.

Claimed benefit
In pool-only mode (`--prefix-cache-memory 0`), the capture chain term stays bounded to one `max_sequence_tokens` chain plus one row's slots instead of scaling with total GPU KV page capacity. For a 1,048,576-token context core on a 96 GiB SM120 workstation GPU (`99,008` KV pages, `~748 KiB`/page record, `91` row slots, `64` tokens/page), the capture buffer drops from `99,099` slots (`~70.7 GiB`) to `16,475` slots (`11.8 GiB`, a `6.0x` reduction) while preserving all `99,008` GPU KV pages (`70.9 GiB`).

Evidence
All six workspace crates pass in release mode under `RUSTFLAGS="-D warnings"` inside `rust:1.94.1-slim-trixie` at this tree (`eos -- --test-threads=1`: 12 passed; `selene --features test-support`: 649 passed; `selene-manager --features test-support`: 448 passed, 1 ignored across 15 binaries including `rank_processes`; `helios --features runtime-core,server`: 2,041 passed, 88 ignored with 7 CI recipe templates prepared; `flare`: 255 passed, 4 ignored; `flare-cli`: 254 passed, 3 ignored). Hardware CUDA tests (`FLARE_RUN_CUDA_TESTS=1`), integrated-memory hosts, multi-host suites, Windows native tests, and Kani/TLA+ runs were not executed against this tree; live Qwen4-35B-A3B `11.8 GiB` startup and container RSS measurements were observed on a `v0.6.0` (`f705086`) build carrying this sizing rule.

Signed-off-by: fakoli <fakoli@users.noreply.github.com>
Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
@fakoli
fakoli force-pushed the fix/bound-pool-only-capture-slab branch from f26d8a8 to 5021b7a Compare December 5, 2026 10:30
@fakoli

fakoli commented Dec 5, 2026

Copy link
Copy Markdown
Author

Applied the follow-up polish and test-coupling cleanups (5021b7a):

  • Non-optional private attach (helios/src/runtime_core/model.rs): Changed private NativeModel::prepare_offload to take NonZeroU64 directly from PlannedHostBudgets::max_sequence_pages instead of Option<NonZeroU64> (keeping Option<NonZeroU64> on PrepareInputs for selene callers).
  • Single non-zero check & NonZeroU64 imports (helios/src/runtime_core/memory.rs, selene/src/offload.rs): Imported NonZeroU64, validated max_sequence_tokens as NonZeroU64 once at lookup time, and replaced the unreachable Option conversion in max_sequence_pages with .expect(...).
  • Shared capture-chain helper & sharper tests (helios/src/runtime_core/memory.rs): Extracted capture_chain_pages(pages, max_sequence_pages) shared by capture_growth and planned_offload_host, and updated pool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages to call capture_chain_pages directly and assert capture_growth(&layout, 512, reserved, 0, 1) == None alongside the bounded Some(0) case.
  • Doc comment precision (selene/src/offload.rs): Clarified PrepareInputs::max_sequence_pages doc comment to name headroom_inner and page units.
  • Re-verified all six workspace crates in --locked --release under RUSTFLAGS="-D warnings" (3,659 passed, 0 failed, 96 ignored; see updated PR Evidence).

@flare-autobot

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

Commit 5021b7a cleanly addresses the remaining optional polish from Round 3 with no regressions: private NativeModel::prepare_offload takes NonZeroU64 directly, max_sequence_tokens is parsed as NonZeroU64 once at lookup with page_tokens == 0 guarded before div_ceil, and capture_chain_pages is shared across capture_growth and planned_offload_host. All production sizing paths agree on min(GPU page capacity, ceil(max_sequence_tokens / page_tokens)), and no verified correctness, hot-path, or contract defects remain.

  • Blockers: 0 · Should fix: 0 · Subtract/Simplify: 0 · Nits: 0
Walkthrough
  • selene/src/offload.rs: Imports NonZeroU64 (:14), adds pub max_sequence_pages: Option<NonZeroU64> to PrepareInputs (:343-346), clamps chain_pages in headroom_inner via inputs.max_sequence_pages.map_or(pages, |limit| pages.min(limit.get())) (:166-168) while preserving intake_slots and the chain > budget admission error (:176-181), and destructures with .. in prepare_with_inputs_budget_with_progress (:628) while forwarding inputs intact to headroom_inner (:707).
  • helios/src/runtime_core/memory.rs: Imports NonZeroU64 (:10), adds max_sequence_pages: NonZeroU64 to PlannedHostBudgets (:35, :1606), validates max_sequence_tokens as NonZeroU64 once at lookup (:1006-1010) and contract.cache.page_tokens > 0 inside max_sequence_pages(context, page_tokens) (:563-568, called at :1012), passes Some(max_sequence_pages) to initial headroom_with_inputs_for_budget without double-clamping minimum_pages (:1146-1148), and shares capture_chain_pages(pages, max_sequence_pages) (:676-678) across capture_growth (:1502) and planned_offload_host (:1568).
  • helios/src/runtime_core/model.rs: Imports NonZeroU64 (:19) and threads planned.max_sequence_pages directly into private NativeModel::prepare_offload(..., max_sequence_pages: NonZeroU64) (:1047-1053, :1125) and into PrepareInputs (:1172), updating the two early-returning prepare_offload unit tests to pass NonZeroU64::MIN (:1562, :1574).
  • docs/prefix-cache-offload.md: Documents the single-sequence capture chain ceiling min(GPU page capacity, ceil(max_sequence_tokens / page_tokens)) plus one row's slots and the capped minimum-capacity startup failure behavior (:1593-1609).
  • Tests (selene/src/offload/tests.rs, helios/src/runtime_core/memory.rs, and existing fixtures): Folds (512, NonZeroU64::new(64)) into pool_only_sizes_registered_capture_and_headroom_for_local_ranks (selene/src/offload/tests.rs:531-575), adds pool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages covering page_tokens == 0 rejection, ceiling rounding, capture_growth exhaustion above max_pages (None vs Some(0) via capture_chain_pages), and pages == uncapped_pages parity (memory.rs:2456-2490), and sets max_sequence_pages: None across existing PrepareInputs fixtures.
Merge Risk: Low · up to 5021b7a
Pre-merge checks: ✅ 3 passed · ⚠️ 1 warnings

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:memory Memory budgets, allocation lifetimes, scratch sharing, and capacity. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. area:selene Selene shared prefix-cache pool, protocol, manager, and transfers. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants