Skip to content

engram: coalesce row advice into distinct page runs - #661

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-prompt-gaps
Oct 22, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-prompt-gaps

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 서버의 첫 요청에서 체크포인트 슬롯 할당을 없애고, per-layer embedding 행 힌트를 서로 다른 페이지 묶음으로 합쳐 호스트 대기를 줄입니다.

Part of #565.

What and why

Two host-side gaps sit in the prompt path of the Qwen3.8 server on GB10.

  1. Checkpoint slots are pinned at load. A sequence's checkpoint slots were pinned and zeroed the first time a checkpoint needed them, so the first request paid for it in the middle of a prompt. Checkpoints::sequence now pins every slot its existing sequence budget allows when it is built, and take, open_take and adopt reuse those slots. The separate allocation code in adopt is gone. The refusal of an unfilled slot, the copy-completion rule and the save guards stay as they were.
  2. Row advice covers each page once. The per-layer embedding (PLE) prefetcher advised the kernel about its table rows one id at a time, so rows that share a page were advised repeatedly. TableBytes::page_runs now reuses adjacent_runs, merges overlapping or adjacent pages, and both advice and populate use it. No page between two disjoint ranges is added. RunTable::each groups an order-independent operation by source run, repeated ids still count repeatedly, and copy_rows keeps the request order.

No model, kernel, scheduler, precision, gate band or runtime flag changes.

On one GB10, the first request after a load had 73 pinned allocations (38.479 ms) before this change and none after it, and the PLE wait on three consecutive prompts fell from 94.630, 134.872 and 163.012 ms to 81.792, 59.164 and 59.425 ms (tables below). The checkpoint change moves that cost to load: the body phase of the load grew from 0.11 s to 0.39 s.

Release notes: Changed: on GB10, the Qwen3.8 server pins its checkpoint slots at load instead of during the first request, and groups PLE row advice by page, which cuts the host waits in the prompt path.

Code shape

  • No second copy. TableBytes::page_runs reuses adjacent_runs, and one owner serves advice and populate. The duplicate slot allocation in adopt is removed.
  • Model code holds only architecture facts. No model code changes.
  • Dead code is gone. make_slot and the lazy-allocation branches in take, open_take and adopt are removed.
  • No silent failure. Allocation errors are returned from Checkpoints::sequence. The named errors for an unfilled slot and an unfinished copy stay.
  • Comments state what is true now. The slot lifecycle and row advice comments are rewritten.
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt is clean on what I touched.

Duplication found or removed (path:line), or "none": removed the second slot allocation in crates/gpu/src/checkpoint.rs (adopt). python3 tools/dup-scan.py found no candidates in the diff.

What I ran

Head bb4c1aad4, base main 69b66367c. The timing, traces and checks below ran on 18db2ba82, the same two commits on main 6e7f43fa9. The head only rebases them (git range-diff shows both commits as equal, and the three edited files are unchanged by the rebase).

GPU Evidence

On an NVIDIA GB10:

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

just gate-gpu-lib not run: the checkpoint tests that recipe wraps ran through tools/gate.sh instead.

Running cargo test -p bloomery-gpu --release --lib -- --include-ignored checkpoint:: --skip hw_held_...
test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 371 filtered out; finished in 9.29s

These cover slot reuse, refusal of an unfinished copy, open, seal and abandon, saved state and staging. The host tests for the row advice ran on a Linux host machine:

cargo test -p bloomery-engram --lib
test result: ok. 22 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Host waits over three prompts

Three different 4096-token code windows ran back to back on the main build and on the head build, one generated token each, with no prompt-cache hit and Nsight Systems attached. The PLE wait is the time the host spent in Prefetcher::wait.

Request Main PLE wait (ms) Head PLE wait (ms) Main pinned calls (API ms) Head pinned calls
First 94.630 81.792 73 (38.479) 0
Second 134.872 59.164 0 0
Third 163.012 59.425 0 0

The PLE wait is smaller on head and still present. Profiling changes timings, so these traces explain where the host waited and are not the speed measurement.

First-request TTFT

One load per arm, main then head, two different 4096-token code windows per load, two generated tokens, temperature 0, context 16896, parallel 1, draft off. Model nvidia/Qwen3.8-Flash-Next-NVFP4 at fc694b54fb0174e0913e6adf86691ef85a4ead47, loaded from its checkpoint folder, on one GB10 (driver 595.84, CUDA 13.3.1 image, sm_121, release binaries, OS page cache not dropped). Prefill rate is the server's own report.

Metric Main Head Change
First request TTFT (ms) 8279.125 8227.218 -51.907 (-0.627%)
Subsequent request TTFT (ms) 8209.141 8213.237 +4.096 (+0.050%)
Median server prefill (tok/s) 497.587 499.146 +1.559 (+0.313%)

The first request was 51.907 ms faster in this pair; the subsequent request did not improve. This is not a statistically established steady-throughput gain.

Each arm is one load and one first request, so these are single observations with no spread. The server load took 205.187 s on main and 206.156 s on head, and the body phase of the load took 0.11 s on main and 0.39 s on head, because every budgeted slot is now pinned during load.

Correctness

  • A 16-token greedy request on each loaded server returned identical token ids.
  • FAIL-first: with slot allocation put back on first use, hw_a_sequence_holds_the_budget_of_its_context failed with left: 0, right: 2. With sorted coalescing removed, page_runs_advise_each_requested_page_once failed, and with file grouping removed, a_run_table_reads_each_row_from_its_run failed. All three passed again on the restored code.
  • No arithmetic or kernel changed, so no oracle or KL measurement was added. No GLM or TP=2 run was made. The checkpoint constructor is shared with other models and holds only the lengths its callers give it.

What I ran into

This does not block the PR. A call that advises many disjoint ranges in one syscall, process_madvise, returned EPERM inside the container on this machine (errno=1), so I kept the per-run advice and added no vector path. Most of the request time is in bf16_tile_gemm (16688.004 ms over the three profiled requests), which this PR does not touch.

Hardware

One NVIDIA DGX Spark (GB10, compute capability 12.1, unified memory), driver 595.84, CUDA 13.3.1 image. Builds use BLOOMERY_ARCH=sm_121. The engram host tests ran on a Linux host machine.

AI help

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

@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 needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 22, 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: No must-fix defect is established in the changed code.

Non-blocking

⚠ Complete the timing evidence: crates/engram/src/lib.rs:641 adds three temporary vectors per valid nonempty page_runs call on the PLE advice path [derived]: sorted IDs, row runs and page spans. The GB10 timing tables omit the server and Nsight commands and their output. Add those commands and a steady-decode base/head comparison to measure the allocation cost against fewer syscalls.

Checked

Duplicates: page coalescing reuses adjacent_runs; dryer reported 0 candidate pairs. Complexity: crapper flagged no function.
Silent failure: invalid rows, allocation failures and advice failures return errors; the helper sends failures back to its caller.
Tests, source-based mutation analysis:

Gates: no bands, pins or test clauses relaxed. The PR reports FAIL-first for the three new contract checks.
Adversarial checks: empty and invalid IDs, disjoint page ranges, repeated cross-file rows, and cleared or unfilled slots are covered by the existing guards.
Escape catalog: no pattern matches.

Notes

Rust/CUDA tests were not rerun during validation.
GPU evidence is incomplete: the PR explicitly omits just gate-gpu-lib and provides no executed just gate-* command with output.

Card check: needs-gpu. This pull request changes crates/gpu/src/checkpoint.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)

Filed outside this PR: #662

@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 2a2d2d2 into midagedev:main Oct 22, 2026
6 of 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 host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset 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