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:
John McDonoughandNunze authored and StillDeadcode committed 2026-10-19 20:13:47 +02:00
1 parent c8311068d0
commit da77f86332
21 files changed
+3217 -19

No files matched your search

+28
View File
@@ -751,6 +751,34 @@ TEST(kv_block_size_comes_off_the_kernel) {
CHECK_EQ((int)gi.layers.size(), 2);
}
TEST(glm_index_cache_pages_are_sized_by_the_real_pool_consumer) {
Registry reg;
REQUIRE_EQ(reg.load_dir(home() + "/kernels", { "libref" }), RAD_OK);
Builder b(reg, make_meta(), make_ctx());
RadKVGroupDecl kd{};
kd.kind = RAD_KV_FULL;
kd.dtype = RAD_U8;
kd.n_head_kv = 1;
kd.head_dim = 17;
const auto group = b.decl_kv_group("glm_index", &kd);
RadWeightDecl wd{};
wd.dtype = RAD_F32;
wd.rank = 2;
wd.shape[0] = 4;
wd.shape[1] = 128;
wd.access = RAD_ACCESS_PER_TOKEN;
wd.shard = RAD_SHARD_NONE;
const auto ape = b.decl_weight("pool_ape", &wd);
const RadParam params[] = { RAD_RANGE("M", 1, 12), RAD_INT("n", 128), RAD_INT("ratio", 4),
RAD_STR("dtype", "bf16"), RAD_INT("block_size", 4) };
REQUIRE(b.decl_op("dsa_pool", params, 5, &ape, 1));
CHECK_EQ(b.kv_block_size(group), 4);
CHECK_OK(b.bind_layer_kv(0, group));
CHECK_OK(b.bind_layer_kv(1, group));
REQUIRE_EQ(b.finish(), RAD_OK);
CHECK_EQ(b.program().kv_groups[group].bytes_per_block, (int64_t)(2 * 136));
}
TEST(a_kv_group_with_no_layers_is_an_error) {
NEED_PLUGIN(reg)
Builder b(reg, make_meta(), make_ctx());