Archived
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:
1 parent
1936bc881f
commit
82445ca71f
9 files changed
+241
-8
No files matched your search
@@ -149,6 +149,9 @@ public:
|
||||
int op_writes(rad_op h, const rad_buf* b, int n);
|
||||
int buf_concurrent(rad_buf b);
|
||||
int weight_shard_span(rad_weight w, int64_t lo, int64_t hi);
|
||||
int weight_shard_span_parts(rad_weight w, const int64_t* lo, const int64_t* hi,
|
||||
const int64_t* total, int n);
|
||||
int weight_shard_zero(rad_weight w);
|
||||
|
||||
/* Finalise: weight first/last use, KV group geometry, buffer liveness and packing. Returns
|
||||
* RAD_OK, or the first structural error class. Resolution MISSES are not an error here -- an
|
||||
|
||||
@@ -892,6 +892,53 @@ int Builder::weight_shard_span(rad_weight h, int64_t lo, int64_t hi) {
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int Builder::weight_shard_span_parts(rad_weight h, const int64_t* lo, const int64_t* hi,
|
||||
const int64_t* total, int n) {
|
||||
if (finished_) { err(RAD_E_STATE, "weight_shard_span_parts after declare finished"); return RAD_E_STATE; }
|
||||
if (h == 0 || h >= prog_.weights.size() || !lo || !hi || !total) return RAD_E_INVAL;
|
||||
WeightInfo& w = prog_.weights[h];
|
||||
const RadWeightDecl& d = w.decl;
|
||||
if (d.shard != RAD_SHARD_ROW || d.n_row_parts < 2 || n != d.n_row_parts) {
|
||||
err(RAD_E_INVAL, "weight '%s': per-part spans need a row-sharded weight of %d stacked "
|
||||
"parts, and %d span(s) were given", w.name.c_str(), d.n_row_parts, n);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
for (int g = 0; g < n; ++g) {
|
||||
if (lo[g] < 0 || hi[g] <= lo[g] || hi[g] > total[g]) {
|
||||
err(RAD_E_INVAL, "weight '%s': part %d span [%lld, %lld) is empty or outside its "
|
||||
"%lld rows", w.name.c_str(), g, (long long)lo[g], (long long)hi[g],
|
||||
(long long)total[g]);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
if (d.row_parts[g] != hi[g] - lo[g]) {
|
||||
err(RAD_E_SHAPE, "weight '%s': part %d span [%lld, %lld) is %lld wide and the "
|
||||
"declared part is %lld", w.name.c_str(), g, (long long)lo[g],
|
||||
(long long)hi[g], (long long)(hi[g] - lo[g]), (long long)d.row_parts[g]);
|
||||
return RAD_E_SHAPE;
|
||||
}
|
||||
w.part_lo[g] = lo[g];
|
||||
w.part_hi[g] = hi[g];
|
||||
w.part_total[g] = total[g];
|
||||
}
|
||||
w.n_part_spans = n;
|
||||
w.shard_lo = 0;
|
||||
w.shard_hi = 0;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int Builder::weight_shard_zero(rad_weight h) {
|
||||
if (finished_) { err(RAD_E_STATE, "weight_shard_zero after declare finished"); return RAD_E_STATE; }
|
||||
if (h == 0 || h >= prog_.weights.size()) return RAD_E_INVAL;
|
||||
WeightInfo& w = prog_.weights[h];
|
||||
if (w.decl.shard != RAD_SHARD_ROW && w.decl.shard != RAD_SHARD_COL) {
|
||||
err(RAD_E_INVAL, "weight '%s': a zero share on a weight that is not row- or "
|
||||
"column-sharded", w.name.c_str());
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
w.shard_zero = true;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* ================================================================== name map */
|
||||
int Builder::decl_name_map(const RadNameMap* m) {
|
||||
if (finished_) { err(RAD_E_STATE, "decl_name_map after declare finished"); return RAD_E_STATE; }
|
||||
@@ -1615,6 +1662,17 @@ int rad_weight_shard_span(RadBuilder* b, rad_weight w, int64_t lo, int64_t hi) {
|
||||
return B(b)->weight_shard_span(w, lo, hi);
|
||||
}
|
||||
|
||||
int rad_weight_shard_span_parts(RadBuilder* b, rad_weight w, const int64_t* lo, const int64_t* hi,
|
||||
const int64_t* total, int n) {
|
||||
if (!b) return RAD_E_INVAL;
|
||||
return B(b)->weight_shard_span_parts(w, lo, hi, total, n);
|
||||
}
|
||||
|
||||
int rad_weight_shard_zero(RadBuilder* b, rad_weight w) {
|
||||
if (!b) return RAD_E_INVAL;
|
||||
return B(b)->weight_shard_zero(w);
|
||||
}
|
||||
|
||||
int rad_decl_name_map(RadBuilder* b, const RadNameMap* m) {
|
||||
if (!b) return RAD_E_INVAL;
|
||||
return B(b)->decl_name_map(m);
|
||||
|
||||
+21
-6
@@ -1979,11 +1979,15 @@ static int fill_from_checkpoint(const CkptWeight& cw, const std::vector<PlaneSha
|
||||
std::string why;
|
||||
for (size_t k = 0; k < shares.size(); ++k) {
|
||||
const PlaneShare& sh = shares[k];
|
||||
uint8_t* at = in + offs[k];
|
||||
if (sh.zero) {
|
||||
std::memset(at, 0, (size_t)sh.dense_bytes());
|
||||
continue;
|
||||
}
|
||||
const RadEncPlane& p = cw.enc.plane[sel[k]];
|
||||
int64_t pr = 0, pc = 0;
|
||||
rad_enc_plane_dims(&p, cw.rows, cw.cols, &pr, &pc);
|
||||
const int64_t crb = rad_enc_row_bytes(p.dtype, pc);
|
||||
uint8_t* at = in + offs[k];
|
||||
for (const PlaneShare::Rect& q : sh.rects) {
|
||||
if (q.byte0 == 0 && q.bytes == sh.row_bytes) {
|
||||
const int64_t off = q.row0 * sh.row_bytes, n = q.rows * sh.row_bytes;
|
||||
@@ -2296,8 +2300,11 @@ int Engine::load_weights() {
|
||||
|
||||
/* FROM A CHECKPOINT, every weight is staged and its worker reads it: there is no
|
||||
* sweep to deliver it, and the stored form is whatever the pool makes of the share --
|
||||
* as it is, widened, or relaid. */
|
||||
if (!e) {
|
||||
* as it is, widened, or relaid. A ZERO SHARE (rad_weight_shard_zero) takes the same
|
||||
* route from a container: nothing in the file is its source, so no sweep run can
|
||||
* deliver it; its worker writes zeros and the pool stores them as it would any share. */
|
||||
const bool zero_share = sh[0].zero;
|
||||
if (!e || zero_share) {
|
||||
StagedWeight sw;
|
||||
sw.prog = &r->program;
|
||||
sw.wi = i;
|
||||
@@ -2322,9 +2329,17 @@ int Engine::load_weights() {
|
||||
std::vector<int> sel(w.sel, w.sel + w.n_sel);
|
||||
std::vector<int64_t> offs(sw.plane_off, sw.plane_off + w.n_sel);
|
||||
const std::string name = w.name;
|
||||
sw.fill = [cw, shares, sel, offs, name](uint8_t* in) -> int {
|
||||
return fill_from_checkpoint(*cw, shares, sel, offs, name, in);
|
||||
};
|
||||
if (zero_share) {
|
||||
const int64_t bytes = in_bytes;
|
||||
sw.fill = [bytes](uint8_t* in) -> int {
|
||||
std::memset(in, 0, (size_t)bytes);
|
||||
return RAD_OK;
|
||||
};
|
||||
} else {
|
||||
sw.fill = [cw, shares, sel, offs, name](uint8_t* in) -> int {
|
||||
return fill_from_checkpoint(*cw, shares, sel, offs, name, in);
|
||||
};
|
||||
}
|
||||
staged.push_back(std::move(sw));
|
||||
++n_loaded;
|
||||
continue;
|
||||
|
||||
+33
-2
@@ -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;
|
||||
|
||||
@@ -27,6 +27,9 @@ struct PlaneShare {
|
||||
uint32_t dtype = RAD_DT_INVALID;
|
||||
int64_t rows = 0, cols = 0; /* the share's extents, in the plane's elements */
|
||||
int64_t row_bytes = 0;
|
||||
/* rad_weight_shard_zero: the share has its extents and no rectangles; the loader writes
|
||||
* dense_bytes() of zeros and reads nothing. */
|
||||
bool zero = false;
|
||||
int64_t dense_bytes() const; /* the share laid out dense: rows * a row of `cols` */
|
||||
};
|
||||
|
||||
|
||||
@@ -146,6 +146,13 @@ struct WeightInfo {
|
||||
/* An uneven shard's slice of the split dimension (rad_weight_shard_span); hi 0 is the even
|
||||
* split. */
|
||||
int64_t shard_lo = 0, shard_hi = 0;
|
||||
/* rad_weight_shard_span_parts: a span per stacked part and each part's rows in the
|
||||
* container; n_part_spans 0 is shard_lo/hi (one span for every part) or the even share. */
|
||||
int n_part_spans = 0;
|
||||
int64_t part_lo[RAD_MAX_ROW_PARTS] = {0}, part_hi[RAD_MAX_ROW_PARTS] = {0};
|
||||
int64_t part_total[RAD_MAX_ROW_PARTS] = {0};
|
||||
/* rad_weight_shard_zero: this rank reads nothing for it and the loader writes zeros. */
|
||||
bool shard_zero = false;
|
||||
|
||||
/* WHAT IT IS A VIEW OF (RadWeightDecl::source and ::planes, spec §4.3). `enc` is the source's
|
||||
* encoding as the model holds it -- or, with nothing behind the builder, plain in the declared
|
||||
@@ -201,6 +208,11 @@ struct WeightInfo {
|
||||
WeightInfo& operator=(const WeightInfo& o) {
|
||||
name = o.name; decl = o.decl; logical_bytes = o.logical_bytes;
|
||||
shard_lo = o.shard_lo; shard_hi = o.shard_hi;
|
||||
n_part_spans = o.n_part_spans;
|
||||
for (int i = 0; i < RAD_MAX_ROW_PARTS; ++i) {
|
||||
part_lo[i] = o.part_lo[i]; part_hi[i] = o.part_hi[i]; part_total[i] = o.part_total[i];
|
||||
}
|
||||
shard_zero = o.shard_zero;
|
||||
source = o.source; enc = o.enc; enc_known = o.enc_known; n_sel = o.n_sel;
|
||||
for (int i = 0; i < RAD_ENC_MAX_PLANES; ++i) {
|
||||
sel[i] = o.sel[i]; sel_rows[i] = o.sel_rows[i]; sel_cols[i] = o.sel_cols[i];
|
||||
|
||||
Reference in new issue
Block a user