Skip to content

gpu: share the serial packing reserve across a part read run - #809

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-loadtime-par
Oct 25, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-loadtime-par

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

병렬로 읽는 part 묶음이 packing 메모리 예약을 한 part 분량만 잡도록 고쳐, 모델 load의 start-to-ready 시간을 줄이는 속도 PR입니다.

What and why

A checkpoint load reads several tensor parts at once. The planner decides how many parts one read may take by adding up each part's host memory cost, and that cost was the part's read bytes plus its packing bytes, summed over the whole read. The reads of one run are alive together, but packing runs one part at a time in plan order, so only one part's packing buffers exist at any moment. Summing the packing bytes overstated the reserve, ended each read early and left more, smaller reads.

This PR charges a run the sum of its read peaks plus the largest single packing peak. Under the same host room the planner now groups more parts per read: FP4-Local plans 50 reads before and 38 after, and NVFP4 plans 39 before and 30 after.

  • read_ahead in crates/model/src/part.rs takes a (read_peak, packing_peak) pair per part instead of one cost. Its one production caller, LoadPlan::new in crates/gpu/src/parts.rs, supplies the read bytes and the packing bytes (twice the staged bytes, as before).
  • The 8 GiB payload limit, the rule that an oversized first part runs alone, the checked arithmetic, the first admission check and the per-run live-room check are unchanged. No kernel, upload order, ring, gate or pin changed.
  • Two existing tests grew. A 64 MiB part and an 8 MiB part are read together at a room of 296 MiB (read and packing of 200 MiB plus a ring of 96 MiB), and the plan is checked at that exact limit and one byte short. A smaller room still plans two runs, so a later run is checked against its own peak.

Release notes: Changed: model load groups more tensor parts per read under the same host memory room, which shortens start-to-ready.

Code shape

  • No second copy. The read grouping stays in its one owner, read_ahead, and the GPU planner calls it.
  • Model code holds only architecture facts. No model file changed, and the common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. The change adds no function, type or constant and leaves nothing unused.
  • No silent failure. Both sums still use checked arithmetic and an overflow is a named refusal.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance, lint or pin moved.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. cargo clippy on bloomery-model ran clean. bloomery-gpu needs CUDA and was not linted here, and I did not record a separate cargo fmt result.

Duplication found or removed (path:line), or "none": none.

What I ran

The metric is start-to-ready: seconds from process start to the first healthy /health response, with --parallel 4 --ctx-size 16896, BLOOMERY_HOST_ROOM=96G and the MTP draft off. The checkpoints are the FP4-Local and NVFP4 builds of Qwen3.8-Flash-Next. Each arm is three starts, main and head alternating on the same DGX Spark in one sitting, after one discarded first start per checkpoint and binary. A cold start first drops the tensor files from the page cache with POSIX_FADV_DONTNEED. A warm start first reads every file once in order.

Checkpoint / cache Main (s) Head (s) Lower start-to-ready
FP4-Local / cold 77.500 68.441 11.689%
FP4-Local / warm 79.679 72.594 8.893%
NVFP4 / cold 59.056 53.289 9.765%
NVFP4 / warm 61.798 56.668 8.300%

Start-to-ready median fell by 11.689% and 8.893% for FP4-Local cold and warm, and by 9.765% and 8.300% for NVFP4 cold and warm.

Each figure is the median of the three starts. In every row the three head starts are all faster than the three main starts, so the ranges do not overlap. For both checkpoints the card bytes read back after load have the same SHA-256 on main and head, and a 128-token greedy generation returns the same content and token count. No out-of-memory error or admission refusal appeared in any run. Each read now fills more of the same room, so the largest reserve of a single read is a little higher than before and stays within the room.

GPU Evidence

The card and driver of the DGX Spark that ran the BF16 gate:

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |
just gate-gpu-bf16
gpu-gate.sh: gate_bf16 ran 3 s (exit 0)

The gate printed 309 PASS lines.

On an RTX 5090 machine:

cargo oxide test --arch sm_120 -- --release -p bloomery-gpu --lib later_reads_use_their_own_peak_under_a_falling_host_room -- --nocapture
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 419 filtered out; finished in 0.00s
cargo test --release -p bloomery-model --lib a_read_takes_the_parts_that_fit_and_at_least_one -- --nocapture
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 540 filtered out; finished in 0.00s

Before the change, the new assertion in the first test fails against the old planner (exit code 101). The all-targets check of the workspace also finishes:

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 44.74s

Not run: the full bloomery-gpu library suite and a PTX comparison (no kernel or launch changed).

Hardware

Timings and the BF16 gate ran on DGX Spark machines (GB10, driver 595.84, CUDA 13.3 on the gate machine). The two regression tests ran on an RTX 5090 machine.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 25, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: The shared packing reserve matches the serial staging lifetime; no must-fix defect was found.

Non-blocking

⚠ Complete the hardware evidence: crates/gpu/src/parts.rs:185. The gate and timing reports omit the tested commit hashes. The timings also lack exact checkpoint paths and benchmark commands with output. Can you attach the measurement record, including both pre-rebase hashes?

Checked

Duplicates: 0 new functions, types or constants; Grep found no second grouping owner. Dryer reported 0 pairs.
Complexity: crapper flagged no changed function.
Silent failure: 0 new default or suppressed-result sites; read errors and arithmetic overflow reach named load refusals.
Tests: static mutation review of a_read_takes_the_parts_that_fit_and_at_least_one: replacing max at crates/model/src/part.rs:184 with addition or the current part's cost fails the existing assertions.
Tests: later_reads_use_their_own_peak_under_a_falling_host_room rejects summing packing peaks: its combined-run assertion fails. Exact-room and one-byte-short checks cover admission and live-room boundaries.
Gates: no pins, tolerances or coverage clauses removed; changed expectations enforce the new accounting.
Adversarial: concurrent reads retain their summed reserve; serial packing and ring-owned copies prevent packing overlap. Empty runs, oversized first parts, falling room and overflow remain guarded.
Performance: load-time planning only; no decode, prefill or kernel path changed.
Escape catalog: no C1–C4 pattern matched.

Notes

Dryer did not scan crates/gpu; the changed GPU code was searched manually.
No Rust or GPU tests were run here; test assertions were checked statically.

Card check: needs-gpu. This pull request changes crates/gpu/src/parts.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 6de9e77 into midagedev:main Oct 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant