Archived
unlimitedocr: tiled/base e2e parity, per-segment tower layout, n-gram whitelist
The pass packer now keeps a view and its one-cell separator in one pass, and RadBatch carries each segment's grid host-side (enc_seg_h/enc_seg_w) so the DeepEncoder no longer reads device coordinates to pick a geometry. The tower lays out a line of n tiles as kMap rows of n*kMap features plus one newline cell, accepts an earlier chunk of a longer line, and emits the learned view_seperator for an explicit 4x4 separator rather than any square segment. The device sam_attn resamples a rel_pos table that is not 2*tile-1 rows on read (the 127-row global tables serve a 40-grid block as 79), matching libref/libavx. The n-gram ban gains the reference's optional whitelist (5th operand, OAI keys, generation_config alias) with range/dtype checks. Gates: tiled e2e stage cosines 0.9994-1.0, det/text 0.9901 with every coordinate within 1 px; two-page 0.9917 within 2 px; device selftest sam_attn (incl. 127->79) and ngram whitelist (1344 columns) 0 mismatches.
This commit is contained in:
1 parent
fad4ba7f1a
commit
52637ec186
37 files changed
+401566
-778
No files matched your search
+10
-3
@@ -704,9 +704,13 @@ static const RadOperandSpec oPenalties[] = { INOUT("logits"), OPD("params"), OPD
|
||||
* is a whole DRY sequence breaker and never penalised. Absent, no token is exempt. */
|
||||
static const RadOperandSpec oDry[] = { INOUT("logits"), OPD("params"), OPD("history"),
|
||||
OPD_O("breakers") };
|
||||
/* The windowed n-gram ban: penalties' operands plus a {n, window} pair a row. */
|
||||
/* The windowed n-gram ban: penalties' operands plus a {n, window} pair a row.
|
||||
* `whitelist` is optional: a bitmask plane [M, ceil(n_vocab/32)] like sample_mask's, a SET bit
|
||||
* marking a token exempt from the ban (the reference's whitelist, removed from the banned set
|
||||
* before the -inf writes). Absent, nothing is exempt. Rows are indexed by the sampled position,
|
||||
* not by mask_row: every row the op bans reads its own words. */
|
||||
static const RadOperandSpec oNgramBan[] = { INOUT("logits"), OPD("params"), OPD("history"),
|
||||
OPD("ngram") };
|
||||
OPD("ngram"), OPD_O("whitelist") };
|
||||
static const RadOperandSpec oTemp[] = { INOUT("logits"), OPD("params") };
|
||||
/* `bitmask` is [rows, ceil(n_vocab/32)] uint32, addressed by the row's mask_row -- which is -1 for
|
||||
* an unconstrained sequence, so the plane is shared and shorter than M. */
|
||||
@@ -1541,7 +1545,10 @@ static const RadOpSchema kSchemas[] = {
|
||||
"by setting -infinity, every token that would complete an n-gram the last `window` tokens of "
|
||||
"the row's history already contain. `ngram` is one i32 {n, window} pair a row; the window "
|
||||
"bounds the n-gram's START index, as in the reference, window <= 0 searches the whole span and "
|
||||
"n 0 is off. Columns are ids less vocab_off." },
|
||||
"n 0 is off. The optional `whitelist` bitmask (a SET bit, word w bit b covering column 32w + b, "
|
||||
"the row's own plane row) exempts a token from the ban, as the reference's "
|
||||
"`banned.difference_update(whitelist)` does; absent, nothing is exempt. Columns are ids less "
|
||||
"vocab_off." },
|
||||
{ "sample_temp", ARR(pMVocab), ARR(oTemp),
|
||||
"logits /= temp, per row. temp <= 0 leaves the row untouched -- greedy decoding is "
|
||||
"sample_argmax, and a temperature of zero silently meaning something else is how a sampler "
|
||||
|
||||
+20
-1
@@ -256,10 +256,17 @@ int ref_sample_dry(const RadArgs* a, RadStream) {
|
||||
* Ids are global and columns are global less `vocab_off`; a banned token on another rank's shard
|
||||
* is that rank's to mask. Rows whose n is 0 (the default) are untouched, so a request without the
|
||||
* ban leaves the logits bit for bit as they were. The scan is O(w * n) a row and compares
|
||||
* integers, so every implementation (this one, libavx, libr4d) agrees by construction. */
|
||||
* integers, so every implementation (this one, libavx, libr4d) agrees by construction.
|
||||
*
|
||||
* The optional `whitelist` bitmask is the reference's whitelist: a token whose column bit is set
|
||||
* in the row's own plane row is removed from the banned set before the -inf writes
|
||||
* (`banned.difference_update(self.whitelist)`, modeling_unlimitedocr.py:379), so it is never
|
||||
* banned. Absent, nothing is exempt -- the default serving form, bit-identical to the ban
|
||||
* without the operand. */
|
||||
int ref_sample_ngram_ban(const RadArgs* a, RadStream) {
|
||||
if (!have(a, 4)) return RAD_E_INVAL;
|
||||
const RadTensor *lg = &a->t[0], *pr = &a->t[1], *hist = &a->t[2], *ng = &a->t[3];
|
||||
const RadTensor* wl = a->n_t > 4 && a->t[4].data ? &a->t[4] : nullptr;
|
||||
const int64_t n_vocab = p_int(a, "n_vocab", lg->rank >= 2 ? lg->shape[lg->rank - 1] : 0);
|
||||
if (n_vocab <= 0) return RAD_E_SHAPE;
|
||||
const int64_t M = numel(lg) / n_vocab;
|
||||
@@ -272,6 +279,9 @@ int ref_sample_ngram_ban(const RadArgs* a, RadStream) {
|
||||
* read past its end. */
|
||||
if (numel(ng) < 2 * M) return RAD_E_SHAPE;
|
||||
const int64_t voff = p_int(a, "vocab_off", 0);
|
||||
const int64_t wwords = (n_vocab + 31) / 32;
|
||||
if (wl && wl->dtype != RAD_I32 && wl->dtype != RAD_U32) return RAD_E_DTYPE;
|
||||
if (wl && numel(wl) < M * wwords) return RAD_E_SHAPE;
|
||||
|
||||
REF_PAR_FOR(M * hmax)
|
||||
for (int64_t m = 0; m < M; ++m) {
|
||||
@@ -294,9 +304,17 @@ int ref_sample_ngram_ban(const RadArgs* a, RadStream) {
|
||||
const int64_t hb = rowoff(hist, m, hmax) + ho * laststride(hist);
|
||||
const int64_t hs = laststride(hist);
|
||||
const int64_t lb = rowoff(lg, m, n_vocab), ls = laststride(lg);
|
||||
const int64_t wb = wl ? rowoff(wl, m, wwords) : 0, ws = wl ? laststride(wl) : 0;
|
||||
auto tok_at = [&](int64_t i) {
|
||||
return ld_int(hist->dtype, hist->data, hb + i * hs);
|
||||
};
|
||||
/* The reference removes the whitelist from the banned set before it writes; a column
|
||||
* whose bit is set in the row's whitelist words is therefore never written. */
|
||||
auto exempt = [&](int64_t col) {
|
||||
if (!wl) return false;
|
||||
const uint32_t word = (uint32_t)ld_int(wl->dtype, wl->data, wb + (col / 32) * ws);
|
||||
return ((word >> (uint32_t)(col % 32)) & 1u) != 0u;
|
||||
};
|
||||
/* n == 1 bans every token in the window: the prefix is empty, as in the reference. */
|
||||
const int64_t plen = n - 1, p0 = hl - plen;
|
||||
|
||||
@@ -309,6 +327,7 @@ int ref_sample_ngram_ban(const RadArgs* a, RadStream) {
|
||||
const int64_t tok = tok_at(idx + plen);
|
||||
const int64_t col = tok - voff;
|
||||
if (tok < 0 || col < 0 || col >= n_vocab) continue;
|
||||
if (exempt(col)) continue;
|
||||
stt(lg, lb + col * ls, -INFINITY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2387,7 +2387,11 @@ int ref_sample_dry_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* ou
|
||||
* and adds one small plane beside them: `ngram`, an i32 {n-gram length, window} pair a row. It is
|
||||
* a plane of its own rather than fields in `params` because the params row is a fixed 24-word wire
|
||||
* format shared by every sampler op (and recorded in the kbench fixtures). Drawn in 0..63 so both
|
||||
* a length inside the 64-token history and the 0 (= off) and whole-window forms occur. */
|
||||
* a length inside the 64-token history and the 0 (= off) and whole-window forms occur.
|
||||
*
|
||||
* The optional `whitelist` bitmask is sample_mask's plane shape (word w bit b covers column
|
||||
* 32w + b, a SET bit marking an exempt token), addressed by the sampled row itself; a random draw
|
||||
* fills it with random bits, so a sweep exercises exemptions as often as plain bans. */
|
||||
int ref_sample_ngram_ban_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
int64_t M = 0, nv = 0;
|
||||
if (sample_vocab(p, n_p, &M, &nv) < 0) return RAD_E_UNSUPPORTED;
|
||||
@@ -2397,6 +2401,7 @@ int ref_sample_ngram_ban_shape(const RadParam* p, int n_p, int operand, RadOpdDe
|
||||
o.t_idx({ M, (int64_t)REF_SAMPLE_HIST }, nv, -1,
|
||||
(uint32_t)RAD_OPD_F_IDX_HISTORY); /* history */
|
||||
o.t_idx({ M, 2 }, 64, -1, 0); /* ngram: {n, window} */
|
||||
o.t((uint32_t)RAD_I32, { M, (nv + 31) / 32 }); /* whitelist, optional */
|
||||
return o.finish("sample_ngram_ban", operand, out);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user