Skip to content

gpu: shrink a part read run to the live host reading instead of refusing - #870

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fix-parts-readahead-live
Oct 27, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fix-parts-readahead-live

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

체크포인트 폴더를 읽을 때 남은 호스트 메모리가 병렬 part 읽기 묶음보다 조금 작으면, 거절하지 않고 그 여유에 맞게 묶음을 줄여 읽도록 고칩니다.

What and why

Loading a checkpoint folder on a DGX Spark can stop with parts::load: part read-ahead needs N B, the host has M B available although the model fits. LoadPlan::checked_runs in crates/gpu/src/parts.rs read each planned run of parts at its planned size and refused the run as soon as the live host reading (MemAvailable, read just before the run) was below it, even by a little. GB10 has unified memory, so the card upload and the page cache lower that reading during the load, and more so right after another process has freed or taken memory. With nvidia/Qwen3.8-Flash-Next-FP4-Local the planned run was 36637682020 B and the reading 34983829504 B.

Now checked_runs reads the live value before each run and applies the existing model::part::read_ahead to the parts that remain, with the live value as the room. When the reading covers the planned run, read_ahead returns the whole run and nothing changes. When it does not, the run is cut to the leading parts that fit, and the reading is taken again before the next run, down to one part at a time. A single part over the reading is refused with the same message as before. Each run that is cut prints one line to stderr:

parts::load: a read-ahead run of N parts needs X B, the host has Y B available; it reads in smaller runs

LoadPlan::check, which runs before any read, now refuses on the serial peak (the largest single part plus the upload ring, new field serial_bytes) instead of the planned peak, because a load can finish at that size. LoadPlan::host_bytes, which the placed caller reserves in its host need, is unchanged. Every run is still no larger than the reading taken just before it, so the load still refuses where it would have run out of memory.

Release notes: Fixed: a checkpoint-folder load no longer stops when the free host memory falls a little below a planned read run; it reads the parts in smaller runs.

Code shape

  • No second copy. The cut reuses model::part::read_ahead, and the serial peak comes from the same function with no room. The change adds no new function.
  • Model code holds only architecture facts. No model code changes.
  • Dead code is gone. Nothing was made unused.
  • No silent failure. A failed live reading and a part that does not fit are both a refused error with the byte counts; each cut run prints its line.
  • Comments state what is true now.
  • No relaxed gate. The test case that asserted a refusal at a reading just under a planned run is replaced, because that refusal is the behavior this PR changes. The refusal for a single part over the reading is still asserted. No band or pin moves.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. cargo fmt -p bloomery-gpu --check is clean; I did not run clippy.

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

What I ran

Base 0df4076ef29b8b6f193d3c2d63c44f78350681dc (main), head a266c556c848fb4a370b40b362542a7b60e7ac03. The runs below were taken on the same change before its last rebase, on main at 95a483fc2. None of crates/gpu/src/parts.rs, crates/model/src/part.rs, crates/gpu/src/model.rs or crates/gpu/src/upload.rs differs between that main and the base above.

Unit tests, on an RTX 5090 machine (I do not have its nvidia-smi output saved):

bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- --include-ignored parts::tests
test parts::tests::later_reads_use_their_own_peak_under_a_falling_host_room ... ok
test parts::tests::hw_a_parts_load_refuses_a_short_host_before_reading ... ok
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 426 filtered out; finished in 15.23s

The changed test, later_reads_use_their_own_peak_under_a_falling_host_room, now covers a reading under a planned run (199 MiB against a 200 MiB run, which reads as two runs of one part), the new check bound (288 MiB) and the refusal of a part alone over the reading.

Reproduction on a DGX Spark with nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6:

bloomery-serve -m <model> --host 127.0.0.1 --port 18741 --parallel 1 --ctx-size 33024

with BLOOMERY_DRAFT=off, and a second process that takes 16 GiB about nine seconds into the load, after the host-need line has printed.

Base (main at 95a483fc2), exit 1:

bloomery-serve: parts::load: part read-ahead needs 36637682020 B, the host has 34983829504 B available

Head, same conditions, starts and answers the same prompt with the same text as the head without the extra process ( Paris. The capital of Germany is Berlin. The capital of Italy is Rome.):

parts::load: a read-ahead run of 95 parts needs 37170050252 B, the host has 35117322240 B available; it reads in smaller runs
parts::load: a read-ahead run of 78 parts needs 36489689144 B, the host has 29003296768 B available; it reads in smaller runs
parts::load: a read-ahead run of 80 parts needs 36496462860 B, the host has 24100417536 B available; it reads in smaller runs
parts::load: a read-ahead run of 46 parts needs 26102196784 B, the host has 19147472896 B available; it reads in smaller runs

Head without the extra process prints no parts::load line.

Load time on the normal path, to check that the change adds no cost when no run is cut. Median of three rounds after one lead-in round, FP4-Local with draft off, base 95a483fc2 against the same change:

Metric Base Head Difference Ranges overlap
load, cold page cache (s) 77.76 78.34 +0.58 s (+0.75%) yes
load, warm page cache (s) 77.52 77.14 -0.38 s (-0.49%) yes

The smallest effect these runs resolve is 4.53% for the cold load and 0.70% for the warm load, so the table shows no difference beyond noise. This run used a 16896-token context, not the 33024 of the reproduction; no run is cut on this path, so the reads are the same.

just gate-gpu-lib not run: the unit tests above cover parts::tests only, and a maintainer runs the selected gates on the workstation. I did not run just contrib-check --tier t0 or the clippy ratchet.

Hardware

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |

One DGX Spark running the reproduction and the load times above. bloomery-serve was built for sm_121a. The unit 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 needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 27, 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: every failure path I built for the shrunk read runs is blocked by the code or by a test.

Non-blocking

⚠ The cut-run line has no test: crates/gpu/src/parts.rs:167. Dropping the eprintln! or its n < left.len() filter turns no assertion red. The line is the only sign to the user that a run was cut, and the PR body promises it. This is acceptable because stderr is hard to assert; consider it only if a cheap seam exists.

Checked

  • Duplicates: 0 new functions, 2 new fields (costs, serial_bytes) and 1 closure (with_ring) checked. The cut reuses model::part::read_ahead at crates/model/src/part.rs:166; no second copy of that logic. dryer: 0 pairs.
  • Complexity: crapper flagged no function.
  • Silent failure: 5 sites followed. A live-reading error, a read_ahead error and a part alone over the reading all return refused with byte counts. read_ahead on a non-empty slice always returns n >= 1, so left always shrinks and the iterator cannot loop. A failed available() leaves left unchanged, and load_plan stops at the first Err through run?.
  • Bounds: a cut run is a prefix of its planned run, so it never exceeds the planned peak (host_bytes) the placed caller reserved. check on the serial peak matches host_bytes when every run is one part, so hw_a_parts_load_refuses_a_short_host_before_reading still holds (288 MiB).
  • Tests: mutants checked. Dropping the bytes > live guard turns the final refusal assertions red (needs 25165824 B). Using host_bytes in check turns shared.check(288 * mib) red. Wrong left.start += n turns the length and name assertions red. The [199, 199] case pins the cut.
  • Gates: no band, tolerance or pin moved. The removed case (refusal just under a planned run) is the behavior this PR changes; the PR body gives the reason.
  • Performance: load-time code only, not a hot path. The PR body carries a timed A/B on GB10 with overlapping ranges.
  • Escape catalog: C1 to C4 are shell patterns; none match.

Notes

  • Evidence: the PR body has the GB10 nvidia-smi line, both hashes and the reproduction output. It has no just gate-* run, and the unit test run on the RTX 5090 has no nvidia-smi line. A maintainer runs the gates.
  • The body says clippy was not run. CI runs the ratchet.

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.

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 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