Repository navigation
gpu: a branch forked again in one capture depends on its fork point alone - #177
Conversation
…lone Branch::fork records an event on the main stream and makes the branch stream wait on it. Inside a capture that wait adds the main stream's dependencies to the branch's capture dependencies and keeps the branch's own last node. A branch forked again in the same capture so depended on its fork point and on its node from the fork before. That edge is redundant (the earlier join already ordered the node before the fork point), but the graph no longer had the shape Branch documents, and the V4.1 step gate's topology check counts it: one more fork and one more join for every attention layer after the first. GLM-5.3's latent mixer forks its k-pool branch once per latent layer in the same way. fork now reads the main stream's capture dependencies and their edge data (cuStreamGetCaptureInfo_v3) and sets the branch's to them (cuStreamUpdateCaptureDependencies_v2, SET). Outside a capture it does what it did after the one query. Dropping the old node is sound only when the fork before was joined into the same main stream, so a Branch is now made for one main stream (Branch::new takes it) and fork takes &mut self and no stream: Forked borrows the branch until its join or drop, so a second open fork, or a fork from another stream, does not compile. AttnChain makes its branch on the card's engine stream; GLM-5.3's branch moves from its kernels to the body and reaches the latent row through Parts. hw_a_branch_forks_one_at_a_time_from_its_fork_point (gate-gpu-lib) captures three fork and join rounds on one branch, the middle one ended by a drop, and walks the graph's edges: each fork point starts two paths that depend on it alone and lead into one join point. The unsafe ratchet's gpu pin moves 1747 -> 1750 for the three new blocks.
There was a problem hiding this comment.
Verdict: CLEAN: No must-fix finding remains; the added eager query cost is unmeasured.
Non-blocking
⚠ Bound the added eager query cost: crates/gpu/src/graph.rs:377.
Branch::fork now issues one capture-info driver query even outside capture. DS41 eager decode adds one query per attention sub-layer; prefill adds one per layer-batch that forks work. GLM adds one per latent-layer fork.
The added host work is query cost × fork count [derived]. The PR leaves query cost unmeasured; structural and PTX equality do not bound it.
Provide a bound on the contributor's card, or a timed eager A/B when the predicted effect exceeds the timing ruler.
Checked
Duplicates: both model families reuse Branch for the new capture-dependency adjustment.
Complexity: Branch::fork adds capture-status handling and fallible driver calls; Body::load_placed adds one fallible branch initializer at load time.
Silent failure: query/update failures return named errors; the two ignored drop results preserve the base cleanup behavior.
Tests: the new ignored hw_ test asserts node and edge counts and each round's fork/join dependencies, including a dropped fork. The PR reports failures with the base dependencies and with the drop join disabled.
Gates: the unsafe-block pin rises 1747 → 1750 with a dated reason identifying all three new blocks. No test or numeric band is relaxed.
Escape catalog: no C1–C4 pattern matches the diff.
Notes
Static validation only; GPU gates were not rerun. The PR omits the required nvidia-smi line and exact model-file identity; gpu.json records incomplete evidence.
Card check: needs-gpu. This pull request changes crates/gpu-deepseek41/src/chain/attn.rs, crates/gpu-deepseek41/src/chain/attn/batch.rs, crates/gpu-glm5next/src/body.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)
|
The review is done and the contribution check passed, so I'm merging this. |
What and why
On a DGX Spark,
just gate-gpu-ds41-stepfails at upstream main on one clause, the--structuretopology check: aBranchforked again in one capture keeps its node from the fork before as a dependency, so the graph carries one redundant edge for every attention layer after the first.Branch::forknow sets the branch's capture dependencies to the main stream's, and aBranchis now bound to one main stream and borrowed by its open fork, so the condition that makes this sound holds by construction. Refs #53.The 8 extra edges each go from layer L's attention
ds41_hc_preto layer L+1's. Each makes the firstds41_hc_prea second fork and the next one a second join, so 9 + 8 = 17. The edge is redundant: layer L'sds41_hc_prealready reaches layer L+1's through itsds41_hc_postand the next fork point. That is why replay still equals eager on every set.The cause is in
Branch::fork(crates/gpu/src/graph.rs). A fork records an event on the main stream and makes the branch stream wait on it. Inside a capture, that wait adds the event's dependencies to the branch's capture dependencies; it does not remove the ones the branch already has.AttnChainreuses oneBranchfor every layer of a capture. From the second fork on, the branch's set still holds its node from the fork before, so the branch's first node depends on both. That breaks the shapeBranch's doc states: inside a capture the branch is an edge from the fork point and one into the join point.What changes:
Branch::forkreads the main stream's capture dependencies and their edge data (cuStreamGetCaptureInfo_v3) and sets the branch's to them (cuStreamUpdateCaptureDependencies_v2withCU_STREAM_SET_CAPTURE_DEPENDENCIES). The edge data is passed through unchanged, so an annotated edge (a programmatic one) would keep its annotation [derived: no caller forks after such an edge today, and the test below uses plain edges]. Outside a capture,forkadds that one query. A main stream whose capture is invalidated is refused by name.Branch::newtakes the main stream (anArc<CudaStream>) instead of the context,fork(&mut self)takes no stream, andForkedholds&mut Branchuntil it is joined or dropped (a drop joins, as before). A second open fork, or a fork from another stream, does not compile.AttnChain's step path (chain/attn.rs) and batch path (chain/attn/batch.rs) make their branch on the card's engine stream (gpu.stream_handle()), the stream every one of their forks already used. GLM-5.3's latent row (gpu-glm5next/src/mla.rs) forks its k-pool branch once per latent layer in the same way; that branch moves fromKernels(which the row reads through a shared reference) toBody, reaches the row through one morePartsfield (the NextN layer's row throughnextn_run's borrow of the body), andlatent_rowtakes it as one more argument.Branch's doc now states what the graph holds on every fork of one capture, and the binding to one main stream.A minimal reproducer outside the engine shows the driver side. A CUDA C program captures three rounds on one main stream and one branch stream: record on main, the branch waits, a kernel on each stream, record on the branch, main waits, a kernel on main. The captured graph has 14 edges (5 forks and 5 joins, 3 and 3 expected). With the branch's dependencies set to main's after each wait, it has 12 edges (3 and 3). Both user-mode drivers on the machine gave the same result: the host's 595.84, and the compat driver 610.43.02 inside the CUDA 13.3.1 container. The test below is the same check inside the crate.
Code shape
The review reads these first. A box left unticked needs one line of why.
copying it (
AGENTS.md"Common code first",docs/rust-quality.mdR14). Where I found an existing copy, Inamed it below.
(tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
tools/check-comments.sh).PIN(YYYY-MM-DD):and its reason.
cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": none. The fix is inBranch, the one owner of the fork and join. The call sites change only in how they make and borrow their branch.Notes on the boxes:
tools/unsafe-ratchet.txt: thegpupin moves 1747 -> 1750 for three new blocks, with aPIN(2026-10-14):line by the file's own rule (new code, each block with its// SAFETY:line): the capture query, the dependency update, and the test's read of the graph's edges.What I ran
The runs below are at
bffb0d76on166921f5. The PR's head94c381aais the same patch rebased onto84f77b01(git range-diff), and main changed none of the nine files this PR touches in between.Machine: DGX Spark (GB10, compute capability 12.1, aarch64), host driver 595.84. The gates ran in the CUDA 13.3.1 dev container, and they used the container's compat driver: during the step gate and lib test runs, the container's processes map
/usr/local/cuda-13.3/compat/libcuda.so.610.43.02. Fixture tier (BLOOMERY_TIER=fixture,BLOOMERY_BOX_LOCAL=1). Base166921f5(upstream main), headbffb0d76. The recipes ran at their default--arch sm_86.FAIL-first
166921f5bffb0d76just gate-gpu-ds41-step, topology summaryjust gate-gpu-ds41-step, rc--slotsleg does not start)PASSED: gate_deepseek41_step, 11 clauses ran and 2 left to the real tier, then the--slotsleg)just gate-gpu-lib,hw_a_branch_forks_one_at_a_time_from_its_fork_point14 edges for 3 rounds, want 4 a round(left 14, right 12)gate-gpu-lib233 passed, then the 4hw_held_tests passedForked'sDropmade to skip the join (head tree,if false && self.open)11 edges for 3 rounds, want 4 a round(left 11, right 12)The base column of the lib test is the base tree with the same test written against the base API (
Branch::new(&ctx),branch.fork(s)); it ran alone (bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- --include-ignored hw_a_branch_forks), as did the mutant row. Beyond the edge count, the test walks the graph round by round: each fork point starts two paths, each path depends on its fork point alone, and both lead into one join point that depends on the two alone. The middle of the three rounds ends with a drop instead of a join.Head, the topology lines:
Structure lines
Every other line of the step gate's first leg (96 of them: the predicted node counts,
graph: nodes=288 kernels=268 memops=19 memcpy=1, replay = eager on the three sets, the pair graph's 576 nodes, the shadow, the cuts, the rollbacks) is the same at the base and the head. So the node count is unchanged and only edges went away. The head's--slotsleg passes (check slots G4 orderandH2 one passhold the captured stagger at 576 nodes).GLM-5.3's fixture has two latent layers, so its decode capture forks the k-pool branch twice and so loses one redundant edge [derived: no GLM gate reads the graph's edges].
just gate-gpu-glm5next-e2eprinted the same 24 verdict lines on both trees, among themstructure decode graph_nodes=172 (want 172 …)andone chain: … logits bit for bit: true PASS. On both it then stops with exit 1 at a file this machine does not have (data/glm5next/corpus-prose.ids: No such file or directory).ptx-scan
The scan set
python3 tools/recipes.py scan-setderives (bloomery-serve-ds41withdeepseek41,vision,gate_kquantandgate_swapwithgpu), built on both trees withcargo oxide build --arch sm_86 -- -p bloomery-gpu-gates --features <features> --release --bin <bin>and scanned withbash tools/ptx-scan.sh --no-jit <bin>. Each scan's output saved to its own file, the comparison is:The entry tables and md5 blocks are equal.
bloomery-serve-ds41's modules, extracted withobjcopy -O binary --only-section=.oxartandtarget/release/oxart_ptx, keep the vision module byte for byte. Thebloomery-gpu-deepseek41module keeps its size and changes bytes, and thebloomery-gpumodule changes size (8493266at the base,8493153at the head).python3 tools/ref/ptx-canon.py --all <base module> <head module>, which compares each entry with the generated module symbols normalized, gives67 shared entries: 67 identical, 0 reordered-only, 0 differand234 shared entries: 234 identical, 0 reordered-only, 0 differ. No kernel moved.The narrowing still keeps the full list of 113 recipes:
crates/gpu/src/graph.rshas no row intools/gate-paths.tsv, so every gate whose binary linksbloomery-gpustays selected.Static tier
just mac-static 166921f5on an Apple silicon Mac (Apple M5), on the head commit: fmt-check rc 0; lint 41 warnings, the ratchet's 41; combos 16 shapes, 0 red; check-arch, check-comments, check-defaults, check-levers, check-loads, check-ptx-names, check-records, check-recipes, check-rustflags, check-unsafe (gpu 1750 194 10,= pin) and check-waits rc 0.just mac-test: 1,200 passed, 1 failed, 179 ignored. The failure isbloomery-refset'sarch::draft::tests::a_plain_target_with_no_draft_beside_is_the_family_path, which sees one temporary file as/var/folders/...and as/private/var/folders/.... An earlier upstream main (cb5688c9) fails the same test on the same machine (1,196 passed, 1 failed, 179 ignored there), and this PR does not touchcrates/refset.Not run here
gate-gpu-ds41-prefill,-tierand-dspark-loop(exit 66, no DSpark fixture draft under/models/fixtures/v41/draft),gate-gpu-ds41-callstream(exit 64,BLOOMERY_CARD=bothneeds two cards),gate-gpu-ds41-media(exit 1, noref-vision/deepseek41vreference set). The batch path's fork (chain/attn/batch.rs) is reached here only through the step gate's prompt calls in its--slotsleg.weekly-gpu-glm5next-e2e-long(selected by the GLM-5.3 files) ran on the head and stopped at the same missingcorpus-prose.idsafter 24 PASS lines, before its long sets.gate-gpu-e2e,gate-gpu-ds41-chain-attn,gate-gpu-ds41-long,weekly-gpu-ds41-candand the other real-file and real-only gatesjust affectedselects: they need the real model files.Timed A/B
None, and none is predicted to show anything:
cuStreamGetCaptureInfo_v3) per fork. That is one per attention sub-layer per step on V4.1's decode path, one per layer-batch on its prompt path, and one per latent layer on GLM-5.3's. Its cost is not measured here.The change class is the host-dispatch clause of the "move, split, rename" row: host dispatch code keeps its structural lines (graph node count, eager = replay, e2e set identical). Those lines are the proof here, and they are identical above; the identical ptx-scan shows that no kernel moved. A same-lease A/B on the 3090 would test a prediction of 0, which is inside the ruler at any round count
lease_takeaccepts.What I ran into
This does not block the PR.
Branch(ac250bb) recordsgate-gpu-ds41-step (topology 40/40 PASS)without naming the card, and b437046 recordsgate-gpu-ds41-step on the 3090 114 sgreen. The step gate captures all body layers with one branch on every card. With the drivers on this machine, every fork after the first keeps the branch's old node. I have not found what makes the other graph different: the driver of those runs is not recorded with them (docs/BUILD.mdnames 615.71.09 for the development machine), and the code path has no per-card branch. Running the reproducer above, orgate-gpu-libwith the base copy of the test, on the 3090 would show whether it is the driver version or the device.Hardware (if the change is for a machine)
DGX Spark (GB10, aarch64), host driver 595.84, CUDA 13.3.1 container (compat driver 610.43.02). The fix itself is not specific to the machine: it holds the graph to the shape
Branchdocuments on any driver.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.