Skip to content

q27: faster cold start: parallel module load, pinned weight upload, tokenizer under the weight read - #34

Merged
data-angel merged 3 commits into
q27/concfrom
q27/fast-start-20261119
Nov 19, 2026
Merged

data-angel merged 3 commits into
q27/concfrom
q27/fast-start-20261119

Conversation

@data-angel

Copy link
Copy Markdown

Summary

Cuts cold engine start for Qwen3.8-27B on one DGX Spark (SparkQwen 0.7.0 profile, release image with this binary overlaid) from 9.1–11.1 s to 7.3–8.1 s to ready, with no change to outputs. Three commits:

  • atlas-core: load the 220 kernel modules on eight threads (CUDA init 0.97 → 0.68 s). The calling thread keeps its bound context, maps are built in blob order, and the first failing blob stops the other loaders.
  • spark-runtime: plain tensors are allocated in order on the calling thread while 16 workers pread 16 MiB pieces into their own page-locked buffers and copy them on their own streams. The 18.8 GB load goes from 3.05 s to 2.5–2.7 s. CSF parts, F16 converts and failed allocations keep the old copier path and its managed-memory fallback. Linux only.
  • spark-server: rank 0 runs the tokenizer phase (~1.2 s) and the tokenizer.json vocab parse (~0.3 s) on threads during the weight read. The early result is used only if every input it read still equals the serial path's inputs; otherwise the phase runs in place as before.

Test plan

  • rustfmt --check on every touched file. cargo fmt --all -- --check still fails on DSpine-era example files already on q27/conc; none of them are touched here.
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy -p atlas-core -p spark-runtime -p spark-server --tests: clean.
  • SPDX header on every new file.
  • Unit tests:
    • spark-runtime fast_weights: 30 pass, including new pinned_upload tests and an allocation-failure fallback test.
    • spark-server tokenizer_prep: 5 pass.
  • On GB10 (spark04), fast_load_bench on nvidia/Qwen3.8-27B-NVFP4 + tandem: the digest of every resident tensor's bytes, b4b9ae18a3bd270d, matches the old loader.
  • Cold start, page cache evicted, SparkQwen 0.7.0-27b image with the binary overlaid: ready 7.3–8.1 s vs 9.1–11.1 s for the same commit without these changes.
  • Four greedy prompts (code, prose, JSON, thinking on), text and logprobs: byte-identical old vs new.
  • KV pool not reduced: 21.8–22.5 GB new vs 21.1–21.7 GB old.

Notes for reviewers

  • What's left is allocation. cuMemAlloc on GB10 runs at ~25 GB/s however many threads call it. This profile allocates ~94 GB at startup (weights, the 14 GB layer build, ~62 GB of KV, SSM pools and drafter context), so allocation, not the ~1.8 s disk read, is now the floor. Going further means allocating pools during the disk-bound weight read, which needs KV sizing moved earlier. Not attempted here.
  • Tried and dropped:
    • Two staging buffers per worker measured slower (2.7–2.9 s).
    • GDS isn't available on the Sparks (no nvidia_fs module).
  • Shared code touched: AtlasRegistry::init, used by every CUDA model, and the fast loader, used by every safetensors load.
  • An independent review pass found that the caller's CUDA context was left unbound after the parallel module load; that is fixed in the first commit.

🤖 Generated with Claude Code

data-angel and others added 3 commits November 19, 2026 07:03
Each of a target's PTX blobs is loaded twice (cudarc and raw driver), and
each load is a JIT or a JIT-cache lookup. Serially, Qwen3.8-27B's 220
blobs took ~1 s of every engine start on GB10; on eight threads the
backend is up ~0.3 s sooner. The calling thread still gets the context
bound (AtlasCudaBackend::new reads it back), the maps are built in blob
order, and the first failing blob stops the other loaders.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fast loader handed every tensor to one copier thread that copied it
from pageable memory and drained the stream before the next. On GB10 that
loaded Qwen3.8-27B's 18.8 GB in 3.05 s (6.2 GB/s) against ~10.5 GB/s of
O_DIRECT reads from the same files.

Plain tensors are now allocated in tensor order on the calling thread
while 16 workers pread 16 MiB pieces into their own page-locked buffers
and copy them on their own streams: 2.5-2.7 s, with a digest of every
resident tensor's bytes identical to the old loader. CSF scale parts, F16
converts and tensors whose allocation fails keep the copier path and its
managed-memory fallback. Linux only. Swept 4-32 workers and 8-64 MiB
pieces; two buffers per worker measured slower (2.7-2.9 s).

direct_io's pread loop is factored into aligned_window + pread_window so
both paths share it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tokenizer phase (chat tokenizer, four whole-vocabulary decode passes,
tool markers, XGrammar engine: ~1.2 s on Qwen3.8's 248K vocabulary) ran
after the model was built, and the vocab cap parsed tokenizer.json again
(~0.3 s) between the weights and the KV config. Both are CPU work that
read none of the GPU phases.

Rank 0 now starts the tokenizer phase on a thread before the weight load
and uses its result at phase 8 only if every input it read (EOS list,
vocab size after the tokenizer cap, model type, thinking support,
template fields, ServeArgs) still equals the serial path's; otherwise it
resolves in place as before. The vocab-size parse runs on a thread too.

Qwen3.8-27B on one Spark with this and the two loader changes: ready in
7.3-8.1 s from a cold page cache against 9.1-11.1 s, with greedy outputs
and logprobs identical to the old binary.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant