format: a span per stacked part, and a share that is zeros

Two additive builder exports, RAD_ABI_VERSION untouched.

rad_weight_shard_span_parts: a row-sharded weight whose stacked parts
are not the same width -- the delta net's [q|k|v|z], 2048, 2048, 6144,
6144 rows on Flash-Next -- cannot take rad_weight_shard_span's one
[lo, hi), which is applied to every part and assumes them equal. This
takes a span per part together with each part's whole extent in the
container; share.cpp cuts every part by its own rows and refuses totals
that do not sum to the entry. It is how a rank declares an UNEVEN share
of the heads -- 6 of 16 K heads where three ranks take 6, 5 and 5 --
with nothing padded.

rad_weight_shard_zero: this rank's share of a row- or column-sharded
weight is zeros. weight_share returns the declaration's extents with no
rectangles; the loader stages the weight with a worker that writes
zeros (the route a checkpoint weight already takes from a container)
and reads nothing. It is for a rank the geometry gives no real heads
(next commit), which then declares the same program as its peers.

share_test holds the per-part cut and the zero share.
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-06 11:23:06 +02:00
1 parent 1936bc881f
commit 82445ca71f
9 files changed
+241 -8

No files matched your search

+43
View File
@@ -1349,4 +1349,47 @@ TEST(the_gate_names_its_caller) {
CHECK(has(msg, "the container's layout"));
}
/* A span, per-part spans and a zero share have to SURVIVE THE WEIGHT LIST GROWING: WeightInfo's
* copy is hand-written (the atomic), so a field the copy leaves out is reset on every weight
* declared before the vector's last reallocation -- which is what the loader saw on rank 0 of a
* three-rank Flash-Next: layer 0's [a|b] with its per-part spans gone, refused as an even share. */
TEST(shard_spans_and_zero_survive_the_weight_list_reallocating) {
NEED_PLUGIN(reg)
Builder b(reg, make_meta(), make_ctx());
/* Three weights declared first and marked, then enough declared after them to grow the
* list several times over. */
RadWeightDecl d{};
d.dtype = RAD_BF16; d.rank = 2; d.shape[0] = 36; d.shape[1] = 64;
d.access = RAD_ACCESS_PER_TOKEN; d.shard = RAD_SHARD_ROW; d.group = rad_group_layer(0);
d.n_row_parts = 2; d.row_parts[0] = 18; d.row_parts[1] = 18;
const rad_weight ab = b.decl_weight("ab", &d);
REQUIRE(ab != 0);
const int64_t lo[2] = { 0, 0 }, hi[2] = { 18, 18 }, tot[2] = { 48, 48 };
CHECK_EQ(b.weight_shard_span_parts(ab, lo, hi, tot, 2), RAD_OK);
const rad_weight sp = decl_w(b, "span", 18, 64);
CHECK_EQ(b.weight_shard_span(sp, 6, 24), RAD_OK);
const rad_weight z = decl_w(b, "zero", 18, 64);
CHECK_EQ(b.weight_shard_zero(z), RAD_OK);
for (int i = 0; i < 300; ++i) {
char n[32]; snprintf(n, sizeof n, "w%d", i);
REQUIRE(decl_w(b, n, 64, 64) != 0);
}
const WeightInfo* w = b.program().weight(ab);
REQUIRE(w != nullptr);
CHECK_EQ(w->n_part_spans, 2);
CHECK_EQ((long long)w->part_lo[1], 0LL);
CHECK_EQ((long long)w->part_hi[1], 18LL);
CHECK_EQ((long long)w->part_total[1], 48LL);
w = b.program().weight(sp);
CHECK_EQ((long long)w->shard_lo, 6LL);
CHECK_EQ((long long)w->shard_hi, 24LL);
w = b.program().weight(z);
CHECK(w->shard_zero);
CHECK_EQ((int)b.errors().size(), 0);
}
RAD_TEST_MAIN()
+51
View File
@@ -163,6 +163,57 @@ TEST(an_uneven_span_is_the_rows_the_plugin_names) {
CHECK_EQ(s[1].rows, (int64_t)3);
}
/* PER-PART SPANS: a stacked weight whose parts are not the same width -- the delta net's
* [q|k|v|z] -- takes a span per part, each in its own part's rows. Three ranks over 16 K heads of
* 128: rank 1 takes K heads [6, 11) of q and of k, and V heads [18, 33) of 48 in v. */
TEST(per_part_spans_cut_each_stacked_part_by_its_own_rows) {
const RadEncoding e = rad_enc_plain(RAD_BF16);
/* entry: q 2048 | k 2048 | v 6144 rows; rank 1 of 3 declares 640 + 640 + 1920 */
WeightInfo w = decl(e, { 0 }, 2048 + 2048 + 6144, 64, RAD_SHARD_ROW, 3, { 640, 640, 1920 });
w.decl.shape[0] = 640 + 640 + 1920;
rad_enc_plane_dims(&e.plane[0], w.decl.shape[0], 64, &w.sel_rows[0], &w.sel_cols[0]);
w.n_part_spans = 3;
const int64_t lo[3] = { 768, 768, 2304 }, hi[3] = { 1408, 1408, 4224 };
const int64_t tot[3] = { 2048, 2048, 6144 };
for (int g = 0; g < 3; ++g) { w.part_lo[g] = lo[g]; w.part_hi[g] = hi[g]; w.part_total[g] = tot[g]; }
PlaneShare s[RAD_ENC_MAX_PLANES];
REQUIRE_EQ(share(w, 2048 + 2048 + 6144, 64, 3, 1, s), RAD_OK);
REQUIRE_EQ(s[0].rects.size(), (size_t)3);
CHECK_EQ(s[0].rects[0].row0, (int64_t)768);
CHECK_EQ(s[0].rects[0].rows, (int64_t)640);
CHECK_EQ(s[0].rects[1].row0, (int64_t)(2048 + 768));
CHECK_EQ(s[0].rects[2].row0, (int64_t)(4096 + 2304));
CHECK_EQ(s[0].rects[2].rows, (int64_t)1920);
CHECK_EQ(s[0].rows, (int64_t)3200);
/* totals that do not sum to the entry are refused */
w.part_total[2] = 6000;
std::string why;
CHECK_EQ(share(w, 2048 + 2048 + 6144, 64, 3, 1, s, &why), RAD_E_SHAPE);
CHECK(why.find("stated rows") != std::string::npos);
}
/* A ZERO SHARE has the declaration's extents and no rectangles: the loader writes zeros and reads
* nothing. At one rank there is nothing to zero. */
TEST(a_zero_share_is_the_declared_extent_and_no_rectangles) {
const RadEncoding e = fp8_block();
WeightInfo w = decl(e, { 0, 1 }, 1536, 128, RAD_SHARD_ROW, 3);
w.shard_zero = true;
PlaneShare s[RAD_ENC_MAX_PLANES];
REQUIRE_EQ(share(w, 1536, 128, 3, 2, s), RAD_OK);
CHECK(s[0].zero);
CHECK_EQ(s[0].rects.size(), (size_t)0);
CHECK_EQ(s[0].rows, (int64_t)512);
CHECK_EQ(s[0].cols, (int64_t)128);
CHECK_EQ(s[0].dense_bytes(), (int64_t)(512 * 128));
CHECK(s[1].zero);
CHECK_EQ(s[1].rows, (int64_t)4);
WeightInfo one = decl(e, { 0, 1 }, 1536, 128, RAD_SHARD_ROW, 1);
one.shard_zero = true;
REQUIRE_EQ(share(one, 1536, 128, 1, 0, s), RAD_OK);
CHECK(!s[0].zero);
CHECK_EQ(s[0].rows, (int64_t)1536);
}
/* A per-tensor scale is one value every rank carries whole, once, whatever the codes' cut. */
TEST(a_per_tensor_scale_is_carried_whole_by_every_rank) {
RadEncoding e;