Archived
libref, libavx: GLM-5.3's ops -- mHC, clamped SwiGLU, f32 routing, KDA, the DSA indexer, MLA
The reference and CPU forms of the ops GLM-5.3-Flash's graph needs, with their schemas and shape hooks: mhc_pre / mhc_post / mhc_contract and the column-split pair mhc_pre_partial / mhc_pre_finish; swiglu_clamped; gemm_nt_f32 (bf16 activation, f32 weight and result) for the router logits and the indexer's head gates; router_sigmoid_topk (correction-bias top-k); kda_update with per-channel decay and both state forms; dsa_pool, dsa_query and dsa_score; and mla_attn and mla_project for absorbed latent attention. moe_gather takes f32 expert weights beside bf16, and fp8a8f32 joins the dtype list. docs/OPS.md states each op. ref_test checks every op against hand-computed cases, avx_check_hand the CPU forms against libref, build_test the indexer cache's page size. Co-Authored-By: Nunze <lorenz.lamping1@web.de>
This commit is contained in:
1 parent
c8311068d0
commit
da77f86332
21 files changed
+3217
-19
No files matched your search
+2
-2
@@ -1098,7 +1098,7 @@ static int moe_gemm_impl(const RadArgs* a, bool quant, int ncls = 2) {
|
||||
if (jc > 0 || (ts && cb_joined(wse[e]))) return RAD_E_DTYPE;
|
||||
}
|
||||
mw[e] = as_mat(&we[e], k);
|
||||
SW[e] = make_scales(quant && ts ? &wse[e] : nullptr, n, k, false);
|
||||
SW[e] = make_scales(quant && ts ? &wse[e] : nullptr, n, k, we[e].dtype == RAD_FP4E2M1);
|
||||
/* An activation scale grid finer than an expert's cannot be hoisted out of the group. No
|
||||
* supported format has one, but libref answers it by scaling each element, so the panel
|
||||
* below is scaled as it is packed and the dot reads no activation scale (`SAg`). */
|
||||
@@ -1218,7 +1218,7 @@ AVX_KERNEL(moe_gemm_q_mod4) { return moe_gemm_impl(a, true, 4); }
|
||||
/* y[t] = sum over the token's slots of expert_w[t, j] * y_expert[position of (t, j)], summed in
|
||||
* ascending slot j (see the file header). The inverse permutation is built once per batch. */
|
||||
AVX_KERNEL(moe_gather) {
|
||||
if (!rad_args_have(a, 6)) return RAD_E_INVAL;
|
||||
if (!a || !a->t || a->n_t < 6 || !rad_args_have(a, 3) || !rad_arg_in(a, 5)) return RAD_E_INVAL;
|
||||
const RadTensor *ye = &a->t[0], *ew = &a->t[1], *sorted = &a->t[2], *Y = &a->t[5];
|
||||
/* Optional shared-expert fold: y = narrow(shared * act(gate)) + narrow(gathered). Both
|
||||
* operands or neither, as in libref. */
|
||||
|
||||
Reference in new issue
Block a user