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

+33 -2
View File
@@ -13,6 +13,23 @@ int weight_share(const WeightInfo& w, const RadEncoding& enc, uint32_t rank, con
return RAD_E_SHAPE;
};
if (w.n_sel < 1 || w.n_sel > RAD_ENC_MAX_PLANES) return refuse("no planes selected");
/* A ZERO SHARE: the declaration's own extents of every selected plane, and nothing to read.
* At one rank there is no share to zero -- the weight is whole and real. */
if (w.shard_zero && world > 1) {
for (int k = 0; k < w.n_sel; ++k) {
const RadEncPlane& p = enc.plane[w.sel[k]];
PlaneShare& s = out[k];
s = PlaneShare{};
s.dtype = p.dtype;
s.rows = w.sel_rows[k];
s.cols = w.sel_cols[k];
s.row_bytes = rad_enc_row_bytes(p.dtype, s.cols);
s.zero = true;
if (s.rows <= 0 || s.cols <= 0)
return refuse(fmt("a zero share of the '%s' plane has no extent", p.role));
}
return RAD_OK;
}
int64_t R = 0, C = 0;
rad_enc_view(rank, shape, &R, &C);
@@ -38,7 +55,7 @@ int weight_share(const WeightInfo& w, const RadEncoding& enc, uint32_t rank, con
struct VRect { int64_t r0, r1, c0, c1; };
std::vector<VRect> view;
const bool span = w.shard_hi > 0;
const bool span = w.shard_hi > 0 || w.n_part_spans > 0;
if (whole) {
view.push_back({ 0, VR, 0, VC });
} else {
@@ -74,7 +91,21 @@ int weight_share(const WeightInfo& w, const RadEncoding& enc, uint32_t rank, con
* a slice of EACH of them, not a contiguous slice of the stack. The parts are THIS
* RANK'S rows, so a part is `world` times as many rows in the entry. */
const int np = w.decl.n_row_parts > 1 ? w.decl.n_row_parts : 1;
if (span) {
if (w.n_part_spans > 0) {
/* PER-PART SPANS: the plugin stated each stacked part's rows in the container
* and this rank's [lo, hi) of it, so the parts need not be equal. */
if (w.n_part_spans != np)
return refuse(fmt("%d per-part spans for %d stacked parts", w.n_part_spans, np));
int64_t sum = 0, soff = 0;
for (int g = 0; g < np; ++g) sum += w.part_total[g];
if (sum != VR)
return refuse(fmt("the %d stacked parts' stated rows sum to %lld and the entry "
"has %lld", np, (long long)sum, (long long)VR));
for (int g = 0; g < np; ++g) {
view.push_back({ soff + w.part_lo[g], soff + w.part_hi[g], 0, VC });
soff += w.part_total[g];
}
} else if (span) {
if (VR % np) return refuse(fmt("%lld rows do not divide into %d parts",
(long long)VR, np));
const int64_t cpart = VR / np;