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
+49
-2
@@ -1653,8 +1653,55 @@ int ref_moe_scatter_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* o
|
||||
return o.finish("moe_scatter", operand, out);
|
||||
}
|
||||
|
||||
/* `a_order` decides the activation's row count: one per token, or one per (token, slot) in
|
||||
* scatter order. */
|
||||
/* The two shape lists concatenated, with `expert_ids` named ONCE as an output -- it is what the
|
||||
* selection writes and what the sort reads. The sort's three outputs are sized by THIS RANK'S
|
||||
* SLICE (`n_local`, absent means the slice is the router), exactly as in libr4d's shape. */
|
||||
int ref_router_topk_scatter_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0);
|
||||
const int64_t ne = gi(p, n_p, "n_expert", 0);
|
||||
const int64_t k = gi(p, n_p, "top_k", 0);
|
||||
const int64_t nl = gi(p, n_p, "n_local", ne);
|
||||
if (M <= 0 || ne <= 0 || k <= 0 || k > ne || nl <= 0 || nl > ne) return RAD_E_UNSUPPORTED;
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
Opd o;
|
||||
o.t(D, { M, ne }); /* logits */
|
||||
o.t((uint32_t)RAD_I32, { M, k }); /* expert_ids */
|
||||
o.t(D, { M, k }); /* expert_w */
|
||||
o.t((uint32_t)RAD_I32, { M * k }); /* sorted_tok */
|
||||
o.t((uint32_t)RAD_I32, { nl + 1 }); /* expert_offset */
|
||||
o.t((uint32_t)RAD_I32, { nl }); /* expert_count */
|
||||
return o.finish("router_topk_scatter", operand, out);
|
||||
}
|
||||
|
||||
/* The router GEMM's list, the pair's list, and -- with the gate present -- the gate's one-column
|
||||
* list, with `logits` named once as the GEMM's output. `gate_b`/`gate` come together or not: the
|
||||
* operand count carries it, as in libr4d's shape. */
|
||||
int ref_router_gemm_topk_scatter_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0);
|
||||
const int64_t K = gi(p, n_p, "K", 0);
|
||||
const int64_t ne = gi(p, n_p, "n_expert", 0);
|
||||
const int64_t k = gi(p, n_p, "top_k", 0);
|
||||
const int64_t nl = gi(p, n_p, "n_local", ne);
|
||||
if (M <= 0 || K <= 0 || ne <= 0 || k <= 0 || k > ne || nl <= 0 || nl > ne)
|
||||
return RAD_E_UNSUPPORTED;
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
Opd o;
|
||||
o.t(D, { M, K }); /* a */
|
||||
o.t(D, { ne, K }); /* b: the router */
|
||||
o.t(D, { 1, K }); /* gate_b: the shared expert's gate */
|
||||
o.t(D, { M, ne }); /* logits */
|
||||
o.t((uint32_t)RAD_I32, { M, k }); /* expert_ids */
|
||||
o.t(D, { M, k }); /* expert_w */
|
||||
o.t((uint32_t)RAD_I32, { M * k }); /* sorted_tok */
|
||||
o.t((uint32_t)RAD_I32, { nl + 1 }); /* expert_offset */
|
||||
o.t((uint32_t)RAD_I32, { nl }); /* expert_count */
|
||||
o.t(D, { M, 1 }); /* gate */
|
||||
return o.finish("router_gemm_topk_scatter", operand, out);
|
||||
}
|
||||
|
||||
/* `a_order` decides the activation's row count: one per token, or one per (token, slot) already
|
||||
* in the scatter's order. A described case that got this wrong would build the operand at the
|
||||
* extent the WRONG reading wants, and the fault it names would go unseen. */
|
||||
static inline bool sorted_a_order(const RadParam* p, int n_p) {
|
||||
const char* s = gs(p, n_p, "a_order");
|
||||
return s && std::strcmp(s, "sorted") == 0;
|
||||
|
||||
Reference in new issue
Block a user