From e0c3f971dc7243531912b4835569f67ae8fc5598 Mon Sep 17 00:00:00 2001 From: keptn42 Date: Sat, 31 Oct 2026 10:46:28 +0000 Subject: [PATCH] arch/common: DFlash2's split fc gathers its message as a range The context pass's all_gather declared numel as a fixed crows * n_embd. crows is max_tok, so every sizing declare (RadBuildCtx::shape_probe) changed a fixed parameter and was refused: with a block-fp8 fc at TP > 1 no arena level was planned and nothing was lent to the expert slab. numel is now a range with the trunk all-reduce's bound, issued at T * n_embd, as the reference reads it (band_rows). arch_test: the fc split's gather is the trunk's bound, as a range. --- arch/common/rad_block_dflash2.h | 10 +++++++--- tests/arch_test.cpp | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/common/rad_block_dflash2.h b/arch/common/rad_block_dflash2.h index b9b9cf9c..bb9f3b1f 100644 --- a/arch/common/rad_block_dflash2.h +++ b/arch/common/rad_block_dflash2.h @@ -555,12 +555,15 @@ inline int Dflash2::declare(RadBuilder* b, Names& nm, const Geom& geom, const Co if (fc_rows) { /* The split (SHARDING above): this rank's block-aligned rows into `cpart`, its window of * them gathered into `c`. The GEMM takes its K split from the whole width. The gather - * rides the trunk's all-reduce instance (the same numel bound, so the same instance). */ + * rides the trunk's all-reduce instance (the same numel bound, so the same instance). + * The message is a range, as the all-reduce's: a fixed numel follows max_tok, and the + * arena's sizing declare (RadBuildCtx::shape_probe) refuses a fixed parameter that + * changes with the step size. */ op_cfc = w_fc.gemm(b, crows, fc_rows, cfg.n_taps * g.n_embd, {w.srcq, w.srcs}, {w.cpart}, g.n_embd); op_cgath = rw(b, RAD_OP(b, "all_gather", RAD_PARAMS(RAD_INT("world_size", g.world), - RAD_INT("numel", crows * g.n_embd), + RAD_RANGE("numel", g.n_embd, crows * g.n_embd), RAD_STR("dtype", g.dtype), RAD_INT("row", fc_share)), RAD_NOWEIGHTS), {w.cpart}, {w.c}); @@ -1090,7 +1093,8 @@ inline void Dflash2::context(RadCtx* c, const RadBatch* batch) const { if (fc_rows) { RAD_ISSUE_N(c, op_cfc, T, brows(w.srcq, T), brows(w.srcs, T), RAD_W(w_fc.w), RAD_W(w_fc.s), brows(w.cpart, T), RAD_NONE, w_fc.bref()); - RAD_ISSUE_N(c, op_cgath, T, bcol(w.cpart, fc_off, fc_share, T), brows(w.c, T)); + RAD_ISSUE_N(c, op_cgath, T * g.n_embd, bcol(w.cpart, fc_off, fc_share, T), + brows(w.c, T)); } else { RAD_ISSUE_N(c, op_cfc, T, brows(w.srcq, T), brows(w.srcs, T), RAD_W(w_fc.w), RAD_W(w_fc.s), brows(w.c, T), RAD_NONE, w_fc.bref()); diff --git a/tests/arch_test.cpp b/tests/arch_test.cpp index c6a8bb09..86f54837 100644 --- a/tests/arch_test.cpp +++ b/tests/arch_test.cpp @@ -8012,7 +8012,11 @@ TEST(gemma4_31b_dflash2_fc_splits_by_rows_without_changing_a_bit) { } if (o.op == "all_gather" && pint(&o, "row") == cs.share) { ++fc_gathers; - CHECK_EQ(pint(&o, "numel"), (long long)(2048 * E)); /* the trunk's instance */ + /* The trunk's instance, and a range: a sizing declare may not change it. */ + const RecParam* ne = param(&o, "numel"); + REQUIRE(ne != nullptr); + CHECK_EQ(ne->kind, (int)RAD_P_RANGE); + CHECK_EQ(ne->ihi, (long long)(2048 * E)); CHECK_EQ(pint(&o, "world_size"), (long long)cs.world); } }