[HIP] loop-controller kernels (RMS pack + gain/forget apply) verified

- k_ctrl_pack / vetta_ctrl_pack: exact strata k1_loop_ctrl_rms +
  k1_loop_ctrl_pack_in_bf16 — inv_c=rsqrt(mean(cur^2)+eps),
  inv_m=rsqrt(mean(msg^2)+eps); packed BF16 [2D] = [cur*inv_c ; msg*inv_m].
- k_ctrl_apply / vetta_ctrl_apply: exact k1_loop_ctrl_apply_out —
  out = (1-tanh(forget))*cur + tanh(gain)*msg (gain/forget gating of the loop
  message). The down/gain/forget low-rank projections reuse gemm_bf16.
- loop_controller_parity_vs_cpu: full controller chain (pack -> down GEMM
  [gate_rank] -> cast -> gain/forget GEMM [D] -> apply) vs a CPU oracle:
  max_rel_err 1.6e-7. The loop controller composes correctly.

This is the last kernel needed for the full Inkling forward. All mechanisms
(SWA + full-attn attention, MoE NVFP4, deep-residual block-mix, shortconv
static/dyn, loop controllers) are now verified microkernels.

Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (5 files) green; GPU 17/17 (--features hip).
This commit is contained in:
adm committed 2026-12-01 15:07:02 +01:00
1 parent 5ae2072981
commit 38ac957b26
3 files changed
+129

No files matched your search

+8
View File
@@ -121,6 +121,14 @@ int vetta_kv_store(const float* k_in, const float* v_in, float* k_cache,
// k_softcap: y = cap * tanh(x / cap) (final logit softcapping).
int vetta_softcap(const float* x, float* y, size_t n, float cap, vetta_stream_t stream);
// k_ctrl_pack: RMS-normalize cur & msg -> packed BF16 [2D] (loop controller input).
int vetta_ctrl_pack(const float* cur, const float* msg, uint16_t* packed, int D,
float eps, vetta_stream_t stream);
// k_ctrl_apply: out = (1-tanh(forget))*cur + tanh(gain)*msg (loop gating).
int vetta_ctrl_apply(const float* cur, const float* msg, const float* gain,
const float* forget, float* out, size_t n, vetta_stream_t stream);
// Core <15 microkernel entry points (implemented progressively in M1 & M2):
// 1. k_embed_bf16
// 2. k_rms_norm