Skip to content

feat(hip): Inkling 2's dense bf16 projections under HIP-DOT-Q4 - #5797

Merged
ashhart merged 4 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-inkling2-dense
Dec 1, 2026
Merged

ashhart merged 4 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-inkling2-dense

Conversation

@AbrahamCete

@AbrahamCete AbrahamCete commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Inkling 2 Mini on HIP has attention (#4633, #5499), loop kernels (#5012), routed experts (#4994), text weights (#5031), serve-flag refusals (#5034), and per-stream state/snapshots (#5728), but no HIP dense bf16 projection kernel (q, k, v, rel, gate, sink, global k/v taps, wo, and the router scores). This adds the inkling2_dense kernel group (tf_ink2_dense) under the HIP-DOT-Q4 serial dot baseline, its host geometry/refusal launcher, its host and GPU contract suite, its four-chip launch records, and its docs/kernel-contract.md entry. No forward pass, serving path, or inference caller calls it yet.

This branch carries three commits:

  1. 1978eadff build(hip): share Inkling 2 family files in one module across HIP contract launchers: Zig 0.17 requires each source file to belong to one module. After perf(hip): Inkling 2's loop kernels (cross-pass message and message gate) at hidden 2,304 and 256 under named HIP baselines #5012, feat(hip): Inkling 2's routed experts under HIP-DOT-Q4, the HIP column's serial dot baseline #4994, feat(hip): Inkling 2's attention at each layer's bias extent, tiny-inkling2-mini's 128 and 256 beside Mini's 1,024 #5499, and feat(hip): Inkling 2 Mini's per-stream state and prompt snapshots on one HIP rank #5728, inkling2_hip, inkling2_loop_hip, inkling2_experts_hip, and the stream state targets (hip_engine, hip_snapshot) all imported config.zig directly, causing duplicate module ownership inside tf-hip-kernel-contract. This groups the shared family files (config, plan, names, names_test, loop, kept_state, hip_weights, config_test) into zig/src/families/inkling2/hip_family.zig and passes one shared inkling2_family module into the Inkling 2 HIP launcher and state modules.
  2. 8f40f56fa feat(hip): Inkling 2's dense bf16 projections under HIP-DOT-Q4, the serial dot baseline: adds zig/kernels/hip/inkling2/dense.hip (tf_ink2_dense plus seven planted controls), zig/src/families/inkling2/hip_dense.zig + hip_dense_test.zig, zig/tests/hip/contract_inkling2_dense.zig + contract_inkling2_dense_ref.zig, zig/src/core/contract/hip_records_inkling2_dense.zig, build/registry wiring, and docs/kernel-contract.md.
  3. 1ed1386a7 refactor(hip): share bf16 lo16/hi16 and HIP-DOT-Q4 quad join in zmath.hpp: moves the packed bf16 unpack helpers (lo16, hi16) and the four-chain HIP-DOT-Q4 pairwise join (q4Join) into zig/kernels/hip/inkling2/zmath.hpp (namespace ink2z), replaces the four local copies across dense.hip, tile.hpp, loop.hip, and experts.hip, and updates hip_records_inkling2_experts.zig for tf_ink2_mxfp8_gu dropping from 95 to 94 VGPRs on gfx1100, gfx1151, and gfx1201.

Checks on this head

  • Head commit: 1ed1386a7 (on main f17dedbd9, after feat(hip): Inkling 2 Mini's per-stream state and prompt snapshots on one HIP rank #5728 merged).
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: base 88 problems (inherited), head 88 problems, 0 new (python3 tools/zig/lean_new.py: lean: 88 problems, 88 on the base, 0 new).
  • Tests run, with the command and pass, fail and skip counts:
    • zig fmt --check build.zig zig and git diff --check f17dedbd9..HEAD: passed (0 issues).
    • zig build -Dhip=true test-inkling2-dense-hip-host: 19 passed, 0 failed, 0 skipped (hip_dense_test.zig 11/11, contract_inkling2_dense_ref.zig 8/8).
    • zig build -Dhip=true test-inkling2-hip-state-host: passed (0 failed).
    • zig build -Dhip=true test-inkling2-hip-host: passed (0 failed; names_test.zig skips 2 local checkpoint env-var tests).
    • zig build -Dhip=true test-inkling2-loop-hip-host: 33 passed, 0 failed, 0 skipped.
    • zig build -Dhip=true test-inkling2-experts-hip-host: 27 passed, 0 failed, 0 skipped.
    • zig build -Dhip=true check-hip-kernel-contract-host: compiled clean.
    • zig build -Dhip=true test-kernel-symbols-host: 6 passed, 0 failed, 0 skipped.
    • zig build -Dhip=true -Dhipcc=$HIPCC hip-kernel-contract-limits: 32/32 PASS for inkling2_dense (8 symbols across gfx1030, gfx1100, gfx1151, gfx1201, 0 scratch bytes, 0 stale records) and 120/120 PASS for inkling2_experts (30 symbols across all 4 chips after q4Join sharing, 0 scratch bytes, 0 stale records).
    • tf-hip-kernel-contract image inkling2_dense smoke on Radeon 8060S (gfx1151): exit 0 (8/8 kernels pass gates 1-4, 14/14 controls red as planted, 0 limit problems).
    • tf-hip-kernel-contract image inkling2_dense full on Radeon 8060S (gfx1151): exit 0 (8/8 kernels pass gates 1-4, 14/14 controls red as planted, 0 limit problems).
    • tf-hip-kernel-contract image inkling2_experts smoke on Radeon 8060S (gfx1151, regression after zmath.hpp dedup): exit 0 (29/29 kernels pass gates 1-4, 62/62 controls red as planted, 0 limit problems).
  • CI: 5/5 active checks passed on 1ed1386a7 (fmt, pytest, zig, benchmark-clients (ubuntu-latest), comfyui-moss-installer; 6 optional jobs skipped).
  • Not run, and why:
    • GPU execution on gfx1030, gfx1100, and gfx1201: only a gfx1151 machine is available here; those three targets were compiled and audited against their .hsaco metadata via hip-kernel-contract-limits.
    • Served inference benchmarks (bench_openai.py, bench_concurrent.py, bench_cache.py): n/a, no forward pass or server path reaches inkling2_dense yet.

Receipt

n/a: no forward, server, or inference path reaches inkling2_dense yet. The host model tests (19/19), four-chip .hsaco limits audit (32/32 PASS dense, 120/120 PASS experts), and gfx1151 GPU kernel contracts (inkling2_dense smoke + full and inkling2_experts smoke, all exit 0) are the evidence.

  • Main against branch: n/a (no inference caller reaches inkling2_dense yet).
  • Boxes it reaches: n/a (kernel contract only).
  • New switch? Default, accepted values, profile row: none.
  • Environment: TensorFold base f17dedbd9 / head 1ed1386a7, Zig 0.17.0, ROCm TheRock 10.1.0 (HIP version: 7.16.26385-0000000, AMD clang version 24.0.0git), Ubuntu 26.04.1 LTS (kernel 7.0.0-44-generic), Radeon 8060S (gfx1151), tf-hip-kernel-contract sha256 a7cde3d60569439b25dc72abd898625af39a4a8b389b8fc7abd5f8fc5229f414; checkpoint: n/a (synthetic contract inputs covering Inkling 2 Mini and tiny-inkling2-mini geometries).
  • Paths and platforms the change reaches, which I ran and which I could not: HIP inkling2_dense kernel contract (tf_ink2_dense and 7 controls), zmath.hpp shared helpers across dense.hip, tile.hpp, loop.hip, and experts.hip, plus hip_family.zig shared across inkling2, inkling2_loop, inkling2_experts, and hip_engine/hip_snapshot. GPU-executed on gfx1151; compiled and ELF-limit-audited on gfx1030, gfx1100, gfx1151, and gfx1201; not GPU-executed on gfx1030, gfx1100, or gfx1201 (hardware unavailable).
  • Exactness: n/a for served inference (no inference caller); kernel contract verifies exact bit-for-bit equality against the HIP-DOT-Q4 host model in contract_inkling2_dense_ref.zig across rows {1, 4, 8, 16, 64, 128, 2048}, including solo row-37 invariance against a 64-row call, plus bit-exact inkling2_experts regression.
  • Main against this branch, same machine and checkpoint: n/a (no inference caller).
  • Decode speed before and after: n/a (no inference caller).
  • Prompt speed before and after: n/a (no inference caller).
  • Licence of any new weights or drafter: n/a (no new weights or drafter).
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: tf_ink2_dense in group inkling2_dense (new baseline kernel for Inkling 2 dense bf16 projections under HIP-DOT-Q4; replaces no prior HIP kernel). Registered across 8 checkpoint calls: Inkling 2 Mini and tiny-inkling2-mini sliding attention, global attention (with k/v taps), wo, and f32 router scores. inkling2_experts (tf_ink2_mxfp8_gu) keeps bit-exact behavior after sharing ink2z::q4Join and drops 1 VGPR (95 -> 94) on gfx1100, gfx1151, and gfx1201.
  • A planted control for each new kernel, and each one fails as planted: 7 planted control kernels tested at both Mini and tiny-inkling2-mini global layers (14 control runs total, all 14 red at shapes):
    • tf_ink2_dense_ctl_w32 (W32 lanes instead of HIP-DOT-Q4 chains)
    • tf_ink2_dense_ctl_serial (single serial fmaf chain)
    • tf_ink2_dense_ctl_quarters (contiguous quarters per chain)
    • tf_ink2_dense_ctl_seq_join (((c0 + c1) + c2) + c3 sequential join)
    • tf_ink2_dense_ctl_unfused (products rounded before add)
    • tf_ink2_dense_ctl_row_late (x read one row late)
    • tf_ink2_dense_ctl_neighbour (q and k written into each other's output)
  • Each backend's SUMMARY line and exit status:
    • HIP gfx1151 inkling2_dense smoke (exit 0):
      SUMMARY inkling2_dense HIP smoke: 8 kernels: 8 pass gates 1-4, 0 fail, 0 known findings; 14 controls: 14 red as planted, 0 missed; 0 limit problems; gates 6135 ms, limits 5 ms
    • HIP gfx1151 inkling2_dense full (exit 0):
      SUMMARY inkling2_dense HIP full: 8 kernels: 8 pass gates 1-4, 0 fail, 0 known findings; 14 controls: 14 red as planted, 0 missed; 0 limit problems; gates 15645 ms, limits 5 ms
    • HIP gfx1151 inkling2_experts smoke regression (exit 0):
      SUMMARY inkling2_experts HIP smoke: 29 kernels: 29 pass gates 1-4, 0 fail, 0 known findings; 62 controls: 62 red as planted, 0 missed; 0 limit problems; gates 12352 ms, limits 46 ms
  • Chips I could not run: gfx1030, gfx1100, gfx1201 (compiled and verified with 0 limit problems via hip-kernel-contract-limits; not GPU-executed due to no local hardware).

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • 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 in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (n/a: no inference caller)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (n/a: no inference caller)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (n/a: new baseline under HIP-DOT-Q4, no inference caller)
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (n/a: no inference caller)

@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Thanks @AbrahamCete. This gives the HIP column Inkling 2's dense projections under the same HIP-DOT-Q4 order as the experts. The contract is thorough: seven planted controls that each go red, the row-37 invariance cell, and records for all four chips.

What I checked at e2fc9cef54:

  • Nothing served changes. No forward pass calls tf_ink2_dense. dense.hip only joins the HIP image list (zig/build/hip.zig:512, zig/src/hip/kernels.zig:28). Every HIP engine loads every group's image at startup (zig/src/hip/launches.zig:210), so the models served on HIP load one more code object and launch nothing from it.
  • The kernel keeps the documented order. Chain j takes chunks 4i + j (dense.hip:58), its fmaf chain starts from +0, and the quad joins (c0 + c1) + (c2 + c3) (dense.hip:69-70). Outputs are rounded to bf16 once through zmath.hpp's tobf. contract_inkling2_dense_ref.zig restates the order on its own.
  • The PR adds no switch, keeps every file under 600 lines, and adds no lean problems against main.
  • The shared family module fixes a real break: on main, the contract runner puts config.zig in three modules.

Asks:

  1. Main has moved since your base, and it conflicts in zig/build/hip_contract.zig. We'll bring the branch onto main and push it to you, but the module change needs one more step after that. Your stream-state work on main (53ef64d43d, 60a6ec21db) builds hip_engine.zig and hip_snapshot_test.zig in their own modules (state(), zig/build/hip_contract.zig:144, used at lines 64 and 96). hip_engine.zig imports hip_attention.zig by path. With this PR, hip_attention.zig:4 imports inkling2_family, which those modules don't have. That breaks the build of test-inkling2-hip-state-host and of the snapshot check that zig build test compiles. Adding the import alone puts config.zig in two modules again, because hip_engine.zig:4, hip_snapshot.zig:3 and loop.zig:3 import it by path. Please bring those files under the shared module, or put all of Inkling 2's HIP launchers in one module if that's simpler. Then rerun test-inkling2-hip-host, test-inkling2-hip-state-host and check-hip-kernel-contract-host.
  2. Small: dense.hip:33-34 defines lo and hi, which tile.hpp:38-39 already has as lo16 and hi16, and loop.hip and experts.hip repeat them. Please take them from one shared header, ideally zmath.hpp, which dense.hip already includes. If it's easy, move the HIP-DOT-Q4 quad join there too, so dense.hip and experts.hip can't drift apart.

Once these are in, it's ready for our device check. On a Radeon 8060S (gfx1151), we'll run tf-hip-kernel-contract image inkling2_dense full and the three existing Inkling 2 groups. We'll also check one HIP-served model's replies and load line against main, to confirm the extra image changes nothing.

  • Synthena

@AbrahamCete
AbrahamCete force-pushed the feat/hip-inkling2-dense branch from e2fc9ce to 8f40f56 Compare December 1, 2026 07:10
@AbrahamCete

Copy link
Copy Markdown
Contributor Author

Both points are addressed on head 1ed1386a7 (rebased onto main f17dedbd9):

  1. Rebase onto feat(hip): Inkling 2 Mini's per-stream state and prompt snapshots on one HIP rank #5728 and inkling2_family wiring are in 1978eadff and 8f40f56fa. hip_family.zig exports loop, kept_state, hip_weights, and config_test, and hip_engine, hip_snapshot, and state() use the shared inkling2_family module. Verified with test-inkling2-hip-state-host, test-inkling2-hip-host, check-hip-kernel-contract-host, and inkling2-hip-state-test on gfx1151 (exit 0).
  2. lo16, hi16, and q4Join are now defined once in zig/kernels/hip/inkling2/zmath.hpp (namespace ink2z) in 1ed1386a7, replacing the four local copies across dense.hip, tile.hpp, loop.hip, and experts.hip. Sharing q4Join dropped tf_ink2_mxfp8_gu by 1 VGPR (95 -> 94) on gfx1100, gfx1151, and gfx1201; hip_records_inkling2_experts.zig is updated accordingly.

Re-verified on 1ed1386a7:

  • lean_new.py: 0 new (88 = 88).
  • hip-kernel-contract-limits: inkling2_dense 32/32 PASS, inkling2_experts 120/120 PASS.
  • gfx1151 GPU contracts: inkling2_dense smoke and full (8/8 pass, 14/14 controls red) and inkling2_experts smoke (29/29 pass, 62/62 controls red), all exit 0.

The PR description is updated to match 1ed1386a7, and #5800 is rebased onto it.

@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Reviewed at this head: nothing served calls the new kernel, and the Inkling 2 HIP modules now share one family module, which also repairs main's HIP kernel-contract build. On a Radeon 8060S (gfx1151): the HIP kernel tests and the Inkling 2 HIP host and state tests pass, the inkling2 image's 27 kernels and the new inkling2_dense image's 8 kernels pass the full contract, and every planted control goes red. This head's CI passed. Thank you!

  • Synthena

AbrahamCete and others added 4 commits December 1, 2026 14:14
…tract launchers

Zig 0.17 requires each source file to belong to one module. After ashhart#5012,
ashhart#4994, ashhart#5499 and ashhart#5728, inkling2_hip, inkling2_loop_hip,
inkling2_experts_hip and the stream state targets all imported config.zig
directly, causing duplicate module ownership inside tf-hip-kernel-contract.

Group the shared Inkling 2 family files (config, plan, names, names_test,
loop, kept_state, hip_weights, config_test) into
zig/src/families/inkling2/hip_family.zig and pass one inkling2_family
module into the Inkling 2 HIP launcher and state modules.
…erial dot baseline

Inkling 2 Mini's dense projections (q, k, v, rel, gate, sink, a global
layer's k and v taps, wo and the router's scores) get their own strict
HIP group, inkling2_dense, under a named baseline: HIP-DOT-Q4. Input e
goes to chain (e / 32) mod 4; each chain starts at +0 and runs ascending,
one fmaf(w, x, acc) a step on bf16 w and x widened exactly; the chains
join as (c0 + c1) + (c2 + c3); the result is rounded once to bf16, or
kept in f32 where a segment asks for it.

tf_ink2_dense takes up to eight segments of one depth in a launch, so a
layer's attention projections are one launch and wo and the router one
each. A quad of lanes computes an output, lane j running chain j, and
one weight read serves up to 16 rows, so no sum depends on how a call
groups its rows.

hip_dense.zig reads every width and depth from the parsed config and
refuses by name what the kernel cannot serve: UnsupportedDenseDepth for
a hidden_size, wo depth or launch depth that is not a multiple of 128,
Inkling2DenseShape for rows, segment counts and empty segments outside
the kernel's range, Inkling2DenseAlign for bases off 16 bytes.

The contract runs Inkling 2 Mini's and tiny-inkling2-mini's sliding and
global attention calls, wo and the router at 1 to 2,048 rows, each
output's bits against a host model of HIP-DOT-Q4. Its cells separate
the chain assignment, the join and fmaf from the plausible other orders,
and an invariance cell runs one row alone against its row of a 64-row
call. Seven controls go red at shapes: W32 lanes, one serial chain,
contiguous quarters, a sequential join, rounded products, x one row
late, and two segments' outputs swapped.
….hpp

Define lo16, hi16 and q4Join once in zig/kernels/hip/inkling2/zmath.hpp
and reuse them from dense.hip, tile.hpp, loop.hip and experts.hip so the
Inkling 2 HIP groups share one bf16 pair decoder and one HIP-DOT-Q4 quad
join.
@ashhart
ashhart force-pushed the feat/hip-inkling2-dense branch from 1ed1386 to 95b593d Compare December 1, 2026 14:14
@ashhart
ashhart merged commit fbb0cf0 into ashhart:main Dec 1, 2026
4 of 9 checks passed
@ashhart

ashhart commented Dec 1, 2026

Copy link
Copy Markdown
Owner

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

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.

2 participants