Skip to content

load: read ahead of the card upload, split planes into the upload slot, a load A/B runner - #971

Merged
midagedev merged 9 commits into
mainfrom
cflra2
Oct 29, 2026
Merged

midagedev merged 9 commits into
mainfrom
cflra2

Conversation

@midagedev

Copy link
Copy Markdown
Owner

The model load reads ahead of the card upload, and block formats split into their planes straight into the upload slot.

What changes

  • threads: a helper scope closes its workers when the body panics; a float caller runs the body beside them.
  • gpu: planes.rs is the one owner that splits Q8_0, NVFP4, MXFP4, MXFP8 and FP8_B128 file bytes into planes, written straight into the upload slot (upload.rs copy_split).
  • gpu, placement: read_ahead.rs reads the next segments ahead of the copy (16 helpers, MADV_POPULATE_READ, 8 MiB chunks, a 1 GiB window). A plan with no churn pool walks its host set beside the upload.
  • tools/ref/evict.sh owns dropping a model's shards from the page cache. tools/ref/load-ab.sh times a load's phases, base against new, under the lease, cold or warm. Its self-test runs in card-tests because the runner calls lease_take.
  • tools/gpu-gate.sh: each gate run uses a private hard link of the binary. A concurrent cargo re-link can no longer delete the image a run has mapped (rc 73 when the link fails).

Evidence

load-ab.sh, DeepSeek V4.1 plan (a), RTX A6000, cold page cache, 3 rounds (card docs/cards/cflra-load.card):

  • upload_s 13.42 s → 9.31 s, −30.6 % ± 1.4
  • load_s 48.90 s → 43.07 s, −11.9 % ± 8.7
  • warm restart upload_s 10.88 s → 8.09 s, −25.7 % ± 6.8 (cflra-load-warm.card)

The card predicted −78..−60 %. The term that was wrong is the base upload rate: measured 3.33 GB/s, against 0.85-2.7 GB/s assumed.

Fixture-tier landing batch: DONE total=238 red=0. Static tier (just remote-static origin/main): rc 0. Rebased on main 7163db3; no file overlaps the new main commits.

AI use: Claude wrote the code and this text; the maintainer reviewed it and ran the gates.

🤖 Generated with Claude Code

midagedev and others added 9 commits October 29, 2026 21:04
…a float caller runs the body beside them

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…raight into the upload slot

planes.rs de-interleaves Q8_0, NVFP4, MXFP4, MXFP8 and FP8_B128 in one place; upload.rs's copy_split writes the
planes into the pinned slot, and mxfp4::repack and q8f32's e4m3 planes call it. A test holds every format, whole and
in slot pieces, to the scalar splitter it replaces.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…plan with no churn pool walks its host set beside the upload

Helpers read the file bytes of the segments after the one being copied (MADV_POPULATE_READ in 8 MiB chunks, a 1 GiB
window), so the upload waits on the drive's rate, not on page faults; a failed read or a range outside the mapping is
a named error. A plan whose residency holds no churn pool starts the host set's walk right after the plan, beside the
context and the upload, and joins it before the body; LoadTimes.host_set is that join's wait. V4.1, plan (a), A6000,
cold page cache, 3 rounds (tools/ref/load-ab.sh, docs/cards/cflra-load.card): card upload 13.42 s -> 9.31 s
(-30.6 % +/- 1.4), whole load 48.90 s -> 43.07 s (-11.9 % +/- 8.7). No kernel moved (canon-check: 1750 of 1750
entries identical).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e; depth-qwen3moe.sh sources it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the lease, cold or warm

One start per arm per round to its first `load phases` record, the order rotated every round; a cold arm drops every
shard from the page cache first and fails by name when more than 1 % stays resident. Each ROW carries the record's
fields and the start's majflt, Cached and pgpgin; the end prints each field's paired effect and its interval. A card is
required, as every runner's. `--self-test` runs with stubs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uild cannot delete its image

A build re-links target/release/<bin> (removes it and links it again) even when the bin is fresh. A run that mapped
the shared name then fails at start: cuda-oxide's anchor loader re-opens its mapped image by path. After every lock
is held, the run hard-links the binary as .<NAME>.run.<pid> in the same directory (current_exe().with_file_name
still finds its siblings) and runs that; the EXIT trap removes it, and the next run of that name removes a link whose
pid is gone. A link that cannot be made ends the run with 73, named, never a run from the shared path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ner calls lease_take

check-recipes named it directly, so gate-batch's walker refused check-scripts as a timed recipe.
depth-serve.sh's self-test runs there for the same reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@midagedev
midagedev merged commit af1be29 into main Oct 29, 2026
10 checks passed
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 29, 2026
@midagedev
midagedev deleted the cflra2 branch October 29, 2026 14:29

@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: MUST_FIX: valid uploads can fail, and runner error paths can corrupt comparisons.

Must fix

1. Keep wide rows uploadable

crates/gpu/src/upload.rs:207 Calling upload_file_tensor (weights.rs:1430) with a valid one-row Q8_0 tensor, k=262144, needs 278528 bytes per row [derived]. Its ring budget produces 262144-byte slots, so this check rejects it. The layout accepts this width; the previous uploader streamed both planes across slots.
Handle this boundary now so every loader keeps its supported shapes. Replace the per_piece assignment with a packing fallback:

let per_piece = match planes::piece_rows(format, row_recs, slot_bytes) {
    Some(n) => n,
    None => {
        let file: Vec<u8> = src.iter().flat_map(|s| s.iter()).take(take).copied().collect();
        let mut packed = vec![0u8; take];
        planes::fill_piece(format, row_recs, 0, &file, &mut packed).map_err(shape)?;
        let (c, h) = packed.split_at(rows * code_row);
        self.copy_bytes(stream, codes, &[c], c.len())?;
        return self.copy_bytes(stream, heads, &[h], h.len());
    }
};

2. Wait for the surviving process group

tools/ref/load-ab.sh:147 bounded_bg_get PID returns timeout's PID. After cleanup kills timeout, a model stuck in uninterruptible I/O can remain in its group. Checking only the reaped monitor skips the wait and starts the next arm while the old model still holds memory and the lease.
Reuse group_live now to keep failed cleanup from contaminating later rounds. Replace the stop/wait block:

  if alive "$pid"; then
    [ "$seen" = 0 ] || sleep "$RECORD_GRACE" 9>&-
    if ! bounded_bg_stop; then
      echo "load-ab.sh: cleanup incomplete; waiting for group $pid" >&2
    fi
  else
    bounded_bg_wait
  fi
  k=0
  while :; do
    local live
    live=$(group_live "$pid") || {
      echo "load-ab.sh: cannot read process group $pid" >&2
      exit 70
    }
    [ -n "$live" ] || break
    [ "$k" -lt "$UNMAP_WAIT" ] || {
      echo "load-ab.sh: process group $pid survived cleanup" >&2
      exit 70
    }
    sleep 1 9>&-
    k=$((k + 1))
  done

3. Check the parser's status before eval

tools/ref/load-ab.sh:165 If Python fails with no stdout after a successful arm or warm-up, eval "" succeeds and the previous global LOAD_S and phase values remain. The failed parse becomes a successful row in RECS and enters the means. An empty producer returning 1 reproduces the status loss (escape C1).
Fix this before using the runner's comparisons as evidence. Replace this line with:

  local parsed
  if ! parsed=$(python3 -I "$HERE/../bloomery/records.py" sh --bin "$BIN_NAME" "$out" "${specs[@]}" 2> "$WORK/records.err") || ! eval "$parsed" || [ -z "${LOAD_S:-}" ]; then

Non-blocking

⚠ Test retirement during an active read: crates/model/src/placement/read_ahead.rs:136. The current test waits for reads before retiring them. Hold a helper inside the adviser and assert retirement waits for its release. Removing the running-job wait must turn that assertion red.

Checked

Duplicates: Dryer reported 0 candidate pairs; crates/gpu was excluded.
Complexity: diagnostics report placed_pre 18→23 and load_segments 13→17. Growth alone is not a finding.
Silent failure: parser status loss reaches RECS and effects (item 3).
Tests: in-memory shell stubs reproduced stale parser values and cleanup continuing with a surviving group member. The inline parser replacement rejects the failed producer and passes bash -n. The read-ahead test does not hold a helper inside its adviser during retirement.
Gates: no build or GPU gate ran during validation. The findings concern load time and tooling.
Escapes: C1 matches item 3.

Notes

Validation used source reads, shell stubs and sizing arithmetic. The PR body omits the nvidia-smi line, complete gate commands/output and FAIL-first evidence.

Card check: needs-gpu. This pull request changes crates/gpu/src/lib.rs, crates/gpu/src/model.rs, crates/gpu/src/mxfp4.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)

Comment thread tools/ref/load-ab.sh
fi
specs=("LOAD_S=load.load_s")
for ph in "${PHASES[@]}"; do specs+=("P_$ph=load_phases.${ph}_s"); done
if ! eval "$(python3 -I "$HERE/../bloomery/records.py" sh --bin "$BIN_NAME" "$out" "${specs[@]}" 2> "$WORK/records.err")" || [ -z "${LOAD_S:-}" ]; then

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.

Check Python's exit status before eval so a failed parse cannot reuse the preceding arm's values.

Suggested change
if ! eval "$(python3 -I "$HERE/../bloomery/records.py" sh --bin "$BIN_NAME" "$out" "${specs[@]}" 2> "$WORK/records.err")" || [ -z "${LOAD_S:-}" ]; then
local parsed
if ! parsed=$(python3 -I "$HERE/../bloomery/records.py" sh --bin "$BIN_NAME" "$out" "${specs[@]}" 2> "$WORK/records.err") || ! eval "$parsed" || [ -z "${LOAD_S:-}" ]; then

@github-actions github-actions Bot added the needs-gpu Changes code a card must check, and carries no gate run on a card label Oct 29, 2026
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 host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset 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 tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant