Archived
arch: the experts stay on the rotation; only the delta net goes remainder-first
An expert block is a whole GEMM of every routed token; a rank taking the extra block of every class became the step's slowest rank. Measured on Flash-Next at three ranks, interleaved image A/B, two reps each: experts 50/25/25 cost 25% a step single-stream; one class's extra block (37/25/37) swung 16.5-19.1 ms between boots; the delta-net head alone on the attention-zero rank gave 15.6 ms both reps against 16.7-17.2, c1 +10-16%, c4 +4%, c8 +2-3%, acceptance unchanged at 2.54 tokens a step. The experts cut as every world always has; TP2 and TP4 are untouched.
This commit is contained in:
1 parent
2d93182213
commit
92b8aaff2b
2 files changed
+21
-15
No files matched your search
@@ -733,11 +733,12 @@ inline long long meta_int2(const RadModelMeta* m, const char* gguf_key, const ch
|
|||||||
* count). With it set, a width the world does not divide is left whole in g.n_ff and the plugin
|
* 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
|
* 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. */
|
* IS the per-rank width. A width that does divide is unaffected either way. */
|
||||||
/* THE REMAINDER-FIRST ORDER OF THE RANKS. Whatever does not divide evenly over the world -- the
|
/* THE REMAINDER-FIRST ORDER OF THE RANKS. What does not divide evenly over the world and is a
|
||||||
* extra block of an expert's width, the extra delta-net head -- goes to the ranks with NO
|
* HEAD'S worth of work -- the extra delta-net head -- goes to the ranks with NO attention first:
|
||||||
* attention first: they pay nothing for attention (rad_block_attn_gated_fp8.h: one fill) and keep
|
* they pay nothing for attention (rad_block_attn_gated_fp8.h: one fill) and keep no attention
|
||||||
* no attention cache (rad_kv_group_zero), so they have the time and the memory for it, and every
|
* cache (rad_kv_group_zero), so they have the time for it, and the rank that held the extra head
|
||||||
* rank with heads is lighter for it. This is a rank's PLACE in that order: the attention-zero ranks
|
* AND attention -- the step's slowest -- is lighter for it. An expert's extra block is not a
|
||||||
|
* head's worth (qwen4exp_fp8.cpp says why it stays on the rotation). This is a rank's PLACE in that order: the attention-zero ranks
|
||||||
* take places 0..n-1 whatever `parity` is, and the attention ranks follow in today's rotation by
|
* take places 0..n-1 whatever `parity` is, and the attention ranks follow in today's rotation by
|
||||||
* `parity` -- so where no rank is attention-zero (every world the heads divide) the place is
|
* `parity` -- so where no rank is attention-zero (every world the heads divide) the place is
|
||||||
* exactly (rank - parity) mod world and every cut is what it always was, byte for byte. */
|
* exactly (rank - parity) mod world and every cut is what it always was, byte for byte. */
|
||||||
@@ -823,8 +824,8 @@ inline int geom_from(Geom& g, const RadModelMeta* m, const RadBuildCtx* c,
|
|||||||
g.attn_zero = g.rank >= g.attn_world;
|
g.attn_zero = g.rank >= g.attn_world;
|
||||||
g.attn_rank = g.attn_zero ? g.attn_world - 1 : g.rank;
|
g.attn_rank = g.attn_zero ? g.attn_world - 1 : g.rank;
|
||||||
fprintf(stderr, "radiance: world_size = %d over n_head_kv = %lld: attention on %d rank(s), "
|
fprintf(stderr, "radiance: world_size = %d over n_head_kv = %lld: attention on %d rank(s), "
|
||||||
"rank(s) %d..%d carry no attention and take the delta net's and the "
|
"rank(s) %d..%d carry no attention and take the delta net's remainder "
|
||||||
"experts' remainders first\n", g.world, (long long)g.n_head_kv_all,
|
"first\n", g.world, (long long)g.n_head_kv_all,
|
||||||
g.attn_world, g.attn_world, g.world - 1);
|
g.attn_world, g.attn_world, g.world - 1);
|
||||||
}
|
}
|
||||||
const int aw = g.attn_world, ar = g.attn_rank;
|
const int aw = g.attn_world, ar = g.attn_rank;
|
||||||
|
|||||||
@@ -605,9 +605,15 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
|||||||
* the ranks to fit inside the two parities' blocks together. */
|
* the ranks to fit inside the two parities' blocks together. */
|
||||||
const int64_t base = nb / g.world, extra = nb % g.world;
|
const int64_t base = nb / g.world, extra = nb % g.world;
|
||||||
for (int q = 0; q < 2; ++q) {
|
for (int q = 0; q < 2; ++q) {
|
||||||
/* This rank's place in expert parity q's split: the ranks without attention
|
/* This rank's place in expert parity q's split: first for its own parity.
|
||||||
* first, then first for its own parity (rad_arch.h remainder_place). */
|
* THE EXPERTS DO NOT GO REMAINDER-FIRST (rad_arch.h remainder_place): an
|
||||||
const int64_t p = remainder_place(g, g.rank, q);
|
* expert block is a whole GEMM of every routed token, and a rank taking the
|
||||||
|
* extra block of every class became the step's slowest rank -- measured at
|
||||||
|
* three ranks, Flash-Next: 50/25/25 cost 25% a step single-stream, and even
|
||||||
|
* one class's extra block (37/25/37) swung 16-19 ms between boots. The delta
|
||||||
|
* net's remainder is a head's worth of work and goes to the rank without
|
||||||
|
* attention; the experts stay on the rotation every world has always had. */
|
||||||
|
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 b0 = p * base + std::min<int64_t>(p, extra);
|
||||||
const int64_t b1 = b0 + base + (p < extra ? 1 : 0);
|
const int64_t b1 = b0 + base + (p < extra ? 1 : 0);
|
||||||
mc.ff_lo[q] = b0 * RAD_FP8_BLOCK;
|
mc.ff_lo[q] = b0 * RAD_FP8_BLOCK;
|
||||||
@@ -621,7 +627,7 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
|||||||
* rank already takes of some parity. */
|
* rank already takes of some parity. */
|
||||||
if (g.world == 4) {
|
if (g.world == 4) {
|
||||||
for (int q = 0; q < 4; ++q) {
|
for (int q = 0; q < 4; ++q) {
|
||||||
const int64_t p = remainder_place(g, g.rank, q);
|
const int64_t p = (g.rank - q + 4) % 4;
|
||||||
const int64_t b0 = p * base + std::min<int64_t>(p, extra);
|
const int64_t b0 = p * base + std::min<int64_t>(p, extra);
|
||||||
const int64_t b1 = b0 + base + (p < extra ? 1 : 0);
|
const int64_t b1 = b0 + base + (p < extra ? 1 : 0);
|
||||||
mc.ff_lo4[q] = b0 * RAD_FP8_BLOCK;
|
mc.ff_lo4[q] = b0 * RAD_FP8_BLOCK;
|
||||||
@@ -639,10 +645,9 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c
|
|||||||
} else {
|
} else {
|
||||||
rad_note(b, "routed experts: rank %d computes columns [%lld, %lld) of each "
|
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 "
|
"even expert and [%lld, %lld) of each odd one, of %lld. The width "
|
||||||
"is %lld blocks of %d, which %lld ranks split unevenly: the extra block "
|
"is %lld blocks of %d, which %lld ranks split unevenly, so the rank "
|
||||||
"goes to a rank without attention where there is one, else to the "
|
"taking the extra block alternates with the expert's parity; the "
|
||||||
"rank the expert's parity picks; the block's all-reduce sums the "
|
"block's all-reduce sums the partials.",
|
||||||
"partials.",
|
|
||||||
g.rank, (long long)mc.ff_lo[0], (long long)mc.ff_hi[0],
|
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)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.n_ff_all, (long long)nb, RAD_FP8_BLOCK,
|
||||||
|
|||||||
Reference in new issue
Block a user