[HIP] k2 attention-prep kernels: L2 clip, relpos bias projection, KV store
- k_l2_clip / vetta_l2_clip: exact strata Q/R/K per-head L2 clip — v = x*scale (scale nullable), fac = min(1, clip/(sqrt(sum v^2)+1e-6)), optional tau fac *= 1 + 0.1*log(max(1,(pos+1)/8192)) (kLogScaleAlpha=0.1, floor=8192); x = v*fac, in place. Config: qk_clip=22.627, rel_clip=8.0; tau=!is_swa. - k_relpos_bias / vetta_relpos_bias: rel_bias[h,dist] = sum_rc R[h,rc] * rel_proj[rc,dist] for dist < lim=min(pos+1,rel_extent). R pre-clipped [n_head,d_rel=16], rel_proj [d_rel,rel_extent=1024] (rel_logits_proj.proj). - k_kv_store / vetta_kv_store: K (pre-clipped) stored as-is, V RMS-normalized (rsqrt(mean v^2 + eps)), into a contiguous f32 KV cache [n_kv,seq,hd] at pos. (Paged FP16/FP8 KV pool is a later perf refinement; contiguous f32 first.) - Combined parity test vs CPU oracles: l2_clip (scale+tau and plain), relpos bias, kv_store (K exact, V <1e-5). These complete the k2 attention prep; with gemm_bf16 (projections) + shortconv4 + flash_swa_gqa the full attention block can now be composed. Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS; lean proofs (4 files, 42 theorems) green; GPU 14/14 (--features hip).
This commit is contained in:
1 parent
a5ee804641
commit
b5d6d7cee3
3 files changed
+220
No files matched your search
@@ -99,6 +99,20 @@ int vetta_attn_res_mix(const float* blocks, const float* cur, const float* queri
|
||||
float* out, int n_blocks, int M, int n_queries, int D,
|
||||
float eps, vetta_stream_t stream);
|
||||
|
||||
// k_l2_clip: per-head L2 clip + optional per-dim scale + optional tau (in place).
|
||||
int vetta_l2_clip(float* x, const float* scale, int rows, int hd, float clip,
|
||||
int apply_tau, int pos, vetta_stream_t stream);
|
||||
|
||||
// k_relpos_bias: rel_bias[h,dist] = sum_rc R[h,rc]*rel_proj[rc,dist], dist<lim.
|
||||
int vetta_relpos_bias(const float* r, const float* rel_proj, float* rel_bias,
|
||||
int n_head, int d_rel, int rel_extent, int lim,
|
||||
vetta_stream_t stream);
|
||||
|
||||
// k_kv_store: K (pre-clipped) as-is + V RMS-normalized -> contiguous f32 cache.
|
||||
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);
|
||||
|
||||
// Core <15 microkernel entry points (implemented progressively in M1 & M2):
|
||||
// 1. k_embed_bf16
|
||||
// 2. k_rms_norm
|
||||
|
||||
Reference in new issue
Block a user