Skip to content

gpu: a branch forked again in one capture depends on its fork point alone - #177

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-graph-fork-deps
Oct 14, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-graph-fork-deps

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

What and why

On a DGX Spark, just gate-gpu-ds41-step fails at upstream main on one clause, the --structure topology check: a Branch forked 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::fork now sets the branch's capture dependencies to the main stream's, and a Branch is now bound to one main stream and borrowed by its open fork, so the condition that makes this sound holds by construction. Refs #53.

topology: 288 nodes, 17 forks and 17 joins (one each per attention sub-layer: 9), 0 nodes with more than two edges on a side: FAIL

The 8 extra edges each go from layer L's attention ds41_hc_pre to layer L+1's. Each makes the first ds41_hc_pre a second fork and the next one a second join, so 9 + 8 = 17. The edge is redundant: layer L's ds41_hc_pre already reaches layer L+1's through its ds41_hc_post and 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. AttnChain reuses one Branch for 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 shape Branch's doc states: inside a capture the branch is an edge from the fork point and one into the join point.

What changes:

  • Branch::fork reads the main stream's capture dependencies and their edge data (cuStreamGetCaptureInfo_v3) and sets the branch's to them (cuStreamUpdateCaptureDependencies_v2 with CU_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, fork adds that one query. A main stream whose capture is invalidated is refused by name.
  • Dropping the branch's old node is sound only when the fork before was joined into the same main stream: then the node is already ordered before the fork point. The API now makes both conditions hold. Branch::new takes the main stream (an Arc<CudaStream>) instead of the context, fork(&mut self) takes no stream, and Forked holds &mut Branch until it is joined or dropped (a drop joins, as before). A second open fork, or a fork from another stream, does not compile.
  • The call sites: 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 from Kernels (which the row reads through a shared reference) to Body, reaches the row through one more Parts field (the NextN layer's row through nextn_run's borrow of the body), and latent_row takes 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.

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moved to make a check pass; a re-pin carries PIN(YYYY-MM-DD):
    and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none. The fix is in Branch, 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: the gpu pin moves 1747 -> 1750 for three new blocks, with a PIN(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 bffb0d76 on 166921f5. The PR's head 94c381aa is the same patch rebased onto 84f77b01 (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). Base 166921f5 (upstream main), head bffb0d76. The recipes ran at their default --arch sm_86.

FAIL-first

Check Base 166921f5 Head bffb0d76
just gate-gpu-ds41-step, topology summary 17 forks and 17 joins: FAIL 9 forks and 9 joins: PASS
the same, 9 per-layer topology lines 9 FAIL 9 PASS
just gate-gpu-ds41-step, rc 1 (only the topology clause red; the --slots leg does not start) 0 (both legs: PASSED: gate_deepseek41_step, 11 clauses ran and 2 left to the real tier, then the --slots leg)
just gate-gpu-lib, hw_a_branch_forks_one_at_a_time_from_its_fork_point red: 14 edges for 3 rounds, want 4 a round (left 14, right 12) ok; gate-gpu-lib 233 passed, then the 4 hw_held_ tests passed
the same test with Forked's Drop made to skip the join (head tree, if false && self.open) red: 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:

topology layer=0 attention ds41_hc_pre (node 2) depends on [ds41_glue_embed_q3k], is depended on by [ds41_hc_post]; body's first kernel [norm_quant] depends on [ds41_glue_embed_q3k]; ds41_hc_post depends on [ds41_hc_pre,q3k_gemv]: PASS
topology layer=1 attention ds41_hc_pre (node 34) depends on [ds41_hc_fold], is depended on by [ds41_hc_post]; body's first kernel [norm_quant] depends on [ds41_hc_fold]; ds41_hc_post depends on [ds41_hc_pre,q3k_gemv]: PASS
topology layer=2 attention ds41_hc_pre (node 58) depends on [ds41_ffn_post], is depended on by [ds41_hc_post]; body's first kernel [norm_quant] depends on [ds41_ffn_post]; ds41_hc_post depends on [ds41_hc_pre,q3k_gemv]: PASS
topology layer=3 attention ds41_hc_pre (node 93) depends on [ds41_ffn_post], is depended on by [ds41_hc_post]; body's first kernel [norm_quant] depends on [ds41_ffn_post]; ds41_hc_post depends on [ds41_hc_pre,q3k_gemv]: PASS
topology layer=4 attention ds41_hc_pre (node 127) depends on [ds41_hc_fold], is depended on by [ds41_hc_post]; body's first kernel [norm_quant] depends on [ds41_hc_fold]; ds41_hc_post depends on [ds41_hc_pre,q3k_gemv]: PASS
topology layer=5 attention ds41_hc_pre (node 162) depends on [ds41_ffn_post], is depended on by [ds41_hc_post]; body's first kernel [norm_quant] depends on [ds41_ffn_post]; ds41_hc_post depends on [ds41_hc_pre,q3k_gemv]: PASS
topology layer=6 attention ds41_hc_pre (node 197) depends on [ds41_ffn_post], is depended on by [ds41_hc_post]; body's first kernel [norm_quant] depends on [ds41_ffn_post]; ds41_hc_post depends on [ds41_hc_pre,q3k_gemv]: PASS
topology layer=7 attention ds41_hc_pre (node 225) depends on [ds41_ffn_post], is depended on by [ds41_hc_post]; body's first kernel [norm_quant] depends on [ds41_ffn_post]; ds41_hc_post depends on [ds41_hc_pre,q3k_gemv]: PASS
topology layer=8 attention ds41_hc_pre (node 255) depends on [ds41_ffn_post], is depended on by [ds41_hc_post]; body's first kernel [norm_quant] depends on [ds41_ffn_post]; ds41_hc_post depends on [ds41_hc_pre,q3k_gemv]: PASS
topology: 288 nodes, 9 forks and 9 joins (one each per attention sub-layer: 9), 0 nodes with more than two edges on a side: PASS

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 --slots leg passes (check slots G4 order and H2 one pass hold 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-e2e printed the same 24 verdict lines on both trees, among them structure decode graph_nodes=172 (want 172 …) and one 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-set derives (bloomery-serve-ds41 with deepseek41,vision, gate_kquant and gate_swap with gpu), built on both trees with cargo oxide build --arch sm_86 -- -p bloomery-gpu-gates --features <features> --release --bin <bin> and scanned with bash tools/ptx-scan.sh --no-jit <bin>. Each scan's output saved to its own file, the comparison is:

python3 tools/recipes.py affected 166921f5..bffb0d76 --no-box --narrow \
  --scan base/bloomery-serve-ds41.log head/bloomery-serve-ds41.log \
  --scan base/gate_kquant.log head/gate_kquant.log \
  --scan base/gate_swap.log head/gate_swap.log
narrow: ptx-scan bloomery-serve-ds41: identical (JIT skipped: --no-jit both)
narrow: ptx-scan gate_kquant: identical (JIT skipped: --no-jit both)
narrow: ptx-scan gate_swap: identical (JIT skipped: --no-jit both)

The entry tables and md5 blocks are equal. bloomery-serve-ds41's modules, extracted with objcopy -O binary --only-section=.oxart and target/release/oxart_ptx, keep the vision module byte for byte. The bloomery-gpu-deepseek41 module keeps its size and changes bytes, and the bloomery-gpu module changes size (8493266 at the base, 8493153 at the head). python3 tools/ref/ptx-canon.py --all <base module> <head module>, which compares each entry with the generated module symbols normalized, gives 67 shared entries: 67 identical, 0 reordered-only, 0 differ and 234 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.rs has no row in tools/gate-paths.tsv, so every gate whose binary links bloomery-gpu stays selected.

Static tier

just mac-static 166921f5 on 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 is bloomery-refset's arch::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 touch crates/refset.

Not run here

  • The fixture tier on this machine refuses these selected gates for reasons outside this change, the same at the base and the head: gate-gpu-ds41-prefill, -tier and -dspark-loop (exit 66, no DSpark fixture draft under /models/fixtures/v41/draft), gate-gpu-ds41-callstream (exit 64, BLOOMERY_CARD=both needs two cards), gate-gpu-ds41-media (exit 1, no ref-vision/deepseek41v reference set). The batch path's fork (chain/attn/batch.rs) is reached here only through the step gate's prompt calls in its --slots leg.
  • weekly-gpu-glm5next-e2e-long (selected by the GLM-5.3 files) ran on the head and stopped at the same missing corpus-prose.ids after 24 PASS lines, before its long sets.
  • gate-gpu-e2e, gate-gpu-ds41-chain-attn, gate-gpu-ds41-long, weekly-gpu-ds41-cand and the other real-file and real-only gates just affected selects: they need the real model files.

Timed A/B

None, and none is predicted to show anything:

  • graph replay: the node count is unchanged and one transitively redundant edge goes per attention layer after the first (8 here). No dependency on the critical path changes. Predicted Δt = 0 [derived].
  • eager runs: one host driver query (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.
  • capture: one query and one dependency update per fork, at capture time only.

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_take accepts.

What I ran into

This does not block the PR.

  • Why does the 3090 pass? The commit that added Branch (ac250bb) records gate-gpu-ds41-step (topology 40/40 PASS) without naming the card, and b437046 records gate-gpu-ds41-step on the 3090 114 s green. 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.md names 615.71.09 for the development machine), and the code path has no per-card branch. Running the reproducer above, or gate-gpu-lib with 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 Branch documents on any driver.

AI help

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

…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.
@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 14, 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 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)

@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 a13125a into midagedev:main Oct 14, 2026
6 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 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