[HIP] FP16 KV cache path (strata default), opt-in VETTA_F16_KV

strata stores K/V in FP16 by default (KvDtype::FP16, 'default lossless FP16');
vetta used F32. Add k_kv_store_f16 (RNE round to u16 cache) + k_flash_swa_gqa_decode_f16
(f32 attention math over FP16 KV), FFI/wrappers, and a new_state/forward branch
gated by VETTA_F16_KV=1 (F32 stays the CPU-oracle baseline). New GPU parity test
fp16_kv_store_and_flash_parity: stored K == cast_f32_f16 bits, attention over the
decoded FP16 KV matches a CPU oracle fed the same values (18 hip GPU green).

MEASURED honestly: FP16 KV does NOT fix the chat token-2+ divergence (still
~3.6 logit gap vs reference, robust also to VETTA_F16_EXPERT and -ffp-contract=off).
The gap is a systematic multi-token accumulation difference, not KV precision;
kept as faithful opt-in infrastructure, not claimed as a parity fix.
This commit is contained in:
adm committed 2026-12-01 17:42:57 +01:00
1 parent dfa6013bfd
commit 74b3384270
4 files changed
+295 -18

No files matched your search

+13
View File
@@ -64,6 +64,14 @@ int vetta_flash_swa_gqa_decode(const float* q, const float* k, const float* v,
const float* sink_logit, const float* gate,
vetta_stream_t stream);
// k_flash_swa_gqa_decode_f16: FP16 KV cache variant (strata default FP16 KV).
int vetta_flash_swa_gqa_decode_f16(const float* q, const uint16_t* k, const uint16_t* v,
float* out, int n_head, int n_kv, int seq, int hd,
float scale, int swa_window, int cur_pos,
const float* rel_bias, int max_rel,
const float* sink_logit, const float* gate,
vetta_stream_t stream);
// k_moe_router_topk: Inkling exact sigmoid router (top-K, route_scale norm).
int vetta_moe_router_topk(const float* logits, const float* bias,
int32_t* topk_ids, float* topk_weights,
@@ -146,6 +154,11 @@ 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_kv_store_f16: K/V rounded to FP16 (RNE) -> contiguous u16 cache (strata FP16 KV).
int vetta_kv_store_f16(const float* k_in, const float* v_in, uint16_t* k_cache,
uint16_t* 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);