Archived
qwen4exp at four ranks: slice the width by parity, do not shard experts
The real-container declare gate refused this container at layers 46-47: 'keeps 1 experts plain bf16 on this rank, which leaves 127 quantised'. Root cause: protected-expert counts are per-rank, and the recipe protects IN PAIRS precisely so that each rank's quantised count stays even. Expert parallelism broke that property the parity tables rest on; fixing it properly would need unequal-length weight tables, which the builder's equal-split rule refuses by design. The width split was always the right answer above two ranks and serves more ranks than the old code realised. Each parity's blocks are cut contiguously across the ranks and the rank taking the odd block alternates with the parity: at four ranks and five blocks, [0,2) [2,3) [3,4) [4,5), with the fat class rotating between the two parities so no rank takes both. Every block of every expert has exactly one owner, protected counts go back to the recipe's global even numbers, and -- because every rank still computes a slice of every routed expert -- the routing-balance cost the EP design carried disappears with it. World 2 is byte-identical: base, extra and the parity rotation reduce to the same expressions at g.world == 2. Worlds up to the block count now declare; beyond it the refusal names the reason.
This commit is contained in:
1 parent
7cf4c005e1
commit
10f3d6875b
3 files changed
+45
-18
No files matched your search
@@ -515,7 +515,7 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
||||
* is two row ranges and a column range of the container, which the file tier cannot read
|
||||
* as one run, and nothing about bf16 needs the parity split's balance -- a bf16 model is
|
||||
* served to calibrate and to compare, not for its decode rate. */
|
||||
if (g.world > 2 || (g.world > 1 && (mc.calib || mc.expert_bf16))) {
|
||||
if (g.world > 1 && (mc.calib || mc.expert_bf16)) {
|
||||
int s;
|
||||
int64_t per = 0;
|
||||
if ((s = divide_or_fail(mc.n_expert_all, g.world, "expert_count", &per)) < 0) return s;
|
||||
@@ -549,11 +549,19 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
||||
const int64_t nb = g.n_ff_all / RAD_FP8_BLOCK;
|
||||
if (nb % g.world == 0) {
|
||||
mc.n_ff_exp = g.n_ff_all / g.world;
|
||||
} else if (g.world == 2) {
|
||||
const int64_t base = nb / 2, extra = nb % 2;
|
||||
} else if (g.world <= nb) {
|
||||
/* The uneven split is TWO SLICES, not two RANKS: each parity's blocks are cut
|
||||
* contiguously across the ranks and the rank taking the odd block alternates with
|
||||
* the parity, so every rank's slices are whole blocks and every block of every
|
||||
* expert has exactly one owner. At two ranks this is the split the tree has always
|
||||
* made, byte for byte; at four it gives widths of ceil(nb/W) and floor(nb/W).
|
||||
* A rank must come away with at least one block of each parity -- an empty slice
|
||||
* is a rank that computes nothing and still joins the all-reduce -- which needs
|
||||
* the ranks to fit inside the two parities' blocks together. */
|
||||
const int64_t base = nb / g.world, extra = nb % g.world;
|
||||
for (int q = 0; q < 2; ++q) {
|
||||
/* This rank's place in expert parity q's split: first for its own parity. */
|
||||
const int64_t p = (g.rank - q + 2) % 2;
|
||||
const int64_t p = (g.rank - q + g.world) % g.world;
|
||||
const int64_t b0 = p * base + std::min<int64_t>(p, extra);
|
||||
const int64_t b1 = b0 + base + (p < extra ? 1 : 0);
|
||||
mc.ff_lo[q] = b0 * RAD_FP8_BLOCK;
|
||||
@@ -562,11 +570,23 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
||||
mc.n_ff_exp = std::max(mc.ff_hi[0] - mc.ff_lo[0], mc.ff_hi[1] - mc.ff_lo[1]);
|
||||
rad_note(b, "routed experts: rank %d computes columns [%lld, %lld) of each even "
|
||||
"expert and [%lld, %lld) of each odd one, of %lld. The width is %lld "
|
||||
"blocks of %d, which two ranks split unevenly, so the rank taking the "
|
||||
"blocks of %d, which %lld ranks split unevenly, so the rank taking the "
|
||||
"extra block alternates with the expert's parity; the block's "
|
||||
"all-reduce sums the partials.",
|
||||
g.rank, (long long)mc.ff_lo[0], (long long)mc.ff_hi[0],
|
||||
(long long)mc.ff_lo[1], (long long)mc.ff_hi[1], (long long)g.n_ff_all,
|
||||
(long long)nb, RAD_FP8_BLOCK, (long long)g.world);
|
||||
} else {
|
||||
fprintf(stderr, "radiance: qwen4exp: an expert is %lld blocks of %d, which %d ranks "
|
||||
"cannot each take a whole block of in both parities. Lower the rank "
|
||||
"count, or serve whole experts (a bf16 container or a calibration "
|
||||
"run does).\n",
|
||||
(long long)nb, RAD_FP8_BLOCK, g.world);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
}
|
||||
g.rank, (long long)mc.ff_lo[0], (long long)mc.ff_hi[0],
|
||||
(long long)mc.ff_lo[1], (long long)mc.ff_hi[1], (long long)g.n_ff_all,
|
||||
(long long)nb, RAD_FP8_BLOCK);
|
||||
} else {
|
||||
fprintf(stderr, "radiance: qwen4exp: an expert is %lld blocks of %d, which %d ranks "
|
||||
|
||||
Reference in new issue
Block a user