qwen4exp: the plugin owns the expert width split; geom_from does not refuse it first

geom_from divides n_ff by the world before the plugin's own split runs,
and 640 does not divide by 3. The plugin cuts the routed experts' width by
whole fp8 blocks and parity at any world up to the block count (1.0.8),
so the refusal is answered before it is asked. geom_from gains
arch_splits_ff (default off): with it, a width the world does not divide
is left whole in g.n_ff for the plugin to slice; a width that divides is
unaffected, and every other plugin keeps the refusal because for them
g.n_ff is the per-rank width. qwen4exp opts in.
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-05 19:31:12 +02:00
1 parent 2149a1a757
commit 6b394ccca6
2 files changed
+15 -3

No files matched your search

+11 -2
View File
@@ -717,8 +717,13 @@ inline long long meta_int2(const RadModelMeta* m, const char* gguf_key, const ch
return v == sentinel ? dflt : v;
}
/* `arch_splits_ff`: the plugin divides the feed-forward width across the ranks ITSELF (qwen4exp:
* the routed experts' width is cut by whole fp8 blocks, by parity, at any world up to the block
* count). With it set, a width the world does not divide is left whole in g.n_ff and the plugin
* takes its slice from there; without it the refusal stands, because for every other plugin g.n_ff
* IS the per-rank width. A width that does divide is unaffected either way. */
inline int geom_from(Geom& g, const RadModelMeta* m, const RadBuildCtx* c,
const char* dtype, uint32_t act_dtype) {
const char* dtype, uint32_t act_dtype, bool arch_splits_ff = false) {
if (!m || !c) return RAD_E_INVAL;
if (c->is_draft) {
/* A drafter declared into this plugin would need a second set of per-rank handles and a
@@ -814,7 +819,11 @@ inline int geom_from(Geom& g, const RadModelMeta* m, const RadBuildCtx* c,
} else {
g.kv_off = 0; /* a split rank reads the rows the plain row-shard already gives it */
}
if ((s = divide_or_fail(g.n_ff_all, g.world, "n_ff", &g.n_ff)) < 0) return s;
if (arch_splits_ff && g.world > 1 && g.n_ff_all % g.world != 0) {
g.n_ff = g.n_ff_all; /* the plugin slices it (see the parameter's comment) */
} else if ((s = divide_or_fail(g.n_ff_all, g.world, "n_ff", &g.n_ff)) < 0) {
return s;
}
/* THE VOCABULARY IS SPLIT. r4d_sample_topk_f32 takes a vocabulary offset and packs its
* candidates as (u32 GLOBAL id, f32 logit) pairs, and the all-gather places every rank's
* pairs for one sampled position side by side, which is the layout sample_merge_topk reads.
+4 -1
View File
@@ -318,7 +318,10 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
m.nm = Names(ctx->scope ? ctx->scope : "");
Names& nm = m.nm;
RAD_ARCH_TRY(geom_from(m.g, meta, ctx, "bf16", RAD_BF16));
/* arch_splits_ff: the routed experts' width (640 = five fp8 blocks) is split by the plugin
* below, by whole blocks and parity, at any world up to the block count -- three ranks included,
* which 640 does not divide. geom_from must not refuse what the plugin then answers. */
RAD_ARCH_TRY(geom_from(m.g, meta, ctx, "bf16", RAD_BF16, /*arch_splits_ff=*/true));
Geom& g = m.g;
/* Qwen4-Exp's norms are all `x_hat * (1 + w)` -- `Qwen3NextRMSNorm.forward` is