Skip to content

feat(hip): Inkling 2's embedding norm and attention residuals under HIP-RMS-W32, HIP-RETRIEVE-W32, HIP-NORM-W and HIP-AR-SHARES - #5813

Open
AbrahamCete wants to merge 4 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-inkling2-norms
Open

AbrahamCete wants to merge 4 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-inkling2-norms

Conversation

@AbrahamCete

@AbrahamCete AbrahamCete commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Inkling 2 Mini on HIP has dense projections (#5797), logits (#5800), short convolutions/rewind/router (#5809), 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 embedding norm or attention-residual mixing kernels. This adds the final HIP2 kernel group, inkling2_norms (tf_ink2_embed, tf_ink2_ar, tf_ink2_mix), under four named baselines (HIP-RMS-W32, HIP-RETRIEVE-W32, HIP-NORM-W, HIP-AR-SHARES), shares the W32 device helpers (inkling2/w32.hpp, reused by loop.hip and auto-tracked by hip_headers.zig) and the W32 host model (contract_inkling2_w32.zig, reused by contract_inkling2_loop_ref.zig), wires hip_norms.zig directly on inkling2_family, and adds host and GPU contract suites, four-chip launch records, and docs/kernel-contract.md entries. No forward pass, serving path, or inference caller calls it yet.

Rebased onto main 11729eec9 (after #5809 merged at 7df094676, keeping main's hip_headers.zig auto-collector), this PR adds four commits (18 changed files):

  1. e17851cd3 feat(hip): carry HIP-RMS-W32 and HIP-RETRIEVE-W32's W32 sums into inkling2/w32.hpp, with their host model: adds zig/kernels/hip/inkling2/w32.hpp (using ink2z::lo16/hi16 from inkling2/zmath.hpp for bf16 chunk loads, plus ld4, invSqrt, inverse, butterfly, squares, and dot), switches zig/kernels/hip/inkling2/loop.hip to reuse inkling2/w32.hpp (.text and .note sections of loop.hip are byte-identical before vs after across all four chips: gfx1030, gfx1100, gfx1151, gfx1201), and adds the W32 host model and order cells.
  2. b8fd87ef1 feat(hip): Inkling 2's embedding norm and attention residuals under HIP-RMS-W32, HIP-RETRIEVE-W32, HIP-NORM-W and HIP-AR-SHARES: adds zig/kernels/hip/inkling2/norms.hip (tf_ink2_embed, tf_ink2_ar, tf_ink2_mix, and 19 planted controls), zig/src/families/inkling2/hip_norms.zig + hip_norms_test.zig (config-driven geometry and refusals: UnsupportedNormsHidden, UnsupportedNormsSources, UnsupportedNormsQueries), zig/tests/hip/contract_inkling2_norms{,_plan,_ref,_ref_test}.zig, zig/src/core/contract/hip_records_inkling2_norms.zig, build/registry wiring, and docs/kernel-contract.md.
  3. 735b6cd37 refactor(hip): share W32 host reference with loop and wire inkling2_norms on inkling2_family: renames the W32 host model to zig/tests/hip/contract_inkling2_w32.zig and shares it with contract_inkling2_loop_ref.zig (removing ~120 duplicated lines), and wires hip_norms.zig and hip_norms_test.zig directly on inkling2_family (dropping norms_dense in hip_contract.zig).
  4. ca65baf1e fix(hip): refuse zero or excess residual blocks in hip_norms.geometry: addresses review feedback by replacing divCeil ... catch unreachable in hip_norms.geometry with explicit UnsupportedNormsSources refusals (block == 0 and blocks > max_blocks) + host unit test, and updates docs/kernel-contract.md to name contract_inkling2_w32.zig (no .hip/.hpp changes).

Checks on this head

  • Head commit: ca65baf1e (fast-forward host/doc fix over 735b6cd37 on main 11729eec9; no .hip/.hpp files changed).
  • Lean checker, python3 tools/zig/lean_check.py: 88 problems across 9,759 files (0 new over main; zig/build/hip.zig is 595 lines).
  • Env lookup check, python3 tools/zig/env_lookups.py: passed (0 issues).
  • Tests run, with the command and pass, fail and skip counts:
    • zig fmt --check build.zig zig and git diff --check origin/main..HEAD: passed (0 issues).
    • zig build -Dhip=true -Dhipcc=/bin/false test-inkling2-norms-hip-host test-inkling2-loop-hip-host check-hip-kernel-contract-host on ca65baf1e (and full 7-suite host run including test-inkling2-conv-hip-host test-hip-headers test-create-defaults-host test-kernel-symbols-host on 735b6cd37): passed (0 failed).
    • zig build hip-kernel-contract-limits -Dhip=true -Dhip-arch=gfx1151 -Dhipcc=$HIPCC: inkling2_norms 88/88 PASS, 0 fail (0 scratch bytes, 0 stale records across gfx1030/gfx1100/gfx1151/gfx1201).
    • loop.hip code-object parity before vs after w32.hpp extraction (clang-offload-bundler --unbundle + llvm-objcopy --dump-section .text + llvm-readelf --notes): .text and .note byte-identical across all four chips (gfx1030, gfx1100, gfx1151, gfx1201).
    • tf-hip-kernel-contract image inkling2_norms smoke on Radeon 8060S (gfx1151): exit 0 (21/21 kernels pass gates 1-4, 35/35 controls red as planted, 0 limit problems).
    • tf-hip-kernel-contract image inkling2_norms full on Radeon 8060S (gfx1151): exit 0 (21/21 kernels pass gates 1-4, 35/35 controls red as planted, 0 limit problems).
    • tf-hip-kernel-contract image inkling2_loop smoke on Radeon 8060S (gfx1151): 7/7 kernels pass gates 1-4, 21/21 controls red as planted (328 ms; the 21 live limit mismatches are pre-existing toolchain drift on main, unchanged by w32.hpp).
  • CI: passed 100% on 735b6cd37 (zig, fmt, pytest, verify); will re-run after fast-forward pushing ca65baf1e.
  • Not run, and why:
    • GPU execution on gfx1030, gfx1100, and gfx1201: only a gfx1151 machine is available here; all four chips' .hsaco metadata passed hip-kernel-contract-limits (88/88 PASS, 0 scratch bytes, 0 stale records) and loop.hip .text/.note parity held across all four chips.
    • Metal, CUDA, and Windows builds: HIP-only kernel contract slice, no Metal/CUDA/Windows code changed.
    • Served inference benchmarks (bench_openai.py, bench_concurrent.py, bench_cache.py): n/a, no forward pass or server path reaches inkling2_norms yet.

Receipt

n/a: no forward, server, or inference path reaches inkling2_norms yet. The host tests (-Dhipcc=/bin/false), four-chip .hsaco limits audit (88/88 PASS), four-chip loop.hip .text/.note byte-identity check, and gfx1151 GPU kernel contracts (inkling2_norms smoke + full, both exit 0, plus inkling2_loop smoke 7/7 gates + 21/21 controls red) are the evidence.

  • Main against branch: n/a (no inference caller reaches inkling2_norms yet).
  • Boxes it reaches: n/a (kernel contract only).
  • New switch? Default, accepted values, profile row: none.
  • Environment: TensorFold base main 11729eec9 (includes merged feat(hip): Inkling 2's short convolutions, rewind and router under named baselines #5809 7df094676), head ca65baf1e (GPU contract runs from 735b6cd37; zero .hip/.hpp changes in ca65baf1e), 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 daf5767c620bc3d89c994482e0a8085a5f26c0a4ba416e402fc2e5d14278ca73; checkpoint: n/a (synthetic contract inputs covering Inkling 2 Mini, tiny-inkling2-mini, and an rms_norm_eps = 0.25 cell).
  • Paths and platforms the change reaches, which I ran and which I could not: HIP inkling2_norms (tf_ink2_embed, tf_ink2_ar, tf_ink2_mix, and 19 control kernels) and inkling2/loop.hip (w32.hpp header share, byte-identical .text and .note across all four chips). 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 host models in contract_inkling2_w32.zig and contract_inkling2_norms_ref.zig (HIP-RMS-W32, HIP-RETRIEVE-W32, HIP-NORM-W, HIP-AR-SHARES) across 1 to 2,048 rows, 1 to 9 sources, 1 to 3 queries, bf16 and f32 partials, and rms_norm_eps = 0.25, including solo row-37 invariance against a 64-row call.
  • 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_embed, tf_ink2_ar, and tf_ink2_mix in group inkling2_norms (new baseline kernels under HIP-RMS-W32, HIP-RETRIEVE-W32, HIP-NORM-W, and HIP-AR-SHARES; replace no prior HIP kernels). Registered across 21 entries: 9 for Inkling 2 Mini (hidden = 2,304, 5 sources), 9 for tiny-inkling2-mini (hidden = 256, 4 sources), and 3 at rms_norm_eps = 0.25 (embed, ar, mix).
  • A planted control for each new kernel, and each one fails as planted: 35 control runs across 19 control kernels (16 Mini + 16 tiny + 3 eps_fixed at rms_norm_eps = 0.25), all 35 red at shapes:
    • tf_ink2_embed (3 controls): tf_ink2_embed_ctl_serial_rho, tf_ink2_embed_ctl_norm_bf16, tf_ink2_embed_ctl_eps_fixed.
    • tf_ink2_ar (9 controls): tf_ink2_ar_ctl_rsqrt, tf_ink2_ar_ctl_serial_rho, tf_ink2_ar_ctl_serial_dot, tf_ink2_ar_ctl_butterfly_desc, tf_ink2_ar_ctl_unfused_sq, tf_ink2_ar_ctl_fused_shares, tf_ink2_ar_ctl_sources_desc, tf_ink2_ar_ctl_expf, tf_ink2_ar_ctl_eps_fixed.
    • tf_ink2_mix (7 controls): tf_ink2_mix_ctl_serial_rho, tf_ink2_mix_ctl_butterfly_desc, tf_ink2_mix_ctl_h_bf16, tf_ink2_mix_ctl_skip_source, tf_ink2_mix_ctl_norm_bf16, tf_ink2_mix_ctl_no_norm, tf_ink2_mix_ctl_eps_fixed.
  • Each backend's SUMMARY line and exit status:
    • HIP gfx1151 inkling2_norms smoke (exit 0):
      SUMMARY inkling2_norms HIP smoke: 21 kernels: 21 pass gates 1-4, 0 fail, 0 known findings; 35 controls: 35 red as planted, 0 missed; 0 limit problems; gates 125 ms, limits 14 ms
    • HIP gfx1151 inkling2_norms full (exit 0):
      SUMMARY inkling2_norms HIP full: 21 kernels: 21 pass gates 1-4, 0 fail, 0 known findings; 35 controls: 35 red as planted, 0 missed; 0 limit problems; gates 1104 ms, limits 14 ms
    • HIP gfx1151 inkling2_loop smoke (gates/controls PASS, 21 pre-existing main limit mismatches):
      SUMMARY inkling2_loop HIP smoke: 7 kernels: 7 pass gates 1-4, 0 fail, 0 known findings; 21 controls: 21 red as planted, 0 missed; 21 limit problems; gates 328 ms, limits 21 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 baselines under HIP-RMS-W32, HIP-RETRIEVE-W32, HIP-NORM-W, HIP-AR-SHARES, 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 2, 2026

Copy link
Copy Markdown
Owner

Thanks for the final HIP2 kernel group and the byte-identity proof for the shared header.

Decision: ready for our review. No device cells are owed by anyone - the gfx1151 run is yours and is the accepted form for HIP, the other chips' .hsaco metadata passes the limits audit without hardware, and no forward pass or serving path calls it yet. The remaining HIP5 forward/lane/serve stack and HIP6 DSpark are open on their own PRs.

What stands: the three kernels (tf_ink2_embed, tf_ink2_ar, tf_ink2_mix) under four named baselines (HIP-RMS-W32, HIP-RETRIEVE-W32, HIP-NORM-W, HIP-AR-SHARES), the W32 helpers shared into inkling2/w32.hpp with loop.hip's .text and .note sections byte-identical across all four chips, the W32 host model shared with the loop reference (~120 duplicated lines removed), the 88/88 four-chip limits audit, and the gfx1151 contract runs (21/21 kernels, 35/35 controls red, 0 limit problems). No served byte can move.

  • Synthena

…ling2/w32.hpp, with their host model

The Inkling 2 norms and attention residuals reuse the loop kernels' named
baselines. inkling2/w32.hpp holds their device steps over inkling2/zmath.hpp's
lo16/hi16: element e to lane (e / 8) % 32, each lane's chain ascending from +0
by fmaf, the xor butterfly 1, 2, 4, 8, 16, and rho's inverse
1 / sqrt(s / n + eps) with a correctly rounded square root and division.
inkling2/loop.hip now includes inkling2/w32.hpp instead of duplicating those
helpers (identical gfx1151 .text disassembly).

contract_inkling2_norms_w32.zig restates them on the host with the loop
contract's definitions of sumIn, w32Sum, inverseAt and depthW32, and with its
dot and rho cells: the dot cell sums to 1 under W32, 0 in one serial chain and
2 with the butterfly reversed; the rho cell's squares sum to
2^24 + 31 x hidden / 32 under W32 and to 2^24 in one serial chain.
test-inkling2-norms-hip-host runs them.
…IP-RMS-W32, HIP-RETRIEVE-W32, HIP-NORM-W and HIP-AR-SHARES

The inkling2_norms group (inkling2/norms.hip, a block a row) serves three
kernels. tf_ink2_embed norms each token's table row by embed_norm.
tf_ink2_ar writes the raw f32 attention residual of up to eight completed
blocks and a bf16 or f32 partial against one to three f32 queries.
tf_ink2_mix writes that residual normed by each query's weight in bf16,
and with no query norms the partial alone, which serves layer 0's
attention and the gated rows.

HIP-RMS-W32 and HIP-RETRIEVE-W32 are the loop kernels' W32 sums, through
inkling2/w32.hpp and their host model. HIP-NORM-W is bf16(w * (x * inv)),
two f32 multiplies and one round. HIP-AR-SHARES takes the max from -inf,
Zig's f32 exp of each difference, their sum from +0 and each quotient,
then h = (+0 + w_0 z_0) + w_1 z_1 ..., unfused, in ascending source order.

hip_norms.zig reads hidden_size, rms_norm_eps and the residual's sources
from the config and refuses a hidden size that is not a multiple of 256
by name (UnsupportedNormsHidden); the launches also refuse more than
eight blocks (UnsupportedNormsSources), more than three queries
(UnsupportedNormsQueries), bad shapes and unaligned bases. The contract
checks every output's bits against the host model at Mini's and
tiny-inkling2-mini's shapes, 1 to 2,048 rows and one to nine sources,
plus a cell at rms_norm_eps 0.25. It plants 35 controls, each red at
shapes. Records cover all four chips.
@AbrahamCete
AbrahamCete force-pushed the feat/hip-inkling2-norms branch from 2f20cb0 to 735b6cd Compare December 4, 2026 06:17
@AbrahamCete
AbrahamCete marked this pull request as ready for review December 4, 2026 06:17
@ashhart ashhart added kind:feature Classified by Synthena as feature addition synthena:needs-changes Reviewed by Synthena; changes requested labels Dec 4, 2026
@ashhart

ashhart commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Needs changes (kind:feature)

Adds the final HIP2 Inkling 2 kernel group (embedding norm, attention residuals, mixes) under four named baselines, sharing W32 device/host helpers with the loop kernels and adding contract suites, launch records, and docs. No forward-pass or serving caller is wired yet.

Findings:

  • [WARNING] zig/src/families/inkling2/hip_norms.zig: geometry() relies on config.zig rejecting block==0, but the comment is a cross-module invariant, not an enforced check here; if a Text with block==0 ever reaches this path the catch unreachable panics the host. Suggested fix: Handle the divCeil error explicitly (return error.UnsupportedNormsSources or a dedicated refusal) instead of catch unreachable, or assert the invariant with a debug assert and a comment pointing at the enforcing test.
  • Synthena

@AbrahamCete

Copy link
Copy Markdown
Contributor Author

Addressed in fast-forward commit ca65baf1e:

  • zig/src/families/inkling2/hip_norms.zig: replaced std.math.divCeil(u32, t.layers, t.block) catch unreachable in geometry() with explicit error.UnsupportedNormsSources refusals (with why.set(...)) for both t.block == 0 and blocks > max_blocks.
  • zig/src/families/inkling2/hip_norms_test.zig: added host unit test covering block == 0 and blocks > max_blocks (12 blocks).
  • docs/kernel-contract.md: fixed stale host-model filename contract_inkling2_norms_w32.zig -> contract_inkling2_w32.zig.

No .hip/.hpp files changed (code objects and four-chip limits are unchanged); re-verified zig fmt --check, lean_check (88, 0 new), and test-inkling2-norms-hip-host / test-inkling2-loop-hip-host / check-hip-kernel-contract-host on ca65baf1e.

@ashhart ashhart added synthena:needs-ash Needs owner decision and removed synthena:needs-changes Reviewed by Synthena; changes requested labels Dec 4, 2026
@ashhart

ashhart commented Dec 5, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Re-check of this head: the geometry() unreachable is now an explicit UnsupportedNormsSources refusal with a host test. HIP evidence is the author's gfx1151 contract run (21/21 kernels, 35/35 controls red); no inference caller on main reaches it yet.

  • Synthena

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:feature Classified by Synthena as feature addition synthena:needs-ash Needs owner decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants