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:
Juup committed 2026-10-20 07:04:01 +00:00
1 parent fad4ba7f1a
commit 52637ec186
37 files changed
+401566 -778

No files matched your search

+29 -1
View File
@@ -240,7 +240,7 @@ const char* kAcceptedCommon[] = {
"dry_sequence_breakers", "samplers",
"grammar", "json_schema", "priority", "logprobs", "ignore_eos",
"timings_per_token", "return_progress", "session_id", "n_probs",
"ngram_ban_n", "ngram_window",
"ngram_ban_n", "ngram_window", "ngram_whitelist", "no_repeat_ngram_whitelist",
};
const char* kAcceptedChat[] = {
@@ -916,6 +916,34 @@ static int parse_sampling(const json& b, const OaiLimits& lim, OaiRequest* r, Ap
}
r->sp.ngram_window = (int)i64;
/* The ban's whitelist (the reference's `whitelist_token_ids`, which is removed from the
* banned set before the -inf writes): token ids the ban must never touch. An array of
* non-negative integers; absent, empty or null is off, the reference's empty whitelist and
* the form the model's generation_config ships. */
auto nwl = b.find("ngram_whitelist");
if (nwl == b.end()) nwl = b.find("no_repeat_ngram_whitelist");
if (nwl != b.end() && !nwl->is_null()) {
if (!nwl->is_array()) {
*err = err_bad("ngram_whitelist", "expected an array of integer token ids");
return RAD_E_INVAL;
}
std::vector<int32_t> wl;
for (const auto& v : *nwl) {
int32_t id = 0;
if (!token_id(v, &id)) {
*err = err_bad("ngram_whitelist",
"expected token ids in [0, " + std::to_string(INT32_MAX) + "]");
return RAD_E_INVAL;
}
if (wl.size() >= (size_t)1 << 20) {
*err = err_bad("ngram_whitelist", "at most 1048576 ids");
return RAD_E_INVAL;
}
wl.push_back(id);
}
r->sp.ngram_whitelist = std::move(wl);
}
/* `images_config`: Unlimited-OCR's two picture modes. A string names one ("gundam" for a
* single picture -- the global view plus crops --, "base" for a page of a multi-page
* document); an object carries the reference runner's own dict. */