Repository navigation
helios: overlap startup allocation, registration, and setup with runtime-sized zero-copy weight loading - #726
original-el8 wants to merge 1 commit into
Conversation
…ime-sized zero-copy weight loading Model startup previously executed memory allocation, weight loading, kernel and graph preparation, cache allocation, host prefix cache setup, and tokenizer loading strictly in series. On large models—especially host-tiered cores that allocate and register hundreds of gigabytes of mapped host memory—the NVMe storage array sat idle during single-threaded host pre-faulting and `cuMemHostRegister_v2`, while the GPU sat idle during host weight reads and subsequent CPU/CUDA setup. In addition, the payload loader used fixed `SLOTS = 4, READERS = 4, CHUNK = 4 MiB` staging (preventing full double-buffering between `pread` and `cuMemcpyHtoDAsync`) and copied every `MappedHost` weight byte through pinned CUDA staging buffers instead of reading 4 KiB-aligned ranges directly into mapped host memory. What changed: - `helios/src/runtime_core/payload.rs`: replaced fixed staging constants with a runtime `IoPlan` (`choose_io_plan`) derived from CPU count, rank count, Linux block-device `optimal_io_size` (with non-Linux fallback), and available host memory, double-buffering `SLOTS = 2 * READERS` within a bounded staging cap (`<= 128 MiB` across ranks). Added zero-copy `O_DIRECT` reads directly into 4 KiB-aligned `MappedHost` ranges (splitting matching-alignment spans into staged edges and direct interior chunks), separated CUDA-free host payload loading (`load_mapped_host_chunks`) from device payload loading (`load_device`), and added `RegistrationGate` to coordinate chunked host pinning with host `O_DIRECT` readers. - `helios/src/runtime_core/mod.rs` and `helios/src/runtime_core/format.rs`: split `allocate()` into device allocation (`allocate_device`) and coalesced/THP-hinted mapped-host VMA preparation with ordered multi-threaded 2 MiB pre-faulting (`prepare_mapped_host_vmas`, holding no CUDA context locks) so host VMA setup overlaps with device weight uploads. Pipelined `cuMemHostRegister_v2` in `512 MiB`-aligned chunks via `register_pending_mapped_host` (tracked in `host_mmap_spans` and `host_registrations` separately from `host_vmm` `host_mappings`) so host pinning never contends with `cuMemcpyHtoDAsync` while preserving hugepage alignment boundaries and reverse-order teardown. - `helios/src/runtime_core/model.rs`, `helios/src/startup.rs`, `helios/src/server.rs`, `helios/src/server/config.rs`, and `helios/src/server/session.rs`: overlapped `MappedHost` VMA preparation with device weight loading, overlapped chunked `cuMemHostRegister_v2` followed by kernel, graph, embedding-table, KV cache, and host prefix cache setup with `MappedHost` weight loading (replaying completed phase records cleanly in canonical order via `StartupProgress::replay_completed`), and pre-loaded the frontend tokenizer/template on a background CPU thread keyed by immutable frontend config fields for reuse in `LoadedSession::new`. Claimed benefit and result: Measured cold startup for a 552.1 GiB host-tiered signed core (`240.5 GiB` device + `316.6 GiB` mapped host + `64 GiB` host prefix cache) on a 2x PCIe Gen4x4 NVMe RAID0 (`12.78 GiB/s` measured raw `O_DIRECT` ceiling, `43.2 s` physical I/O floor) dropped from `75.0 s` to `45.5 s` (`-29.5 s` / `-39.3%`), sustaining `12.90–13.00 GiB/s` during weight loading with `94.0 GiB` `AnonHugePages` (up from `91.0 GiB`), identical GPU/KV/prefix-cache budgets, and `0.0 s` critical-path cost for allocation, kernel/graph/cache/prefix-cache preparation, and tokenizer loading. Pure-GPU models retain exact serial post-load GPU memory accounting while gaining runtime-sized double-buffered staging and background tokenizer pre-loading. Supporting evidence and material limitations: Validated with `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib` (1919 passed, 0 failed, 49 ignored), `cargo test --locked --release --manifest-path flare/Cargo.toml` (255 passed, 0 failed, 4 ignored), `cargo test --locked --release --manifest-path flare-cli/Cargo.toml` (250 passed, 0 failed, 3 ignored), targeted `runtime-core` tests covering `IoPlan`, zero-copy aligned/unaligned `MappedHost` reads, `RegistrationGate`, `512 MiB` registration chunks, and ordered `2 MiB` pre-fault slices (6 passed, 0 failed), and `cargo build --release --manifest-path flare-cli/Cargo.toml`. Live cold startup (`75.0 s -> 45.5 s`) and streaming serving output were measured via `flare run` on 1x NVIDIA GB300 (`SM103`) on the equivalent `feat/gb300-tiered-runtime` build prior to rebasing cleanly onto `main`. Material limitations: `host_vmm` (Windows and non-identity-mapped Linux GPUs), integrated-GPU `mlock`, `async_transfers`, and multi-rank TP startup overlap paths were not executed on hardware in this change. Design-Signed-Off-By: Jason Cook; design-review=2e5b
|
A case file has been opened for 726. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedRight problem in the right shared runtime layer (
Walkthrough
Merge Risk: High · up to
|
Why
Model startup previously ran memory allocation, weight loading, kernel and graph preparation, KV cache allocation, host prefix cache initialization, and tokenizer loading strictly in series. On large models—especially host-tiered cores with hundreds of gigabytes of
MappedHoststorage—the NVMe storage array sat idle during single-threaded host pre-faulting andcuMemHostRegister_v2, while the GPU sat idle duringMappedHostweight reads and post-load setup. In addition, the payload loader used fixedSLOTS = 4, READERS = 4, CHUNK = 4 MiBstaging (preventing double-buffering betweenpreadandcuMemcpyHtoDAsync) and copied allMappedHostpayload bytes through pinned CUDA staging buffers instead of reading 4 KiB-aligned ranges directly into mapped host memory.Overlapping host VMA preparation with
Deviceweight uploads (holding zero CUDA context locks), pipelining512 MiB-alignedcuMemHostRegister_v2chunks ahead of zero-copyMappedHostO_DIRECTreads, running kernel/graph/cache/prefix-cache setup while NVMe streamsMappedHostweights, and pre-loading the frontend tokenizer on a background CPU thread removes serial startup overhead across every GPU architecture without changing package formats, execution ABIs, or memory accounting.What Changed
helios/src/runtime_core/payload.rs:IoPlan(choose_io_plan) derived from CPU count, rank count, Linux block-deviceoptimal_io_size(with non-Linux fallback), and available host memory, double-bufferingSLOTS = 2 * READERSwithin a bounded cross-rank staging cap (<= 128 MiB).O_DIRECTreads directly into 4 KiB-alignedMappedHostdestinations (splitting matching-alignment spans into staged edges and direct interior chunks), separated CUDA-free host loading (load_mapped_host_chunks) fromDeviceloading (load_device), and addedRegistrationGateto coordinate chunked host pinning with host readers.helios/src/runtime_core/mod.rsandhelios/src/runtime_core/format.rs:allocate()into device allocation (allocate_device) and coalesced, THP-hintedMappedHostVMA preparation with ordered multi-threaded 2 MiB pre-faulting (prepare_mapped_host_vmas, holding no CUDA context locks) so host VMA setup overlaps withDeviceweight uploads.cuMemHostRegister_v2in512 MiB-aligned chunks (register_pending_mapped_host), tracking Unixhost_mmap_spansandhost_registrationsseparately fromhost_vmmhost_mappingsfor clean reverse-order teardown.helios/src/runtime_core/model.rs,helios/src/startup.rs,helios/src/server.rs,helios/src/server/config.rs, andhelios/src/server/session.rs:MappedHostVMA preparation withDeviceweight loading, and overlapped chunkedcuMemHostRegister_v2followed by kernel, graph, embedding-table, KV cache, and host prefix cache setup withMappedHostweight loading (preserving exact post-registration, post-graph memory snapshots inallocate_caches()and replaying completed stage rows in canonical order viaStartupProgress::replay_completed).LoadedSession::new.Claimed Benefit and Result
Measured cold startup on 1× NVIDIA GB300 (
SM103) loading a552.1 GiBsignedAmazon-Ergocore (240.5 GiBdevice +316.6 GiBmapped host +64 GiBSelene host prefix cache) from a2× WD_BLACK SN850XPCIe Gen4×4 RAID0 (12.78 GiB/smeasured rawO_DIRECTceiling,43.2 sphysical I/O floor):Verify core+Verify stored data+Prepare model+Initialize GPU2.5 s0.6 sAllocate model memory21.2 s0.0 sLoad weights(552.1 GiB)43.9 s(12.58 GiB/s)43.8 s(12.90–13.00 GiB/ssustained)Prepare kernels+Prepare execution+Allocate cache+Prepare host prefix cache5.4 s0.0 s(overlapped)Load tokenizer0.8 s0.0 s(pre-loaded)Start server1.2 s1.1 s75.0 s45.5 s(-29.5 s/-39.3%)AnonHugePages:94.0 GiB(up from91.0 GiB); GPU/KV/prefix-cache allocations unchanged (241.16 GiBloaded,7.81 GiB/147,456live GPU KV tokens,64.0 GiBSelene).Supporting Evidence and Limitations
cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib(with generated frontend templates): 1,919 passed, 0 failed, 49 ignored, including 6 new unit tests coveringIoPlan, zero-copy aligned/unalignedMappedHostreads,RegistrationGate,512 MiBregistration boundaries, and ordered2 MiBpre-fault slices.cargo test --locked --release --manifest-path flare/Cargo.toml: 255 passed, 0 failed, 4 ignored.cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 250 passed, 0 failed, 3 ignored.cargo build --release --manifest-path flare-cli/Cargo.toml: clean release build onmain(f705086b).75.0 s -> 45.5 s) and streaming serving verification were measured viaflare runon 1× NVIDIA GB300 (SM103) on the equivalentfeat/gb300-tiered-runtimebuild prior to rebasing cleanly ontomain.PreparedContractchanges.host_vmm(Windows and non-identity-mapped Linux GPUs), integrated-GPUmlock,async_transfers, and multi-rank TP startup overlap paths were not executed on hardware in this PR.Discord: el8