[HIP] FP16 expert-path kernels (strata B=1 parity), opt-in; refactor run_experts
Add the exact strata B=1 FP16 expert path as verified kernels: k_cast_f32_f16 (RNE), k_nvfp4_gemv_f16 / k_mxfp8_gemv_f16 (FP16 activations, group partial dot then scale-fma, fdot2 order), k_situ_f16 (SiTU f32 -> stored FP16). Rust wrappers + expert_gemv_f16 dispatch. Refactor the duplicated SWA/full expert loops into ld::layer::run_experts. Default stays all-f32 (verified parity baseline); VETTA_F16_EXPERT=1 selects the FP16 path. MEASURED A/B (tok100): f32 argmax 220 (23.074) / 68014 22.643; fp16 argmax 220 (23.069) / 68014 22.632. FP16 shifts logits ~0.01 but does NOT flip the near-tie: the residual gap vs reference is the core-loop pass 1/2, NOT expert precision. FP16 kept opt-in for once the loop is fixed. New real_expert_nvfp4_gemv_f16_parity (GPU fp16 vs CPU oracle over same fp16-rounded x) green. Verified: workspace -D warnings, 18 ld GPU + 17 hip GPU green.
This commit is contained in:
1 parent
26bff57645
commit
e4dcc5e015
5 files changed
+316
-31
No files matched your search
@@ -78,21 +78,39 @@ int vetta_vec_add(const float* a, const float* b, float* y, size_t n,
|
||||
int vetta_cast_f32_bf16(const float* x, uint16_t* y, size_t n,
|
||||
vetta_stream_t stream);
|
||||
|
||||
// k_cast_f32_f16: f32 activation -> FP16 (RNE), exact strata k_f32_to_f16.
|
||||
int vetta_cast_f32_f16(const float* x, uint16_t* y, size_t n,
|
||||
vetta_stream_t stream);
|
||||
|
||||
// k_nvfp4_gemv (M=1): y[N] = dequant(W)[N,K] @ x[K], NVFP4 (E2M1 + E4M3/16 +
|
||||
// f32 outer_scale). packed [N,K/2], scales [N,K/16]. K % 16 == 0.
|
||||
int vetta_nvfp4_gemv(const uint8_t* packed, const uint8_t* scales,
|
||||
float outer_scale, const float* x, float* y,
|
||||
int N, int K, vetta_stream_t stream);
|
||||
|
||||
// k_nvfp4_gemv_f16: FP16-activation variant (exact strata B=1 expert path).
|
||||
int vetta_nvfp4_gemv_f16(const uint8_t* packed, const uint8_t* scales,
|
||||
float outer_scale, const uint16_t* x, float* y,
|
||||
int N, int K, vetta_stream_t stream);
|
||||
|
||||
// k_mxfp8_gemv (M=1): MXFP8 experts (layers 20..23). y[N] = sum_k e4m3(W[n,k])
|
||||
// * ue8m0(scale[n,k/32]) * x[k]. weights [N,K] F8_E4M3, scales [N,K/32] U8.
|
||||
int vetta_mxfp8_gemv(const uint8_t* weights, const uint8_t* scales,
|
||||
const float* x, float* y, int N, int K, vetta_stream_t stream);
|
||||
|
||||
// k_situ: SiTU double-softcapped MoE activation. gu=[gate;up] (2*inter) -> act.
|
||||
// k_mxfp8_gemv_f16: FP16-activation variant (exact strata MX8 expert path).
|
||||
int vetta_mxfp8_gemv_f16(const uint8_t* weights, const uint8_t* scales,
|
||||
const uint16_t* x, float* y, int N, int K, vetta_stream_t stream);
|
||||
|
||||
// k_situ: SiTU double-softcapped MoE activation. gu INTERLEAVED gate/up
|
||||
// (row 2j=gate[j], 2j+1=up[j], 2*inter) -> act f32.
|
||||
int vetta_situ(const float* gu, float* act, int inter, float beta, float lb,
|
||||
vetta_stream_t stream);
|
||||
|
||||
// k_situ_f16: SiTU computed in f32, stored FP16 (exact strata act_out half).
|
||||
int vetta_situ_f16(const float* gu, uint16_t* act, int inter, float beta, float lb,
|
||||
vetta_stream_t stream);
|
||||
|
||||
// k_moe_reduce: out[d] = sum_e tk_w[e]*y_part[e,d] (weighted expert sum).
|
||||
int vetta_moe_reduce(const float* y_part, const float* tk_w, float* out,
|
||||
int top_k, int hidden, vetta_stream_t stream);
|
||||
|
||||
Reference in new issue
Block a user