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

+7 -1
View File
@@ -970,6 +970,9 @@ int uocr_mode(const VisionConfig& c, const ImageMode& mode, bool* crop, int32_t*
"patches (" + std::to_string(F) + ")");
if (bs < 4 * F)
return no("base_size " + std::to_string(bs) + " is under two output rows");
if (bs / c.patch != 64 && bs / c.patch != 40)
return no("the DeepEncoder serves base grids 64 and 40 (base_size 1024 or 640); "
"base_size " + std::to_string(bs) + " is neither");
if (mode.image_size > 0 && mode.image_size != c.tile)
return no("crop mode cuts pictures into " + std::to_string(c.tile) + "-pixel tiles; "
"image_size " + std::to_string(mode.image_size) + " is not one");
@@ -980,6 +983,9 @@ int uocr_mode(const VisionConfig& c, const ImageMode& mode, bool* crop, int32_t*
return no("image_size " + std::to_string(is) + " is not a whole number of merged patches "
"(" + std::to_string(F) + ")");
if (is < 4 * F) return no("image_size " + std::to_string(is) + " is under two output rows");
if (is / c.patch != 64 && is / c.patch != 40)
return no("the DeepEncoder serves base grids 64 and 40 (image_size 1024 or 640); "
"image_size " + std::to_string(is) + " is neither");
if (mode.base_size > 0 && mode.base_size != bs)
return no("the base mode pads a page to image_size, not base_size");
*crop = false; *base_size = bs; *image_size = is;
@@ -1101,7 +1107,7 @@ int Processor::image_unlimitedocr(const Frame& f, const ImageMode& mode,
* patches a row carry pixels; the rest are the newline column. */
auto append = [&](const Frame& src, int32_t x0, int32_t y0, int32_t gh, int32_t gw,
int32_t real_w) {
it->segments.push_back({ gh, gw, it->n_patch });
it->segments.push_back({ gh, gw, it->n_patch, real_w == 0 });
it->seg_at.push_back((int32_t)seg_row);
it->expand.insert(it->expand.end(), (size_t)(gh / M) * (size_t)(gw / M), c.tok_image);
seg_row += (int64_t)(gh / M) * (gw / M);