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
@@ -783,8 +783,10 @@ static const RadParamSpec pPenal[] = { P_INT("M"), P_INT("n_vocab"), P_INTO("vo
|
||||
static const RadOperandSpec oPenalties[] = { INOUT("logits"), OPD("params"), OPD("history") };
|
||||
static const RadOperandSpec oDry[] = { INOUT("logits"), OPD("params"), OPD("history"),
|
||||
OPD_O("breakers") };
|
||||
/* `whitelist` is optional, libref's: a bitmask plane a row, a SET bit exempting a token from
|
||||
* the ban. Absent, nothing is exempt. */
|
||||
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") };
|
||||
static const RadOperandSpec oMask[] = { INOUT("logits"), OPD("params"), OPD("bitmask") };
|
||||
static const RadParamSpec pTopk[] = { P_INT("M"), P_INT("n_vocab"), P_INTO("vocab_off") };
|
||||
@@ -1225,7 +1227,8 @@ static const RadOpSchema kSchemas[] = {
|
||||
{ "sample_ngram_ban", ARR(pPenal), ARR(oNgramBan),
|
||||
"the windowed no-repeat-ngram ban: every token completing an n-gram the last `window` tokens of "
|
||||
"the row's history contain is set to -infinity. `ngram` is an i32 {n, window} pair a row; n 0 "
|
||||
"is off." },
|
||||
"is off. The optional `whitelist` bitmask exempts a token whose column bit is set; absent, "
|
||||
"nothing is exempt." },
|
||||
{ "sample_temp", ARR(pMVocab), ARR(oTemp), "per-request temperature." },
|
||||
{ "sample_topk", ARR(pTopk), ARR(oTopk), "exact top-k candidate set, descending, ties to the "
|
||||
"lower id." },
|
||||
|
||||
+16
-1
@@ -237,10 +237,15 @@ AVX_KERNEL(sample_dry) {
|
||||
*
|
||||
* The work is integer comparisons over at most a window of history, so the rows are parallel and
|
||||
* the scan inside a row stays scalar: libref's own loop, bit for bit. A row with n 0 (the
|
||||
* default) is skipped before it reads anything. */
|
||||
* default) is skipped before it reads anything.
|
||||
*
|
||||
* The optional `whitelist` bitmask (a SET bit, the row's own plane row) exempts a token from
|
||||
* the ban, the reference's `banned.difference_update(self.whitelist)`; absent, nothing is
|
||||
* exempt, and the result is bit-for-bit the ban without it. */
|
||||
AVX_KERNEL(sample_ngram_ban) {
|
||||
if (!rad_args_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 = rad_arg_in(a, 4);
|
||||
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;
|
||||
@@ -251,6 +256,9 @@ AVX_KERNEL(sample_ngram_ban) {
|
||||
if (hmax <= 0) return RAD_E_SHAPE;
|
||||
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;
|
||||
|
||||
AVX_PARALLEL_FOR_IF(M >= 2)
|
||||
for (int64_t m = 0; m < M; ++m) {
|
||||
@@ -271,7 +279,13 @@ AVX_KERNEL(sample_ngram_ban) {
|
||||
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 (int64_t)(int32_t)ldi(hist, hb + i * hs); };
|
||||
auto exempt = [&](int64_t col) {
|
||||
if (!wl) return false;
|
||||
const uint32_t word = (uint32_t)ldi(wl, wb + (col / 32) * ws);
|
||||
return ((word >> (uint32_t)(col % 32)) & 1u) != 0u;
|
||||
};
|
||||
const int64_t plen = n - 1, p0 = hl - plen;
|
||||
|
||||
for (int64_t idx = search_start; idx < search_end; ++idx) {
|
||||
@@ -283,6 +297,7 @@ AVX_KERNEL(sample_ngram_ban) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user