Archived
unlimitedocr: the decoder plugin, the fused router ops and an h128 MHA attention leg
The text side of Unlimited-OCR: a 12-layer, 1280-wide decoder, 10 query heads over 10 KV heads at head_dim 128, a dense layer 0 and 64 routed experts (top-6, softmax, no renormalisation) plus one ungated shared arm in layers 1-11. arch/unlimitedocr_bf16/ carries its own plain-Llama bf16 attention, the shared MoE block in its bf16 external-input mode, and the tied LM head; data/recipes/unlimited-ocr-bf16.recipe is the bf16 passthrough convert. core/format/checkpoint.cpp learns n_routed_experts, so n_expert is read from the checkpoint's own key. The router is issued as one op rather than a selection and a sort: libref gains router_topk_scatter and router_gemm_topk_scatter (the second with the shared expert's one-column gate at N = 1), libavx composes both from its router/gemm/scatter kernels, and both get sweep geometries and the gate-absent/gate-present tests. libr4d had no head_dim 128 leg at ratio 1, so every attn_paged band of this geometry resolved to no kernel and the server refused to start on device. r4d_attn_paged_h128_gqa1.hip instantiates the generic body at GQ 1 for both legs; the rows and the selftest cases come with it. Device numbers, one R9700 (gfx1201, HIP 7.16), bf16 weights and KV, no reference-kernel fallback: a 523-token prompt prefills at 35.0-35.8k tok/s (15 ms) and a 4043-token prompt at 54.2k tok/s (75 ms); decode is 351-354 tok/s (2.82-2.85 ms/token) at short context and 315 tok/s at 4k. r4d_selftest is 0 failures; the host suite is 86/87, the miss being mm_test's lossless-webp decode, which fails on this box in code this change does not touch.
This commit is contained in:
1 parent
685ec5bd85
commit
543cba7416
20 files changed
+1179
-5
No files matched your search
@@ -387,6 +387,26 @@ static const RadParamSpec pScatter[] = { P_INT("M"), P_INT("n_expert"), P_INT(
|
||||
static const RadOperandSpec oScatter[] = { OPD("expert_ids"), OUT("sorted_tok"),
|
||||
OUT("expert_offset"), OUT("expert_count") };
|
||||
|
||||
/* THE PAIR AS ONE OP, and the router GEMM in front of it: libref's schemas for the same two rows,
|
||||
* where the operand lists are unions and `expert_ids`/`logits` are named once as outputs. */
|
||||
static const RadParamSpec pRouterTopkScatter[] = { P_INT("M"), P_INT("n_expert"),
|
||||
P_INTO("n_local"), P_INT("top_k"),
|
||||
P_INT("norm"), P_STR("dtype"),
|
||||
P_INTO("expert_base"),
|
||||
P_STRO("protect") };
|
||||
static const RadOperandSpec oRouterTopkScatter[] = { OPD("logits"), OUT("expert_ids"),
|
||||
OUT("expert_w"), OUT("sorted_tok"),
|
||||
OUT("expert_offset"),
|
||||
OUT("expert_count") };
|
||||
static const RadParamSpec pRouterGemmTopkScatter[] = { P_INT("M"), P_INT("K"),
|
||||
P_INT("n_expert"), P_INTO("n_local"),
|
||||
P_INT("top_k"), P_INT("norm"),
|
||||
P_STR("dtype"), P_INTO("expert_base"),
|
||||
P_STRO("protect") };
|
||||
static const RadOperandSpec oRouterGemmTopkScatter[] = {
|
||||
OPD("a"), WGT("b"), WGT_O("gate_b"), OUT("logits"), OUT("expert_ids"), OUT("expert_w"),
|
||||
OUT("sorted_tok"), OUT("expert_offset"), OUT("expert_count"), OUT_O("gate") };
|
||||
|
||||
static const RadParamSpec pMoeGemm[] = { P_INT("M"), P_INT("N"), P_INT("K"), P_INT("n_expert"),
|
||||
P_INT("top_k"), P_STR("a_order"), P_STR("dtype") };
|
||||
static const RadOperandSpec oMoeGemm[] = { OPD("a"), WTAB("w"), OPD("sorted_tok"),
|
||||
@@ -979,6 +999,10 @@ static const RadOpSchema kSchemas[] = {
|
||||
{ "router_sigmoid_topk", ARR(pRouterSigmoid), ARR(oRouterSigmoid),
|
||||
"Single-group sigmoid routing; correction bias selects experts, original scores weight them." },
|
||||
{ "router_topk", ARR(pRouter), ARR(oRouter), "softmax then exact top-k routing." },
|
||||
{ "router_topk_scatter", ARR(pRouterTopkScatter), ARR(oRouterTopkScatter),
|
||||
"the selection and the sort in one op, run as exactly the pair." },
|
||||
{ "router_gemm_topk_scatter", ARR(pRouterGemmTopkScatter), ARR(oRouterGemmTopkScatter),
|
||||
"the router GEMM, the shared expert's gate GEMM and the pair, run as exactly the launches." },
|
||||
{ "moe_scatter", ARR(pScatter), ARR(oScatter),
|
||||
"stable counting sort of routing slots by expert." },
|
||||
{ "moe_gemm", ARR(pMoeGemm), ARR(oMoeGemm), "grouped GEMM over the expert-sorted rows." },
|
||||
@@ -1514,6 +1538,12 @@ SIMPLE("avx_router_topk", "router_topk", "moe", "softmax then exact top-k routin
|
||||
L(router_topk)),
|
||||
SIMPLE("avx_router_sigmoid_topk", "router_sigmoid_topk", "moe", "sigmoid correction-bias routing", DT_FLOAT,
|
||||
L(router_sigmoid_topk)),
|
||||
SIMPLE("avx_router_topk_scatter", "router_topk_scatter", "moe",
|
||||
"the selection and the sort in one op, run as exactly the pair", DT_FLOAT,
|
||||
L(router_topk_scatter)),
|
||||
SIMPLE("avx_router_gemm_topk_scatter", "router_gemm_topk_scatter", "moe",
|
||||
"the router GEMM, the shared expert's gate GEMM and the pair, run as exactly the launches",
|
||||
DT_FLOAT, L(router_gemm_topk_scatter)),
|
||||
SIMPLE("avx_moe_scatter", "moe_scatter", "moe", "stable counting sort of routing slots by expert",
|
||||
"i32 indices", L(moe_scatter)),
|
||||
SIMPLE("avx_moe_gemm", "moe_gemm", "moe", "grouped GEMM over the expert-sorted rows", DT_FLOAT,
|
||||
|
||||
Reference in new issue
Block a user