glm5next: the MLA row form, opt-in with RADIANCE_GLM_MLA_ROWS=1 -- a prefill-sized step by rows over the ranks, each rank with all 64 heads

From GlmTp::kSplitRows each rank runs its run of the step's rows (GlmTp::run_of: ceil(T / world)
rows, the last run shorter) through q_b, absorption, attention with all 64 heads
(mla_attn_rows_bf16), expansion and o, and an all_gather of whole runs takes the all-reduce's
place. The latent cache and the DSA selection are whole on every rank, so nothing is exchanged
before the attention; each rank sends its run to seven peers, half the bytes of the two-shot
all-reduce, through the same exchange instance. In a 4096-row chunk at 16k of context a rank's
attention drops from 14.0 to 3.9 ms a layer on the kernel bench. The price is q_b, kv_b and o at
full width on every rank: 120 MiB a layer, 1.29 GiB a card over the 11 trunk layers, and about
0.1 GiB of activations; the MTP layer keeps its heads. The full-width weights are whole views
(RadWeightDecl::source) of blk.N.attn_q_b, attn_kv_b and attn_output, the head form's container
entries, so they take the stored encoding (fp8a8f32, bf16) and need no name map; LinearFP8 gets
`stored` for that, served by its block-fp8 branch only, and LinearFP8::step writes a run of rows
from a given output row.

The head form stays the default, unset or RADIANCE_GLM_MLA_ROWS=0, and declares none of it: that
graph is the one before this change, byte for byte (the pinned hashes). The row form is not
bit-identical to the head form, and GLM-5.3 turns that into a measurable divergence: over a
43k-position KL corpus at TP8 (English prose, German prose, code) the row form scores a mean KL
of 0.033 against the head form (median 0.004, top-1 agreement 93.5 %), with greedy text
unchanged. The projections are not the cause: q_b and o over a rank's rows give the head form's
bytes (r4d_emu), and o summed as eight rank partials in the all-reduce's order
(RADIANCE_GLM_MLA_ROWS=2, a test form, GlmMla::Form::rows_sliced_o) scores 0.032. The
attention's rounding is: the rows kernel parts from the paired union tile in about 0.1 % of
every row's outputs by one bf16 step (the union pairing sums a pair's second row in another
order), and the 16-head tile, which parts in the same share of every second row only, halves the
KL to 0.015. A bit-identical row form would run the union tile eight times a row over its own
group of eight heads, without this kernel's gain, or need a rows kernel with the union's
arithmetic; neither is here, so the form is opt-in.

Measured on eight R9700 at Gen5 links, the same build: a 20k-token prefill 5074 tok/s in the row
form against 4270 in the head form, BetterBench prefill at 22k 4984 against 4151, single stream
181.8 against 180.2 tok/s, eight streams 468 against 454.

glm5next_test declares the block at one to eight ranks and checks the full-width views and their
sources, the fp8a8f32 GEMMs, the gather's bound against the all-reduce's, each rank's operands
at 300 rows (runs of 38, the last 34 at eight ranks) and the head form at 255; the o-slices
form's eight GEMMs and seven adds; the model's counts and the TP8 pin under
RADIANCE_GLM_MLA_ROWS=1 (0x1d378152c40f8834 / 0x82ed1094dbf4b637), with the default pins
unchanged; and the row rule against both formulas it replaced. plugin_test resolves every band
of every op the row form adds at eight ranks against libr4d, with no card.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
NunzeandClaude Opus 5.5 committed 2026-10-22 09:58:07 +00:00
1 parent 7d7c66da55
commit eb14e4f642
9 files changed
+717 -76

No files matched your search

+60
View File
@@ -1018,6 +1018,66 @@ TEST(libr4d_resolves_the_mla_attention_by_rows) {
CHECK_EQ(band_names(r.build_bands("mla_attn", "M", 1, 512, g)), "512:mla_attn_matrix_bf16 ");
}
/* GLM-5.3-Flash's MLA split by rows at eight ranks (arch/common/rad_block_glm_mla.h), with the
* parameters its ops declare against the container's encodings (block fp8 at f32 scales): every
* band of every op the row form adds resolves on the device, up to a 4096-token step's run of
* 512 rows. A form libr4d does not serve would stop a TP8 start at "resolved to no kernel". */
TEST(libr4d_resolves_every_band_of_glm_mla_split_by_rows) {
const std::string so = libr4d();
if (so.empty()) return;
Registry r;
CHECK(r.load_plugin(so, 0) >= 0);
r.set_device_fact(RAD_FACT_P2P, 1);
auto all_resolve = [&](const char* op, const char* ranged, int64_t lo, int64_t hi,
const Geometry& g) {
const std::vector<Band> bands = r.build_bands(op, ranged, lo, hi, g);
bool ok = !bands.empty();
for (const Band& x : bands) ok = ok && x.dom[RAD_DOMAIN_DEVICE].row;
if (!ok) std::fprintf(stderr, " %s: %s\n", op, band_names(bands).c_str());
return ok;
};
const int64_t R = 512;
for (const auto& [n, k] : { std::pair<int64_t, int64_t>{ 16384, 1536 }, { 4096, 16384 } }) {
Geometry g;
g.set_i("N", n);
g.set_i("K", k);
g.set_i("group", 128);
g.set_s("dtype", "fp8a8f32");
CHECK(all_resolve("gemm_nt_q", "M", 1, R, g));
}
for (const char* mode : { "absorb", "expand" }) {
Geometry g;
g.set_i("heads", 64);
g.set_i("head_dim", 256);
g.set_i("latent_dim", 512);
g.set_s("mode", mode);
g.set_s("dtype", "bf16");
CHECK(all_resolve("mla_project", "M", 1, R, g));
}
{
Geometry g;
g.set_i("latent_dim", 512);
g.set_i("heads", 64);
g.set_i("blocks", 513);
g.set_i("block_size", 4);
g.set_s("dtype", "bf16");
CHECK(all_resolve("mla_attn", "M", 1, R, g));
}
{
Geometry g;
g.set_i("n", 16384);
g.set_i("group", 128);
g.set_s("dtype", "bf16");
CHECK(all_resolve("quant_act_fp8", "M", 1, 4096, g));
}
{
Geometry g;
g.set_i("world_size", 8);
g.set_s("dtype", "bf16");
CHECK(all_resolve("all_gather", "numel", 4096, 4096 * 4096, g));
}
}
/* ================================================================== constraints that are not intervals */
namespace {
std::string extra_dir() { return home() + "/testkernels/extra"; }