Skip to content

Inkling 2's attention kernels under the kernel contract - #4125

Merged
ashhart merged 3 commits into
ashhart:mainfrom
ajensenwaud:ink-k-attn
Nov 20, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
ajensenwaud:ink-k-attn

Conversation

@ajensenwaud

@ajensenwaud ajensenwaud commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Adds Inkling 2's attention kernels, with a relative-position bias, a sink and a sigmoid gate on every head, their launcher in a new inkling2 module, and their registration with the kernel contract. Nothing serves them until the family PR at the top of the stack.

Checks on this head

  • Head 2247c754b; lean checker 168 on the base, 168 on this head, 0 new.
  • zig build test test-golden test-inkling2-cuda-host compile-cuda-tests: 10,925 of 11,016 tests, 91 skipped on main c94e65d33; rebased onto f0d5ddb74, rechecked there: the CUDA tests compile and the family host tests pass; test-gradient-serving passes with kernels.zig re-pinned.
  • zig fmt --check build.zig zig and git diff --check: clean. CI: pending.

Receipt

n/a: no served path reaches these kernels yet.

Kernel contract
  • Registered: tf_ink2_prep (sliding and full), tf_ink2_rel_table, tf_ink2_attn and tf_ink2_attn_fold with tf_ink2_merge, and tf_ink2_attn_prompt, which replaces fold and merge bit for bit. They use common's qmm_frag mma and ldmatrix and tf_common cp.async; nvcc 13.3 gives the same SASS as with local copies on sm_80, 86, 89, 120 and 121.
  • Planted controls: 5, each red as planted.
  • GB10 (sm_121), the family's run on this stack tested over main 4fda6a020, 19 November, with the same family and contract files: SUMMARY 55 kernels: 55 pass gates 1-4, 0 fail, 0 known findings; 35 controls: 35 red as planted, 0 missed; 0 limit problems, exit 0. This PR's share is 7 registrations and 5 controls.
  • Main's full kernel-contract on that head and on main alone: 388 limit problems and 8 known findings on both, and no failure on the head that main does not show.
  • Gate 5: records for nvcc 13.0 and 13.3 on sm_80, 86, 89, 120 and 121; 13.2 stays pending.

@AIFlowML

Copy link
Copy Markdown
Contributor

@ajensenwaud @ashhart I checked 2247c754b with Zig 0.17.0. The first detail I'd add to the receipt is the smaller command on the current head, with its own counts:

  • zig build test-inkling2-cuda-host test-gradient-serving -Dcpu=apple_m1 --summary all passed 10/10 steps and 10/10 tests on M5 Max.
  • zig build test-inkling2-cuda-host test-gradient-serving compile-cuda-tests -Dfixed-cpu --summary all passed 18/18 steps and 10/10 tests on Linux x86-64.

The test merge into 1ece6e6db conflicted in the changelog and the zig/src/cuda/kernels.zig checksum row. In a disposable test merge I kept main's changelog and regenerated the pin (d8de570d54344eb4212620c2a1e4ae730b4a0c29abf914a2c7f229032d279358). The two focused host targets passed again. CUDA compilation here does not cover device execution of the attention kernels or their controls.

Igor Lessio - AIFLOW LABS

ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit to ajensenwaud/TensorFold that referenced this pull request Nov 20, 2026
@ashhart
ashhart merged commit 6dbb32f into ashhart:main Nov 20, 2026
ashhart added a commit that referenced this pull request Nov 20, 2026
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @ajensenwaud. 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.

1 similar comment
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @ajensenwaud. 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.

Nipale-ai added a commit to Nipale-ai/TensorFold that referenced this pull request Nov 22, 2026
Nipale-ai added a commit to Nipale-ai/TensorFold that referenced this pull request Nov 22, 2026
Nipale-ai added a commit to Nipale-ai/TensorFold that referenced this pull request Nov 22, 2026
Nipale-ai added a commit to Nipale-ai/TensorFold that referenced this pull request Nov 22, 2026
ashhart pushed a commit to AbrahamCete/TensorFold that referenced this pull request Nov 24, 2026
Move ashhart#4125's float64 attention reference from zig/tests/cuda into
core.contract.inkling2_attn_ref so the HIP contract can hold its kernels
to the same rounding points. A Call now names its query heads, key heads
and fp32 chains (Chain.cuda by default, Chain.hip for scalar IEEE sums),
and tauAt takes the model's n_floor (Mini's is 8,192).

CUDA's defaults are unchanged: the CUDA tests only change their import,
and a pinned test holds row() at CUDA's defaults to the bits the old
reference gave (checked bit for bit against it on sliding and global
rows before the move).

Checks: zig test of core.contract (17 pass); zig build
test-inkling2-cuda-host (10/10) and compile-cuda-tests on the tree.
ashhart pushed a commit to AbrahamCete/TensorFold that referenced this pull request Nov 24, 2026
A new inkling2 kernel group (strict IEEE build) with ashhart#4125's rounding
points on HIP: tf_ink2_prep (q/k L2 clips, tau on global layers, the
gamma-free v norm, k and v into each segment's ring), tf_ink2_rel_table,
chunked attention for sliding (tf_ink2_attn) and global layers
(tf_ink2_attn_fold, a split form a block a 1,024-key sub-chunk, and
tf_ink2_attn_prompt), and the ordered merge that takes the sink and the
gate raw. One wave holds a (row, head) pair over 64-key K/V tiles in
LDS with scalar fp32 sums; every path runs the same per-pair steps, so
split and prompt are bit-equal to the fold. The prompt kernel shares
each tile among 8 pairs in one 37 KiB LDS stage while the next tile
loads into registers. The kernels build for gfx1030, gfx1100, gfx1151
and gfx1201 (no scratch; records in hip_records_inkling2.zig).

The launcher (families/inkling2/hip_attention.zig) keeps heads, key
heads, floor and clips as runtime arguments and per-segment cache
offsets, as ashhart#4125's; whole-stream rings versus 64-position pages for
global KV stays open with the maintainer.

The contract entry (tf-hip-kernel-contract image inkling2) holds them
at Mini's 24/8 heads and n_floor 8,192 to core.contract's FP64
reference with HIP's chains, at served shapes to 1M keys on a ring that
wraps; three streams in one launch are bit-equal to each stream alone
(prep, sliding, fold, split). Eight controls go red at shapes, among
them a window one key long, the sink and gate given after their sigmoid
(ashhart#4387's glue) and a prep writing one stream's keys into another's.

Checks on gfx1151 with ROCm 10.1's hipcc: image inkling2 smoke and full,
11 kernels pass gates 1-4, 8 controls red, 0 limit problems;
hip-kernel-contract-limits passes all 24 inkling2 records (its 11
remaining problems are other groups' records); test-inkling2-hip-host,
check-hip-kernel-contract-host; lean 165 on base and head, 0 new.
ashhart pushed a commit to AbrahamCete/TensorFold that referenced this pull request Nov 24, 2026
Move ashhart#4125's float64 attention reference from zig/tests/cuda into
core.contract.inkling2_attn_ref so the HIP contract can hold its kernels
to the same rounding points. A Call now names its query heads, key heads
and fp32 chains (Chain.cuda by default, Chain.hip for scalar IEEE sums),
and tauAt takes the model's n_floor (Mini's is 8,192).

CUDA's defaults are unchanged: the CUDA tests only change their import,
and a pinned test holds row() at CUDA's defaults to the bits the old
reference gave (checked bit for bit against it on sliding and global
rows before the move).

Checks: zig test of core.contract (17 pass); zig build
test-inkling2-cuda-host (10/10) and compile-cuda-tests on the tree.
ashhart pushed a commit to AbrahamCete/TensorFold that referenced this pull request Nov 24, 2026
A new inkling2 kernel group (strict IEEE build) with ashhart#4125's rounding
points on HIP: tf_ink2_prep (q/k L2 clips, tau on global layers, the
gamma-free v norm, k and v into each segment's ring), tf_ink2_rel_table,
chunked attention for sliding (tf_ink2_attn) and global layers
(tf_ink2_attn_fold, a split form a block a 1,024-key sub-chunk, and
tf_ink2_attn_prompt), and the ordered merge that takes the sink and the
gate raw. One wave holds a (row, head) pair over 64-key K/V tiles in
LDS with scalar fp32 sums; every path runs the same per-pair steps, so
split and prompt are bit-equal to the fold. The prompt kernel shares
each tile among 8 pairs in one 37 KiB LDS stage while the next tile
loads into registers. The kernels build for gfx1030, gfx1100, gfx1151
and gfx1201 (no scratch; records in hip_records_inkling2.zig).

The launcher (families/inkling2/hip_attention.zig) keeps heads, key
heads, floor and clips as runtime arguments and per-segment cache
offsets, as ashhart#4125's; whole-stream rings versus 64-position pages for
global KV stays open with the maintainer.

The contract entry (tf-hip-kernel-contract image inkling2) holds them
at Mini's 24/8 heads and n_floor 8,192 to core.contract's FP64
reference with HIP's chains, at served shapes to 1M keys on a ring that
wraps; three streams in one launch are bit-equal to each stream alone
(prep, sliding, fold, split). Eight controls go red at shapes, among
them a window one key long, the sink and gate given after their sigmoid
(ashhart#4387's glue) and a prep writing one stream's keys into another's.

Checks on gfx1151 with ROCm 10.1's hipcc: image inkling2 smoke and full,
11 kernels pass gates 1-4, 8 controls red, 0 limit problems;
hip-kernel-contract-limits passes all 24 inkling2 records (its 11
remaining problems are other groups' records); test-inkling2-hip-host,
check-hip-kernel-contract-host; lean 165 on base and head, 0 new.
ashhart pushed a commit that referenced this pull request Nov 24, 2026
Move #4125's float64 attention reference from zig/tests/cuda into
core.contract.inkling2_attn_ref so the HIP contract can hold its kernels
to the same rounding points. A Call now names its query heads, key heads
and fp32 chains (Chain.cuda by default, Chain.hip for scalar IEEE sums),
and tauAt takes the model's n_floor (Mini's is 8,192).

CUDA's defaults are unchanged: the CUDA tests only change their import,
and a pinned test holds row() at CUDA's defaults to the bits the old
reference gave (checked bit for bit against it on sliding and global
rows before the move).

Checks: zig test of core.contract (17 pass); zig build
test-inkling2-cuda-host (10/10) and compile-cuda-tests on the tree.
ashhart pushed a commit that referenced this pull request Nov 24, 2026
A new inkling2 kernel group (strict IEEE build) with #4125's rounding
points on HIP: tf_ink2_prep (q/k L2 clips, tau on global layers, the
gamma-free v norm, k and v into each segment's ring), tf_ink2_rel_table,
chunked attention for sliding (tf_ink2_attn) and global layers
(tf_ink2_attn_fold, a split form a block a 1,024-key sub-chunk, and
tf_ink2_attn_prompt), and the ordered merge that takes the sink and the
gate raw. One wave holds a (row, head) pair over 64-key K/V tiles in
LDS with scalar fp32 sums; every path runs the same per-pair steps, so
split and prompt are bit-equal to the fold. The prompt kernel shares
each tile among 8 pairs in one 37 KiB LDS stage while the next tile
loads into registers. The kernels build for gfx1030, gfx1100, gfx1151
and gfx1201 (no scratch; records in hip_records_inkling2.zig).

The launcher (families/inkling2/hip_attention.zig) keeps heads, key
heads, floor and clips as runtime arguments and per-segment cache
offsets, as #4125's; whole-stream rings versus 64-position pages for
global KV stays open with the maintainer.

The contract entry (tf-hip-kernel-contract image inkling2) holds them
at Mini's 24/8 heads and n_floor 8,192 to core.contract's FP64
reference with HIP's chains, at served shapes to 1M keys on a ring that
wraps; three streams in one launch are bit-equal to each stream alone
(prep, sliding, fold, split). Eight controls go red at shapes, among
them a window one key long, the sink and gate given after their sigmoid
(#4387's glue) and a prep writing one stream's keys into another's.

Checks on gfx1151 with ROCm 10.1's hipcc: image inkling2 smoke and full,
11 kernels pass gates 1-4, 8 controls red, 0 limit problems;
hip-kernel-contract-limits passes all 24 inkling2 records (its 11
remaining problems are other groups' records); test-inkling2-hip-host,
check-hip-kernel-contract-host; lean 165 on base and head, 0 new.
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