[HIP][LD] softcap kernel + correct final output path (AttnRes output mix + softcap)

- k_softcap / vetta_softcap: logits = cap*tanh(x/cap), the final logit
  softcapping (Inkling cap=30). Parity vs CPU 9.7e-8; bounds |logits| <= cap.
- ld::layer::final_logits: the CORRECT final output path extracted from the
  reference — the final norm is itself an AttnRes depth mix over the block
  snapshots + cur with the learned output_query, then norm + unembed + softcap:
    h_norm = norm(attn_res_mix(blocks, cur, output_query))
    logits = softcap(unembed(h_norm), 30)
  (The earlier unembed_logits used a plain rms_norm(cur), missing the final
  depth mix; final_logits fixes that.)
- multi_layer_prelude_forward now uses final_logits: argmax token 128538
  (logit 19.16, bounded by 30). The token shifts vs the plain-norm path,
  confirming the final output mix materially affects the result.

Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (4 files, 42 theorems) green; GPU softcap + multi-layer final PASS
(--features hip, --ignored).
This commit is contained in:
adm committed 2026-12-01 14:51:40 +01:00
1 parent ff524df917
commit 2dd9ff952c
4 files changed
+65 -1

No files matched your search

+3
View File
@@ -113,6 +113,9 @@ int vetta_kv_store(const float* k_in, const float* v_in, float* k_cache,
float* v_cache, int pos, int n_kv, int hd, int seq,
float rms_eps, vetta_stream_t stream);
// 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);
// Core <15 microkernel entry points (implemented progressively in M1 & M2):
// 1. k_embed_bf16
// 2. k_rms_norm