any world size: the attention world, uneven delta-net heads, nothing padded

A world the KV head count neither divides nor is a multiple of -- three
ranks over Flash-Next's two -- was refused by geom_from, and 1.0.12
served it by padding the checkpoint offline (docs/TP3.md): zero heads
appended so that 36 / 3 / 18 / 54 divide, a second 115 GiB container
per model, 1/3 of the attention and 2 of 18 delta-net heads computing
zeros. This serves the shipped container at any world size instead.

The attention world. geom_from serves attention on the largest multiple
of the KV head count under the world (split, or replicated as 1.0.7
does when that is still above the count) and the ranks past it are
attention-zero: they declare the same heads and the same program as
their peers -- the scheduler sees one program -- and read nothing for
attn_qg, attn_k, attn_v and attn_output (rad_weight_shard_zero). Their
attention computes zeros from zeros and their output projection adds
exactly nothing to the reduce. Three ranks over two heads: attention on
ranks 0 and 1 exactly as the two-rank serve declares it, 12 heads, one
KV head, gqa 12, the same kernels; rank 2 zero. Five over two:
attention on four, rank 4 zero. Under a smaller attention world the even
shard over `world` is the wrong cut for every projection, so
rad_block_attn_gated_fp8.h declares spans -- q|gate rows and output
columns [attn_rank * n_head, +n_head) heads, k/v at kv_off -- the same
call the KV replication already used. When the attention world is the
world, every TP2 and TP4 deployment, nothing here is declared and the
block declares as it always did.

Uneven delta-net heads. The delta net has no KV-head constraint: its
kernels are bound on head widths and take any head count. 16 K heads
over three ranks are 6, 5 and 5, each rank's V heads the same multiple
(48 / 16 = 3: 18, 15, 15), every rank real heads. qwen4exp computes the
split and rad_block_gdn_fp8.h declares it as spans of the container's
rows: per-part for [q|k|v|z] and the conv channels (the parts are not
equal), one span for [a|b], A_log, dt_bias and the output columns.
LinearFP8 owns the scale plane's units (1/128 of the weight's rows for
block-fp8, the weight's own for int8 and bf16), so a block declares in
the weight's rows and the scale plane follows. The even split, when the
counts divide, is untouched.

The log says what the geometry did:
  world_size = 3 over n_head_kv = 2: attention on 2 rank(s), rank(s)
  2..2 carry zero attention weights and the delta net and experts of a
  full rank
  qwen4exp: rank 1 takes delta-net K heads [6, 11) of 16 and V heads
  [18, 33) of 48
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-06 11:23:06 +02:00
1 parent 82445ca71f
commit 45963012ee
5 files changed
+155 -15

No files matched your search

+35
View File
@@ -664,6 +664,11 @@ struct LinearFP8 {
rad_weight w = 0, ws = 0;
rad_op op = 0;
int64_t N = 0, K = 0;
/* ROWS OF THE SCALE PLANE PER ROW OF THE WEIGHT: 1 for an int8 or bf16 linear, whose scale
* plane (if any) has the weight's rows, RAD_FP8_BLOCK for a block-fp8 one, whose scale plane
* is 1/128 of them. A row span on `ws` is in the plane's own rows (declare's span code
* divides); span_parts below divides the same way. */
int64_t ws_row_div = 1;
/* A PLAIN bf16 WEIGHT read by `gemm_nt` over the activation's bf16 plane, in a model whose
* linears are bf16 (Geom::w_bf16): one weight and no scale plane, and no quantiser in front. */
bool bf16 = false;
@@ -722,6 +727,35 @@ struct LinearFP8 {
int64_t span_lo = 0, int64_t span_hi = 0);
void step(RadCtx* c, const ActFP8& a, rad_buf y, int64_t T, int64_t r0 = 0,
int64_t rows = 0) const;
/* THIS RANK READS NOTHING FOR IT: the weight and its scale plane are zeros
* (rad_weight_shard_zero). After declare(); for an attention-zero rank (rad_arch.h). */
int zero_share(RadBuilder* b) const {
RAD_ARCH_TRY(rad_weight_shard_zero(b, w));
if (ws) RAD_ARCH_TRY(rad_weight_shard_zero(b, ws));
return RAD_OK;
}
/* A SPAN PER STACKED ROW PART (rad_weight_shard_span_parts), in the weight's rows; the scale
* plane takes the same spans in its own rows. After declare(); every span and total has to be
* whole scale blocks when the plane is 1/128, which head widths of 128 are. */
int span_parts(RadBuilder* b, const int64_t* lo, const int64_t* hi, const int64_t* total,
int n) const {
RAD_ARCH_TRY(rad_weight_shard_span_parts(b, w, lo, hi, total, n));
if (!ws) return RAD_OK;
if (ws_row_div == 1) return rad_weight_shard_span_parts(b, ws, lo, hi, total, n);
int64_t slo[RAD_MAX_ROW_PARTS], shi[RAD_MAX_ROW_PARTS], stot[RAD_MAX_ROW_PARTS];
for (int g = 0; g < n && g < RAD_MAX_ROW_PARTS; ++g) {
if (lo[g] % ws_row_div || hi[g] % ws_row_div || total[g] % ws_row_div) {
fprintf(stderr, "radiance: a part span [%lld, %lld) of %lld rows is not whole "
"%lld-row scale blocks\n", (long long)lo[g], (long long)hi[g],
(long long)total[g], (long long)ws_row_div);
return RAD_E_INVAL;
}
slo[g] = lo[g] / ws_row_div;
shi[g] = hi[g] / ws_row_div;
stot[g] = total[g] / ws_row_div;
}
return rad_weight_shard_span_parts(b, ws, slo, shi, stot, n);
}
};
/* THE NAME MAP OF A LINEAR, DECLARED BEFORE ITS WEIGHT: it is how the checkpoint -- or the recipe
@@ -928,6 +962,7 @@ inline int LinearFP8::declare(RadBuilder* b, Names& nm, const Geom& g, const cha
* bf16 release) declares the same two views; what makes the planes exist is rad-convert. */
w = decl_view(b, wn, nullptr, "codes", RAD_F8E4M3, { N, K },
RAD_ACCESS_PER_TOKEN, shard, grp, wparts, np);
ws_row_div = RAD_FP8_BLOCK;
ws = decl_view(b, sn, wn, "scale", RAD_BF16, { fp8_blocks(N), fp8_blocks(K) },
RAD_ACCESS_PER_TOKEN, shard, grp, sparts, np);
if (!w || !ws) return RAD_E_INVAL;