Skip to content

Commit dad2fa5

Browse files
Reduce disk offload restore latency and integrated-memory intake overhead (#497)
Why Disk-only prefix-cache offload (`--prefix-cache-memory 0` with `--prefix-cache-disk`, default `--lossless-kv-compression off`) incurred five host and coordination costs: (1) opening a raw v1-v3 record file (`selene/src/disk.rs`) issued two sequential `O_DIRECT` reads (4 KiB header, then page checksums); (2) `xxh3` page hashing ran serially on the single disk thread across up to 64 pages (`268 MB` at `4.19 MB`/page); (3) `Staged::pump_all` (`selene/src/disk_store.rs`) submitted unlinks/truncates and outbound writes ahead of interactive restores; (4) while waiting on an inbound restore with an idle GPU, Helios's worker (`helios/src/server/runtime.rs`) slept up to `2 ms` and multi-host disk peers (`selene/src/shard.rs`) slept `1 ms` instead of waking on socket readability; and (5) on integrated-memory GPUs (`CU_DEVICE_ATTRIBUTE_INTEGRATED`), disk-only offload scaled registered host intake with concurrency (`2 * max_active * row_slots + 128`, up to `8.2 GiB` needed on `Qwen3.8-27B-NVFP4` at `--max-concurrency 16`), carving GPU KV cache out of shared RAM even though paged disk streaming stages at most two windows (`2 * (64 + row_slots)` slots). What - Single-read raw open (`selene/src/disk.rs`): preserve `#504`'s v4 packed `Header::read_metadata` open branch, and on raw v1-v3 `O_DIRECT` opens read the 4 KiB header and expected checksum segment in one transfer when `expected.tail_pages <= MAX_TAIL_PAGES` (`CHECKSUM_SCRATCH_BYTES = 1 MiB`), falling back to a 4 KiB header-only read on failure while preserving retry I/O errors, truncated-file checks, and shared scratch span helpers. - Scoped parallel page hashing (`selene/src/disk.rs`): cache `parallel_cpus` once at `Worker::new` and hash raw batches of >= `HASH_PARALLEL_MIN_PAGES` (`4`) pages across `parallel_cpus.min(MAX_HASH_THREADS).min(buffers.len())` `std::thread::scope` threads (`MAX_HASH_THREADS = 4`) when `parallel_cpus >= HASH_PARALLEL_MIN_CPUS` (`4`), with `0` idle helper threads, Linux `SCHED_BATCH` inheritance via `clone`, inline recomputation on helper spawn or unwind failure, and fault hooks folded into `Faults` under `cfg(any(test, feature = "test-support"))` (zero test-only parameters on shipped signatures). - Bounded restore-first submission and wakeup (`disk_store.rs`, `helios/src/server/runtime.rs`, `shard.rs`): order `Staged::pump_all` as inbound restores, then outbound writes, then maintenance while submitting one reserved maintenance job ahead of inbound and outbound after `MAINTENANCE_DEFER_LIMIT` (`8`) consecutive passes where queued maintenance lost free disk-queue space; poll `Worker::idle_wait` at `50 us` during active/waiting inbound restores; and wake Unix disk peers via `libc::poll` (`POLLIN`). - Bounded integrated disk-only intake & `#589` unified-memory budget integration (`selene/src/offload.rs`, `helios/src/offload/mod.rs`, `helios/src/runtime_core/{memory,model}.rs`, `docs/prefix-cache-offload.md`): pass explicit `PrepareInputs` (`max_active`, `input_staging`, `shard`, `integrated`) into `headroom_with_inputs`, `headroom_with_inputs_for_budget`, `prepare_with_inputs`, and `prepare_with_inputs_budget` (deleting unused `prepare` and dead `core: &Path`), unify `disk_enabled()`, `headroom_inner`, private `target_intake_slots`, and parameterless `Prepared::intake_warning()` (`required_intake` + `sized_concurrency`), preserve `options.pool_only()` so a degraded disk directory under `--prefix-cache-pool --prefix-cache-memory 0` remains restore-only against `#589`'s `planned_offload_host`, and target `intake_slots(layout, 1)` (`2 * (64 + row_slots)`) on integrated disk-only hosts without shrink warnings across `#589`'s small-SoC headroom scaling, explicit `--memory-limit` budgets, pre-planned post-KV `planned_offload_host`, and `HOST_NUMA` split-mapping fallback while preserving `#504` lossless KV compression. No core re-export or record-format change is required. Result Live `flare run` A/B on NVIDIA GB10 (SM121) measured `#497` standalone (`cd5a366b`) against pre-`#504` `main` (`c0c4f798`) with `--prefix-cache-memory 0 --prefix-cache-disk /tmp/selene-disk` and default `--lossless-kv-compression off` (the raw v3 `.ckpt` path, whose default GB10 disk-only execution is unchanged by rebasing onto `ba3afb13` / `#589` because GB10 128 GiB exceeds the 16 GiB small-SoC threshold and disk-only intake targets the same two-window floor; ingress-to-first-token TTFT; bandwidth is rank-0 `flare_host_cache_inbound_bytes_per_second`): - `Qwen3.8-27B-NVFP4` (TP1, `--max-concurrency 16 --prefix-cache-disk-limit 40G`, 3 interleaved repeats): intake drops `7.3 GiB` (`1,877` slots, shrink warning) -> `1.0 GiB` (`252` slots, `0` warnings), raising GPU KV cache `64.4 -> 71.6 GiB` (`+7.2 GiB` / `+235.5K` tokens); median single-restore bandwidth and TTFT improve `7.05 -> 8.02 GB/s` (`348.0 -> 301.7 ms`, `-13.3%`; wall `353.5 -> 306.5 ms`) at `30.0K` and `6.28 -> 8.68 GB/s` (`+38.2%`, `551.8 -> 447.6 ms`, `-18.9%`; wall `561.7 -> 455.4 ms`) at `61.1K`; `#497` standalone 8-way `61.1K` cold-restart burst mean median TTFT drops `8,156.1 -> 6,963.4 ms` (`-14.6%`, 2 interleaved repeats; combining this change with concurrent ancestor-restore read coalescing in companion PR `#496` is unmeasured). - Isolated `std::thread::scope` `xxh3` (`cd5a366b` with `MAX_HASH_THREADS = 1` at `selene/src/disk.rs:157` and no other change vs unmodified `cd5a366b` with `MAX_HASH_THREADS = 4`, 3 interleaved repeats on `Qwen3.8-27B-NVFP4`): parallel hashing alone improves median TTFT `486.8 -> 447.6 ms` (`-8.1%`, `7.73 -> 8.68 GB/s`, `+12.3%`, faster on all 3 repeats: `[447.6, 432.7, 451.2]` vs `[479.9, 557.5, 486.8] ms`) at `61.1K` and `322.4 -> 301.7 ms` (`7.55 -> 8.02 GB/s`) at `30.0K`. `HASH_PARALLEL_MIN_PAGES = 4` and `HASH_PARALLEL_MIN_CPUS = 4` assign at least one page per thread at the 4-thread cap and leave cores for serving threads on narrow hosts (not swept separately). - `Qwen3.8-Flash-Next` (TP1, `--max-concurrency 8 --prefix-cache-disk-limit 24G`, `cd5a366b` vs `c0c4f798`): intake drops `1.9 -> 0.3 GiB` (`2,288 -> 398` slots), raising GPU KV cache `23.28 -> 24.98 GiB` (`+1.70 GiB` / `+127.0K` tokens); bandwidth improves `5.67 -> 7.05 GB/s` (`372.1 -> 355.6 ms`) at `30.0K` and `6.65 -> 8.35 GB/s` (`+25.6%`, `458.0 -> 413.8 ms`, `-9.7%`) at `61.0K`; `#497` standalone 8-way burst median TTFT drops `3,327.5 -> 3,078.5 ms` (`-7.5%`). - Expected interaction with `#589` (`ba3afb13`): on unified-memory GPUs with an explicit `--memory-limit`, disk-only intake remains bounded at `intake_slots(layout, 1)` so unlocked unified RAM expands GPU KV cache rather than concurrency-scaled staging, while warm+disk (`--prefix-cache-memory > 0`) and pool-only capture retain `#589`'s pre-planned host budget and small-SoC scaling. What it costs: up to three short-lived scoped `xxh3` helpers during >=4-page raw batches (`0` idle helpers), `50 us` `Worker::idle_wait` polling during active/waiting inbound restores (`969.9 -> 1,069.2 ms/s` `/proc/<pid>/stat` server CPU across 8-way `Qwen3.8-27B-NVFP4` bursts: `+99.3 ms/s` / ~`0.10` of 20 Grace cores combined; the `50 us` poll's CPU share and latency contribution are unisolated from scoped `xxh3` helpers), two-window serialization for concurrent unique-prefix restores and outbound stores on integrated disk-only hosts, and up to `8` passes of maintenance deferral. Companion PR (#496, concurrent ancestor-restore open and window coalescing): merge `#497` first, then rebase `#496` onto `main` so `Staged::pump_all` retains `MAINTENANCE_DEFER_LIMIT = 8` (submitting one reserved maintenance job first after `8` deferred passes) and runs `#496`'s private `host_inbound` and shared `pump_device_inbound` queues ahead of `outbound` and `maintenance`. Evidence - Rebased crate and Python checks over `origin/main` (`ba3afb13`, `#589`) on x86_64 Linux (`O_DIRECT` + `io_uring`): `selene --features test-support` (`514` lib + `1` `mixed_codec_root` integration passed, `0` warnings; also `cargo check --release` without `test-support`, `0` warnings), `selene-manager --features test-support --test client --test offload` (`85 + 2` passed, `0` warnings), `helios --features runtime-core,server --lib -- offload:: runtime_core::memory::tests runtime_core::model::tests server::runtime::phase_tests` (`144` passed, `14` GPU-only ignored, `0` warnings in touched files, covering `#497` + `#589` small-SoC, `--memory-limit`, and degraded-disk restore-only pool coexistence), and `pytest tests/preparation/test_core_boundary.py tests/test_design_review_hook.py` (`22` passed). - Prior SM121 GPU unit and live checks (at `cd5a366b`, `--lossless-kv-compression off`): `helios` `offload::` (`FLARE_RUN_CUDA_TESTS=1 --include-ignored`, `21` single-GPU SM121 tests passed; `split_pools` requires 2 local GPUs); corrupting a multi-page `.ckpt` payload on `Qwen3.8-27B-NVFP4` incremented `fetch_failed_total` (`1`), launched `0` `restore` graphs, and recomputed identical `top-5 logprobs` and tokens; under `--prefix-cache-disk-limit 6G` (`4` concurrent restores + `3` fresh `30K` stores), disk bytes peaked at `6.38 GB` (`<= 6 GiB`) and settled at `6.37 GB` with `0` `retry_abandoned` and `0` `io_error` drops (`2` normal `end_of_chain` evictions); four concurrent decode streams spilling checkpoints over 30 s on `Qwen3.8-Flash-Next` had `0` errors (`100.0 -> 95.9 tok/s`). - Not covered: live `--lossless-kv-compression` (`cpu`/`gpu`) serving, post-rebase SM121 `flare run` re-measurement, live Jetson Orin GA10B / `--memory-limit` GPU serving, isolated `50 us` `Worker::idle_wait` A/B, `#496 + #497` combined serving, multi-host RoCE serving, 2-GPU `split_pools`, discrete PCIe GPUs, Windows serving, and live warm-plus-disk (`--prefix-cache-memory > 0`) or `PooledStore` HTTP serving (`CompositeStore` + `DiskStore` CUDA transfers were covered at `cd5a366b` in `helios` `offload::`). Discord: Dooner Design-Signed-Off-By: Antigravity (Gemini 4); design-review=c3a9 Signed-off-by: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com>
1 parent 1fd5d36 commit dad2fa5

16 files changed

Lines changed: 1809 additions & 360 deletions

File tree

‎docs/prefix-cache-offload.md‎

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,29 @@ holds every rank's bytes in one process. Each disk peer uses its host's intake.
163163

164164
Automatic registered intake is additional to the warm budget whenever warm
165165
memory or local disk is enabled. It needs no setting: its slot count is
166-
`2 × max_active × row_slots + 2 × WINDOW_PAGES`, where `WINDOW_PAGES = 64`.
166+
`2 × max_active × row_slots + 2 × WINDOW_PAGES`, where `WINDOW_PAGES = 64`,
167+
except for disk-only offload (`memory = 0` with local disk enabled) on an
168+
integrated-memory device (`CU_DEVICE_ATTRIBUTE_INTEGRATED`), where intake
169+
targets two streaming windows and two continuation rows,
170+
`2 × (WINDOW_PAGES + row_slots)` (`intake_slots(layout, 1)`).
167171
The warm checkpoint budget rounds down to whole slots. If host headroom cannot
168172
hold the full intake, it shrinks toward two complete windows,
169-
`2 × (64 + row_slots)`, and one warning reports the memory needed for full intake.
173+
`2 × (WINDOW_PAGES + row_slots)`, and one warning reports the memory needed for
174+
full intake; on an integrated-memory disk-only host, the target already equals
175+
that two-window floor, so host headroom neither shrinks it nor emits a warning.
176+
Concurrent unique-prefix disk restores and concurrent outbound disk stores on an
177+
integrated-memory disk-only host share and serialize window allocations through
178+
those two streaming windows (returning `StoreOutcome::Retry(StoreReason::Queue)`
179+
only if `RECORDS_IN_FLIGHT` fills, rather than budget retries).
170180
Prepared image inputs use one eighth of the warm budget, rounded down to 4 KiB,
171181
in ordinary CPU memory; the rest holds checkpoint slots. Text-only cores use
172182
all warm bytes for checkpoints. CPU input serialization also has a separate
173183
bounded window derived from prepared image buffers, including with warm zero.
174184

175-
With zero warm memory and disk enabled, intake uses about 0.5–8 GB of host
176-
memory; the amount depends on checkpoint geometry and selected concurrency.
185+
With zero warm memory and disk enabled, intake on discrete GPUs uses about
186+
0.5–8 GB of host memory depending on checkpoint geometry and selected
187+
concurrency; on integrated-memory devices it depends only on checkpoint geometry
188+
(`2 × (WINDOW_PAGES + row_slots)` slots).
177189

178190
On an integrated-memory device, such as a DGX Spark, GPU memory and host
179191
memory are one physical pool, and the GPU prefix cache takes the
@@ -632,10 +644,20 @@ sweep by up to one max age. The manager sweeps every namespace on its store
632644
tick, using each index's own once-a-minute limit. Expiry does not apply to the
633645
GPU tier.
634646

635-
The disk thread in `selene/src/disk.rs` owns an `io_uring` ring over files
636-
opened with `O_DIRECT`,
637-
chunks transfers at 8 MiB, and computes and verifies checksums. Before accepting
638-
payload reads,
647+
The disk thread in `selene/src/disk.rs` owns an `io_uring` ring on Linux or an
648+
I/O completion port on Windows over raw v1–v3 record files opened for direct I/O,
649+
and chunks direct transfers at 8 MiB. On raw v1–v3 opens it reads the 4 KiB
650+
header and expected page-checksum segment in one direct transfer when the
651+
expected tail fits in its 1 MiB scratch buffer (`MAX_TAIL_PAGES`), retrying the
652+
4 KiB header block alone on failure so truncated-file and invalid-header
653+
diagnostics stay unchanged; v4 packed records read their variable-length
654+
directory metadata via `Header::read_metadata`. Raw page reads and writes hash
655+
64-bit `xxh3` checksums across `parallel_cpus.min(MAX_HASH_THREADS).min(buffers.len())`
656+
scoped `std::thread::scope` threads (`MAX_HASH_THREADS = 4`) when a batch holds
657+
at least `HASH_PARALLEL_MIN_PAGES` (`4`) pages and the host reports at least
658+
`HASH_PARALLEL_MIN_CPUS` (`4`) logical CPUs, keeping zero idle helper threads
659+
between batches and recomputing inline on the disk thread for any partition
660+
whose helper could not be created or unwound. Before accepting payload reads,
639661
it checks the opened file's header against the indexed record, including all
640662
layout and size fields. Changed headers cannot enlarge reads into registered
641663
slabs. A failed ring submission drains every kernel-owned buffer reference
@@ -866,10 +888,15 @@ Offload limits interference through bounded work and explicit ownership:
866888
engines through per-token latency. Batch size and stream priority alone do
867889
not bound those delays.
868890
- CPU: transfer threads sleep on event waits and channel receives; the disk
869-
thread computes checksums and submits I/O. Both use `SCHED_BATCH` with a
870-
positive nice value to reduce contention with the model worker, HTTP runtime,
871-
and frontend workers. Adding CPU affinity requires a serving-latency
872-
measurement that shows a benefit.
891+
thread submits I/O and hashes multi-page raw batches across the scoped
892+
helpers of section 2.5. On Linux, offload threads use `SCHED_BATCH` with a
893+
positive nice value, inherited by scoped hashing helpers through `clone`; on
894+
Windows, offload threads lower priority to `THREAD_PRIORITY_BELOW_NORMAL`.
895+
While an inbound restore is active or waiting and no GPU step is running,
896+
`Worker::idle_wait` polls at `50 µs` instead of `2 ms`; idle multi-host disk
897+
peers (`selene/src/shard.rs`) wait on `poll(POLLIN)` on their rank TCP socket
898+
on Unix (`1 ms` sleep on non-Unix). Adding CPU affinity requires a
899+
serving-latency measurement that shows a benefit.
873900
- Page cache: all record I/O is direct, so disk writes neither grow the page
874901
cache nor evict the core file's mappings.
875902
- Memory: every slab pool is fixed at startup and sized by the defaults in
@@ -963,9 +990,11 @@ Offload limits interference through bounded work and explicit ownership:
963990
worker, so its ids and pins are neither reused nor released.
964991
- Offload copies are bounded per issue, and offload threads run below the
965992
serving threads' priority.
966-
- Steady-state serving allocates no device memory, no pinned memory, and no
967-
threads for offload; slabs, descriptor arrays, rings, and events are created
968-
at startup, as are the cuFile registrations of the `Direct` transport design.
993+
- Steady-state serving allocates no device memory or pinned memory, and keeps
994+
persistent transfer and disk threads fixed from startup (apart from the
995+
short-lived scoped page-hashing helpers of section 2.5); slabs, descriptor
996+
arrays, rings, and events are created at startup, as are the cuFile
997+
registrations of the `Direct` transport design.
969998

970999
### 2.13 Reusable CPU inputs
9711000

@@ -1238,6 +1267,13 @@ same completion events the store produces.
12381267
before they fill. DRAM follows the free and clean floors described above;
12391268
disk uses byte-based headroom. Disk headroom includes
12401269
pending unlink and truncate bytes, which stay charged until completion.
1270+
Within each staged-transport submission pass, `Staged::pump_all` submits
1271+
interactive inbound restores ahead of outbound writes, then drains queued
1272+
unlinks and truncates while disk-queue space remains; after
1273+
`MAINTENANCE_DEFER_LIMIT` (`8`) consecutive passes where queued maintenance
1274+
lost free disk-queue space to inbound or outbound work, the next pass with
1275+
space submits one reserved maintenance job ahead of inbound and outbound so
1276+
reclamation remains bounded under sustained restore bursts.
12411277
Store, eviction, spill completion, handover completion, reconnect and hashing
12421278
progress trigger one coalesced maintenance pass per model-thread poll.
12431279
Selection is bounded by the spill and move caps, without sorting all

‎helios/src/offload/mod.rs‎

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use flare_selene::{CacheGeometry, HostStore};
2828
use crate::Result;
2929

3030
pub use flare_selene::offload::{
31-
KvCompression, PrefixCacheOffload, Preparation, Prepared, Resolved, Shared,
31+
KvCompression, PrefixCacheOffload, Preparation, PrepareInputs, Prepared, Resolved, Shared,
3232
input_memory_bytes, parse_drain_on_shutdown, parse_max_age, parse_size,
3333
};
3434

@@ -69,60 +69,30 @@ impl Binding {
6969
}
7070
}
7171

72-
pub fn prepare(
73-
options: &PrefixCacheOffload,
74-
core: &std::path::Path,
75-
identity: [u8; 32],
76-
geometry: Vec<CacheGeometry>,
77-
contexts: Vec<(usize, i32)>,
78-
) -> Result<Preparation> {
79-
prepare_with_inputs(options, core, identity, geometry, contexts, 1, 0, None)
80-
}
81-
8272
pub fn prepare_with_inputs(
8373
options: &PrefixCacheOffload,
84-
core: &std::path::Path,
8574
identity: [u8; 32],
8675
geometry: Vec<CacheGeometry>,
8776
contexts: Vec<(usize, i32)>,
88-
max_active: usize,
89-
input_staging: u64,
90-
shard: Option<(usize, usize)>,
77+
inputs: PrepareInputs,
9178
) -> Result<Preparation> {
92-
prepare_with_inputs_budget(
93-
options,
94-
core,
95-
identity,
96-
geometry,
97-
contexts,
98-
max_active,
99-
input_staging,
100-
shard,
101-
None,
102-
)
79+
prepare_with_inputs_budget(options, identity, geometry, contexts, inputs, None)
10380
}
10481

105-
#[allow(clippy::too_many_arguments)]
10682
pub fn prepare_with_inputs_budget(
10783
options: &PrefixCacheOffload,
108-
core: &std::path::Path,
10984
identity: [u8; 32],
11085
geometry: Vec<CacheGeometry>,
11186
contexts: Vec<(usize, i32)>,
112-
max_active: usize,
113-
input_staging: u64,
114-
shard: Option<(usize, usize)>,
87+
inputs: PrepareInputs,
11588
host_budget: Option<u64>,
11689
) -> Result<Preparation> {
11790
Ok(flare_selene::offload::prepare_with_inputs_budget(
11891
options,
119-
core,
12092
identity,
12193
geometry,
12294
contexts,
123-
max_active,
124-
input_staging,
125-
shard,
95+
inputs,
12696
host_budget,
12797
&registrar::CudaRegistrar,
12898
)?)

‎helios/src/offload/pool/tests.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,15 @@ fn peer_registration_budget_fails_startup() {
123123
};
124124
let mut prepared = super::super::prepare_with_inputs(
125125
&options,
126-
std::path::Path::new("model.safetensors"),
127126
[3; 32],
128127
vec![flare_selene::testing::geometry(64, &[("kv", 4096)], 4096)],
129128
vec![(0, 0)],
130-
1,
131-
0,
132-
Some((1, 2)),
129+
super::super::PrepareInputs {
130+
max_active: 1,
131+
input_staging: 0,
132+
shard: Some((1, 2)),
133+
integrated: false,
134+
},
133135
)
134136
.unwrap();
135137
let super::super::Preparation::Store(resources) = &mut prepared else {

‎helios/src/runtime_core/memory.rs‎

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,12 @@ impl NativeModel {
833833
let (device, tier_host) = options.prefix_cache.headroom_with_inputs_for_budget(
834834
self.ranks.len(),
835835
&layout,
836-
active,
837-
staging != 0,
836+
crate::offload::PrepareInputs {
837+
max_active: active,
838+
input_staging: staging,
839+
shard: self.cluster().map(|cluster| (cluster.rank, cluster.world)),
840+
integrated: integrated > 0,
841+
},
838842
capture.then_some(minimum_pages),
839843
initial_budget,
840844
)?;
@@ -1522,6 +1526,57 @@ mod tests {
15221526
),
15231527
2 * gib - 512 * mib
15241528
);
1529+
1530+
// Disk-only offload on integrated GPUs stays bounded at two streaming windows
1531+
// (`intake_slots(layout, 1)`) even when an explicit `--memory-limit` unlocks
1532+
// extra unified memory, leaving the difference for GPU KV pages, while warm+disk
1533+
// retains concurrency-scaled intake under the same explicit/SoC budget.
1534+
let geometry = vec![flare_selene::testing::geometry(64, &[("kv", 1 << 20)], 8 << 20)];
1535+
let layout = flare_selene::Layout::new(&geometry).unwrap();
1536+
let active = 16;
1537+
let bounded =
1538+
flare_selene::offload::intake_slots(&layout, 1) as u64 * layout.page_record_bytes;
1539+
let full =
1540+
flare_selene::offload::intake_slots(&layout, active) as u64 * layout.page_record_bytes;
1541+
assert!(bounded < full);
1542+
let inputs = crate::offload::PrepareInputs {
1543+
max_active: active,
1544+
input_staging: 0,
1545+
shard: None,
1546+
integrated: true,
1547+
};
1548+
let disk_only = crate::offload::PrefixCacheOffload {
1549+
memory_bytes: Some(0),
1550+
disk: Some("records".into()),
1551+
disk_limit: Some(10 * gib),
1552+
..Default::default()
1553+
};
1554+
let gb10 = MemorySnapshot {
1555+
free: 90 * gib,
1556+
total: 128 * gib,
1557+
};
1558+
let limit = Some(MemoryLimit::Bytes(100 * gib));
1559+
let initial_disk_budget = integrated_offload_host_budget(gb10, 20 * gib, limit, 0);
1560+
assert_eq!(initial_disk_budget, 80 * gib);
1561+
let (disk_dev, disk_host) = disk_only
1562+
.headroom_with_inputs_for_budget(1, &layout, inputs, None, initial_disk_budget)
1563+
.unwrap();
1564+
assert_eq!(disk_host, bounded);
1565+
let kv_budget =
1566+
limited_budget(gb10, 20 * gib, limit, HEADROOM_BYTES, true, disk_dev + disk_host)
1567+
.unwrap();
1568+
assert_eq!(kv_budget, 80 * gib - (disk_dev + bounded));
1569+
1570+
let warm_bytes = 64 * mib;
1571+
let warm_and_disk = crate::offload::PrefixCacheOffload {
1572+
memory_bytes: Some(warm_bytes),
1573+
..disk_only
1574+
};
1575+
let orin_warm_budget = integrated_offload_host_budget(orin8, 4 * gib, None, warm_bytes);
1576+
let (_, warm_host) = warm_and_disk
1577+
.headroom_with_inputs_for_budget(1, &layout, inputs, None, orin_warm_budget)
1578+
.unwrap();
1579+
assert_eq!(warm_host, warm_bytes + full);
15251580
}
15261581

15271582
#[test]

‎helios/src/runtime_core/model.rs‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::{
1616
};
1717
use crate::{Result, execution::ExecutionManifest, startup::StartupProgress};
1818
use blake2::{Blake2b, Digest, digest::consts::U32};
19-
use std::{collections::HashSet, path::Path, thread};
19+
use std::{collections::HashSet, thread};
2020

2121
pub struct NativeModel {
2222
pub(super) ranks: Vec<NativeResources>,
@@ -311,7 +311,6 @@ impl NativeModel {
311311
(descriptor, None, Some(cores), FilesRef::Payload(source))
312312
}
313313
};
314-
let root = files.path();
315314
// A multi-host core holds every rank; each host keeps only the bundle it serves, so
316315
// it never maps another rank's storage.
317316
let cluster = match (descriptor.cluster.take(), options.cluster_rank) {
@@ -915,7 +914,7 @@ impl NativeModel {
915914
&initial,
916915
embedding_host_bytes,
917916
)?;
918-
model.prepare_offload(root, options, progress, active, planned_offload_host)?;
917+
model.prepare_offload(options, progress, active, planned_offload_host)?;
919918
}
920919
Ok(model)
921920
}
@@ -924,7 +923,6 @@ impl NativeModel {
924923
/// pools, and scan its record directory.
925924
unsafe fn prepare_offload(
926925
&mut self,
927-
root: &Path,
928926
options: &LoadOptions,
929927
progress: &StartupProgress,
930928
max_active: usize,
@@ -964,15 +962,18 @@ impl NativeModel {
964962
.cluster
965963
.as_ref()
966964
.map(|cluster| (cluster.rank, cluster.world));
965+
let integrated = self.ranks.iter().any(|rank| rank.integrated);
967966
let prepared = crate::offload::prepare_with_inputs_budget(
968967
&options.prefix_cache,
969-
root,
970968
identity,
971969
geometry,
972970
contexts,
973-
max_active,
974-
staging,
975-
shard,
971+
crate::offload::PrepareInputs {
972+
max_active,
973+
input_staging: staging,
974+
shard,
975+
integrated,
976+
},
976977
planned_host_budget,
977978
)?;
978979
phase.finish(self.attach_offload(prepared)?);
@@ -1318,9 +1319,7 @@ mod tests {
13181319
..Default::default()
13191320
};
13201321
unsafe {
1321-
model
1322-
.prepare_offload(Path::new("unopened-core"), &options, &progress, 1, None)
1323-
.unwrap();
1322+
model.prepare_offload(&options, &progress, 1, None).unwrap();
13241323
}
13251324
assert!(model.offload.shared().is_none());
13261325
}
@@ -1331,9 +1330,7 @@ mod tests {
13311330
},
13321331
..Default::default()
13331332
};
1334-
let error =
1335-
unsafe { model.prepare_offload(Path::new("unopened-core"), &options, &progress, 1, None) }
1336-
.unwrap_err();
1333+
let error = unsafe { model.prepare_offload(&options, &progress, 1, None) }.unwrap_err();
13371334
assert!(error.to_string().contains("lacks an identity"));
13381335
}
13391336

‎helios/src/server/runtime.rs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,7 @@ impl ModelRuntime {
690690
if let Some(rank) = prepared.geometry.first() {
691691
worker_metrics.codec_placement(rank.placement);
692692
}
693-
if let Some(warning) =
694-
prepared.intake_warning(worker_config.limits.max_active)
695-
{
693+
if let Some(warning) = prepared.intake_warning() {
696694
if log_to_stderr { eprintln!("warning: {warning}"); }
697695
}
698696
crate::offload::open(prepared, gpu_cubins)
@@ -1196,6 +1194,14 @@ impl<'a> Worker<'a> {
11961194
}
11971195

11981196
fn idle_wait(&self) -> std::time::Duration {
1197+
if self
1198+
.store
1199+
.as_ref()
1200+
.is_some_and(|store| store.stats().inbound_in_flight > 0)
1201+
|| self.scheduler.stats().inbound_waiting > 0
1202+
{
1203+
return std::time::Duration::from_micros(50);
1204+
}
11991205
let now = std::time::Instant::now();
12001206
if self
12011207
.pending

0 commit comments

Comments
 (0)