[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

+17
View File
@@ -794,4 +794,21 @@ extern "C" int vetta_kv_store(const float* k_in, const float* v_in, float* k_cac
k_kv_store<<<n_kv, 256, 0, s>>>(k_in, v_in, k_cache, v_cache, pos, n_kv, hd, seq, rms_eps);
HIP_CHECK(hipGetLastError());
return 0;
}
// ---- k_softcap: logits = cap * tanh(x / cap) (final logit softcapping) -----
__global__ void k_softcap(const float* __restrict__ x, float* __restrict__ y, size_t n, float cap) {
size_t i = (size_t)blockIdx.x * blockDim.x + threadIdx.x;
if (i < n) y[i] = cap * tanhf(x[i] / cap);
}
extern "C" int vetta_softcap(const float* x, float* y, size_t n, float cap, vetta_stream_t stream) {
if (n == 0) return 0;
if (cap <= 0.f) return 1;
const int nt = 256;
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
k_softcap<<<(n + nt - 1) / nt, nt, 0, s>>>(x, y, n, cap);
HIP_CHECK(hipGetLastError());
return 0;
}