Skip to content

idol: the octree and Gaussian decoders on CUDA (stacked on #1773, #1767; not yet run on a GPU) - #1858

Merged
ashhart merged 5 commits into
ashhart:mainfrom
jayleaton:idol-decoders-cuda
Nov 21, 2026
Merged

ashhart merged 5 commits into
ashhart:mainfrom
jayleaton:idol-decoders-cuda

Conversation

@jayleaton

Copy link
Copy Markdown
Contributor

Stacked on #1773 and #1767 (Idol's decoders on Metal, and the denoiser on CUDA). This branch is #1773 with #1767 merged in. Its own change is ad8501a8a and da5e1bdf1. Review after them.

Compiles and passes host tests; never run on a GPU; GB10 qualification pending. The Sparks are busy, so nothing in this PR has run on an NVIDIA device.

What this changes

Idol's octree and Gaussian decoders on CUDA, the CUDA side of #1773. For #1757. Details: the "Decoders" part of docs/recipes/idol-cuda.md.

  • zig/kernels/cuda/idol_decoder.cu (glue flags): tf_idol_dec_embed, _half, _kv, _heads, the tiled cross attention _attention and an fp32 short form _few for 8 query rows or fewer.
  • Reused from idol: Idol's denoiser on CUDA (stacked on #1766) #1767: the self attention (the Gaussian decoder's qkv rows are already in its layout), the cuBLASLt fp16 linears with fp32 sums, the bias, GELU, norm and gated-add kernels, and true-fp32 cuBLASLt (no TF32) for input_layer and the head.
  • The host steps (softmax, systematic resampling, compaction, jitter, the activation, PLY and camera) are shared with Metal, not copied. tf-idol-decode is one driver (zig/tests/idol_decode_run.zig) with thin Metal and CUDA mains; the CUDA build step is idol-decode-cuda.
  • Decoder.load admits sm_121 and sm_120 and refuses any other GPU by name.

Precision

  • Attention keeps fp32 scores and sums and rounds P once to nearest fp16 before P V, as torch's CUDA attention does; no hi/lo split is needed on CUDA. At 8 query rows or fewer it stays fp32 throughout, as the SDK's MPS run that recorded the cases does.
  • The NaN and infinity fixes the Metal contract found carry over: tf_idol_dec_heads keeps a NaN norm, and an infinity stays infinite wherever its fp16 P is nonzero.

Kernel contract

tf-cuda-test idol-decoder-contract: the six kernels and #1767's self attention at the decoders' shapes, with 13 planted controls (an fp16 sum, a rounding moved earlier, P V in fp16, the tail keys unmasked, fmaxf dropping a NaN). It is in the full contract's family sets and contract_limits.zig. Gate-5 records (idol_decoder_cuda_records.zig) are nvcc 13.0's for sm_80, 86, 89, 120 and 121. There is no SUMMARY line yet: it needs a GPU.

Receipt

  • Linux box (no GPU), nvcc 13.0:
    • idol_decoder.cu and the controls image compile for sm_80, 86, 89, 120 and 121, exit 0. The records come from cuobjdump -res-usage of that build. This branch's kernel and the merged tree's give the same usage.
    • zig build test-cuda-host: 4,137 of 4,154 passed, 8 failed (see below). test-idol-cuda-host: 37 of 37.
    • zig build fatbins -Dnvcc=... -Dsm=121,120 and the CUDA tools build on the merged tree (226 of 226 and 173 of 173 steps).
  • Pre-existing host-suite failures: on the Linux box, zig build test-cuda-host failed the same 8 tests with and without this change: 6 in recall_store_test, plus recall_routes ("the record's state and size…") and late_system_test ("GET and DELETE /v1/recall…"). The tree with only idol: Idol's denoiser on CUDA (stacked on #1766) #1767 merged into the Metal branch fails the same 8 (4,117 of 4,134 passed, 8 failed). The recall store reads back nothing ("found 0") on a box whose disk was nearly full. None of them touches Idol. The final run on the merged CUDA tree (idol-e2e-cuda) passed with no failures (282 of 282 steps).
  • Metal, M5 Ultra: zig build test test-golden -Dcpu=apple_m1: 589 of 589 steps, 8,980 of 9,033 tests pass, 53 skipped. The pre-change and new tf-idol-decode on decode262k and decode32k: gate logs, tf-idol-decode.ply and camera.json byte-identical, the JSON identical apart from timings, all gates pass.
  • zig fmt --check build.zig zig: clean. lean_check.py: 424, the same as main.
  • Not run: every kernel's output on a device, the contract gates and controls on a device, the cuBLASLt plans at the octree's varying row counts, scratch at 1M Gaussians, case parity, timing and memory. tools/zig/idol_gb10_qualify.sh (in the CUDA end-to-end PR) runs this component's contract and case on a Spark with the rest; its section in docs/recipes/idol-cuda.md lists the case files to copy from the Mac.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (No token path.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (n/a.)
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt. (CUDA: registered; no SUMMARY line until a GPU runs it.)
  • Prompt processing is no slower than the last release. (Not touched.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

@ashhart

ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thanks @jayleaton. Sharing the host steps and one tf-idol-decode driver between backends, with byte-identical Metal output before and after, is the right shape. This waits on #1773 and #1767. It has the same line-limit point as #1767 (registry.zig is at 600 lines on main, and this branch adds two), and it needs GB10 receipts: the idol-decoder-contract SUMMARY line and the case parity. If you can't get time on one, we can run it on ours.

ashhart added a commit to jayleaton/TensorFold that referenced this pull request Nov 19, 2026
@ashhart
ashhart marked this pull request as ready for review November 19, 2026 00:28
@Bizuayeu Bizuayeu mentioned this pull request Nov 19, 2026
4 tasks done
@jayleaton

jayleaton commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

#1773 and #1767 are both on main now, so I rebased this onto main 9ba855b3b at 0b8f39ca7. Only this PR's four commits remain: the CUDA decoders, their gate-5 records, and @ashhart's pin refresh and test fix.

Host checks (Linux): zig fmt, git diff --check, lean 0 new against main, pr_check 0 errors, cuda_common_check 0 violations, cuda_fragment_check 0 misses, the checker unittest, and test-gradient-serving, test-idol-cuda-host, test-kernel-contract and compile-cuda-tests (56 of 56 steps, 301 of 301 tests). The nvcc build and the GB10 idol-decoder-contract and case receipts are still to come.

@jayleaton
jayleaton force-pushed the idol-decoders-cuda branch 2 times, most recently from b7d49e1 to 0b8f39c Compare November 20, 2026 17:58
@AIFlowML

Copy link
Copy Markdown
Contributor

Independent check on 0b8f39ca from M5 Max with Zig 0.17.0. zig build test-idol-cuda-host test-gradient-serving test-kernel-contract -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j3 --summary all passed 301/301. compile-cuda-tests is absent on the default macOS target. The runnable command from the Mac is zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu -Doptimize=ReleaseSafe -j3 --summary all, which cross-built tf-cuda-test successfully (10/10 steps).

The trial merge against 46c6ee22 found five conflicts in the CUDA build, kernel registration, contract limits and gradient pin. After reconciling those, the remaining device evidence is the GB10 idol-decoder-contract SUMMARY and octree/Gaussian case parity on the resolved SHA. The cross-build verifies the runner compiles for Linux ARM64.

Igor Lessio - AIFLOW LABS

@jayleaton

Copy link
Copy Markdown
Contributor Author

Rebased onto main 46c6ee229 at 9e6f0d0ef. This PR's four commits are unchanged otherwise: the CUDA decoders, their gate-5 records, and @ashhart's pin refresh and test fix. Thanks @AIFlowML for the M5 Max check and the trial merge, which found the five conflicts below.

Host checks (Linux x86-64), all passing:

  • zig fmt, git diff --check, lean 0 new against main, and pr_check with 0 errors.
  • cuda_common_check with 0 violations, cuda_fragment_check with 0 misses, and the checker unittest.
  • test-gradient-serving, test-idol-cuda-host, test-kernel-contract and compile-cuda-tests: 58 of 58 steps, 299 of 299 tests.
  • AIFlowML's cross-build, zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu -Doptimize=ReleaseSafe, builds tf-cuda-test: 10 of 10 steps.

@ashhart, we can't get time on a GB10, so yes please to your offer. The open receipts are the idol-decoder-contract SUMMARY line and the octree and Gaussian case parity on 9e6f0d0ef. The nvcc build has not been run here either.

@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the rebase. While it was in flight I ran the decoder contract on the previous public head 0b8f39ca. I compared it with 9e6f0d0ef and the Idol kernel sources, Idol contract fixtures, and shared gate and spec sources are unchanged. The result below is from the older binary.

Linux x86-64, GeForce RTX 5090 Laptop GPU (SM 12.0, driver 595.99.02), Zig 0.17.0, nvcc 13.1.115. zig build compile-cuda-tests -Dnvcc=/usr/local/cuda/bin/nvcc -Dsm=120 -Doptimize=ReleaseSafe -j2 --summary all passed all 176 build steps. I ran timeout 360s /path/to/tf-cuda-test idol-decoder-contract on that build's runner.

The tiled tf_idol_dec_attention kernel failed the shapes gate at 16×1000×65. Output 73111 was 6.011963e-3 versus the float64 reference 6.075550e-3, 1.35× the existing error bound. All 13 planted controls went red as expected. The run timed out after the self-attention shapes gate (exit 124) before a final SUMMARY.

I isolated output 73111, query row 71, head 6, channel 23, using the contract's 0x1d0d seed and the shapes gate's per-shape seed offset. In float64, rounding probabilities relative to the final maximum gives the reference's 0.00607555010675. Rounding them at each 64-key tile's running maximum, then rescaling the accumulated numerator, gives 0.00601326493969 before the output store and 0.006011962890625 after FP16 rounding, exactly the observed GPU value. The lone key in tile two raises the maximum from 2.15348862484 to 2.36253021751.

This isolates a rounding-order difference on the failing fixture. If tiled rounding is the intended contract, the reference should simulate the tile maxima and the matching midpoint allowance. The GB10 run and release-checkpoint parity are still needed to decide which behavior to keep.

Igor Lessio - AIFLOW LABS

jayleaton and others added 5 commits November 21, 2026 11:08
… pending)

Port Idol's decoders from Metal to CUDA under the same precision contract,
sharing the host steps (decode.zig now takes either decoder) and the case
driver (tf-idol-decode: idol_decode_run.zig, thin Metal and CUDA mains; the
Metal tool's gate lines, JSON and PLY are unchanged on both Mac cases).

- idol_decoder.cu: dec_embed, dec_half, dec_kv, dec_heads (MultiHeadRMSNorm
  in place, NaN norm kept), the tiled cross attention (full<64, 8>'s row
  arithmetic from query rows to the latent's keys, P rounded to nearest fp16
  as torch's CUDA kernels do) and the fp32 short form for <= 8 query rows;
  each a template whose BREAK 0 ships
- self attention reuses idol.cu's tf_idol_attention; blocks reuse its
  cuBLASLt fp16 linears, norms and gated adds; stem and head in true fp32
- admission: sm_120/sm_121 only, others refused by name
- contract: idol-decoder-contract (gates 1-4 over the six kernels and
  tf_idol_attention at anchor shapes, 13 controls as other BREAK values),
  joined to the family sets; image in contract_limits
- host tests: launch geometry, scratch sizing, contract range references

Not yet compiled with nvcc (the Linux box was unreachable): gate-5 records
and the sm_120/121 fatbin build are pending. Never run on a GPU.
@ashhart
ashhart merged commit 6cd8c58 into ashhart:main Nov 21, 2026
1 check passed
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thank you @jayleaton. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit to kotevcode/TensorFold that referenced this pull request Nov 21, 2026
@jayleaton

Copy link
Copy Markdown
Contributor Author

Thanks @AIFlowML for the RTX 5090 run and for isolating output 73111 down to the tile maxima. Pushed 15e93b9 on top of Ash's eea88db. It is a fast-forward and doesn't touch Ash's commits.

Behaviour chosen: tiled rounding is the contract, and the reference now simulates it. The kernel stays as it is. torch's CUDA flash and memory-efficient attention also round P to fp16 at the running maximum of each key tile and then rescale. Release-checkpoint parity on CUDA therefore means matching that, and the changelog already describes the kernel as rounding P "as torch's CUDA kernels do". Moving the kernel to final-max rounding would need a second pass over the keys and would depart from torch. The Metal decoders (#1773) are unaffected: they feed P·V as fp16 P hi + lo halves (about 22 bits), and their short form uses fp32 P, so where P rounds within a tile doesn't move them. CUDA and Metal both stay within their own references.

  • contract_idol_dec_attn.zig: the float64 reference (weigh) walks the keys in the spec's 64-key tiles. Each P is rounded to fp16 at the running maximum through its tile and then carried to the final maximum. The midpoint allowance is taken at that running maximum, using the errors of the key's score and of the running maximum's score. The few-row form is unchanged (fp32 P).
  • Regression host test: a three-tile case whose P·V cancels exactly at tile 0's own maximum but not at tile 2's maximum, 0.2 higher. An fp32 online-softmax simulation of the kernel lands within the new allowance and more than 4× outside the old final-max one. Forcing the reference back to final-max rounding fails the test. I couldn't rebuild your exact fixture on the host, because its inputs come through the GPU rig, so I'd appreciate a rerun at 16×1000×65.

Timeout: gate 4 runs on the largest served shape, 8,192×8,192 at one head. The self-attention sums gate computed float64 outputs for all 8,192 tokens ten times (a reference plus nine fp32/fp16/bf16 simulations, each over all 8,192 keys), about 4e10 float64 steps. The stress inputs make every key alike, so every token's outputs equal token 0's. It now computes token 0's once and copies them to the rest. A host test checks that the copies match the full computation. This is untimed here (no GPU), so please say if it still runs past 360 s.

Checks on 15e93b9: fmt, git diff --check, lean (0 new), pr_check --pr 1858 (0 errors, 0 warnings), cuda_common/fragment checks and their unittest. test-gradient-serving test-idol-cuda-host test-kernel-contract compile-cuda-tests passes 306/306, and the aarch64-linux compile-cuda-tests cross-build passes. GPU validation is still open. The GB10 idol-decoder-contract SUMMARY and the case parity are still Ash's offer.

@ashhart, the #1858 changelog line from lines/1858.txt still says it "has not yet run on a GPU". Suggested wording: "…rounds P to nearest fp16 at each 64-key tile's running maximum as torch's CUDA kernels do… On an RTX 5090 the contract's reference rounded P at the final maximum and went red; it now follows the tile maxima (#1858, …). Thanks to @AIFlowML for the RTX 5090 run."

jayleaton added a commit to jayleaton/TensorFold that referenced this pull request Nov 22, 2026
…ter ashhart#1858)

The tiled decoder attention rounds P to fp16 at each 64-key tile's running
maximum and rescales the sums, as torch's CUDA online-softmax kernels do.
The float64 reference rounded at the final maximum, so a later tile with a
larger score moved where P rounds and the shapes gate went red at
16x1000x65 (reported on an RTX 5090). The reference now follows the tile
maxima, with the midpoint allowance at the running maximum, and a host test
checks a fp32 online-softmax simulation against both.

Gate 4's self attention over 8,192 anchors computed every token's outputs
in float64 nine times, though alike keys make every token's outputs token
0's; it computes those once and copies them (about 4e10 float64 steps
fewer, untimed here: no GPU).
jayleaton added a commit to jayleaton/TensorFold that referenced this pull request Nov 22, 2026
…ter ashhart#1858)

The tiled decoder attention rounds P to fp16 at each 64-key tile's running
maximum and rescales the sums, as torch's CUDA online-softmax kernels do.
The float64 reference rounded at the final maximum, so a later tile with a
larger score moved where P rounds and the shapes gate went red at
16x1000x65 (reported on an RTX 5090). The reference now follows the tile
maxima, with the midpoint allowance at the running maximum, and a host test
checks a fp32 online-softmax simulation against both.

Gate 4's self attention over 8,192 anchors computed every token's outputs
in float64 nine times, though alike keys make every token's outputs token
0's; it computes those once and copies them (about 4e10 float64 steps
fewer, untimed here: no GPU).
ashhart pushed a commit to jayleaton/TensorFold that referenced this pull request Nov 23, 2026
…ter ashhart#1858)

The tiled decoder attention rounds P to fp16 at each 64-key tile's running
maximum and rescales the sums, as torch's CUDA online-softmax kernels do.
The float64 reference rounded at the final maximum, so a later tile with a
larger score moved where P rounds and the shapes gate went red at
16x1000x65 (reported on an RTX 5090). The reference now follows the tile
maxima, with the midpoint allowance at the running maximum, and a host test
checks a fp32 online-softmax simulation against both.

Gate 4's self attention over 8,192 anchors computed every token's outputs
in float64 nine times, though alike keys make every token's outputs token
0's; it computes those once and copies them (about 4e10 float64 steps
fewer, untimed here: no GPU).
ashhart pushed a commit that referenced this pull request Nov 23, 2026
…ter #1858)

The tiled decoder attention rounds P to fp16 at each 64-key tile's running
maximum and rescales the sums, as torch's CUDA online-softmax kernels do.
The float64 reference rounded at the final maximum, so a later tile with a
larger score moved where P rounds and the shapes gate went red at
16x1000x65 (reported on an RTX 5090). The reference now follows the tile
maxima, with the midpoint allowance at the running maximum, and a host test
checks a fp32 online-softmax simulation against both.

Gate 4's self attention over 8,192 anchors computed every token's outputs
in float64 nine times, though alike keys make every token's outputs token
0's; it computes those once and copies them (about 4e10 float64 steps
fewer, untimed here: no GPU).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants