Archived
unlimitedocr: prefill and decode performance work
- sam_attn: tile queries and hoist the relative-position dots; the tower drops from 0.44-2.09 s to 0.10-0.36 s per tile. - processor: split OCR patch/LUT staging across rows, then make both bicubic passes and the LUT append AVX2 (bit-exact, 1.15-1.38x host preprocessing). - tower: batch the DeepEncoder across every tile segment of an encode pass. Patch embed, the 12 SAM blocks, neck, the 24 CLIP blocks and the projector run once per batch of up to 8 tiles (4 at the 64 grid); sam_attn and attn_dense stay segment-independent through B+1 cu tables, and position tables are host-staged PERSIST planes. B == 1 emits the old graph. Fix the newline layout: the reference expands image_newline over every map row, while the copy read past the one-row vector; with a multi-tile batch that made the trailing cells live data and the decoder dropped the text at the right margin of every line. - attn: instantiate attn_paged_qrow at head_dim 128 (bf16 and fp8 caches) and read OCR's q slice of the fused q|k|v plane in place, keeping the dense cast as the fallback when the library does not serve the qrow row. - tests: h128 attention emulator cases, a batched-tower arch test, an AVX2 bit-identity test, and a 15 s arch_test CPU budget for the image. Measured through the router at 256 tokens: 8-page TTFT 4157 -> 1327 ms, 640 page 608 -> 284 ms, 8 concurrent pages 17.6 -> 4.26 s wall; decode unchanged at ~344 tok/s. Parse gate 0.9901 text / 1 px on the deployed image.
This commit is contained in:
1 parent
8bcf695db9
commit
912c57cb21
14 files changed
+1026
-398
No files matched your search
@@ -34,6 +34,7 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
@@ -1805,4 +1806,66 @@ TEST(unlimitedocr_bicubic_antialias_resample_is_the_reference) {
|
||||
(void)clip_mism;
|
||||
}
|
||||
|
||||
/* The AVX2 resample and patch-staging paths must be the scalar function, not an approximation:
|
||||
* the goldens above pin the modelled result, and this pins the vector lanes against the scalar
|
||||
* loop that produced them. RAD_MM_NO_AVX2 selects the scalar path (core/mm/processor.cpp), so the
|
||||
* same input goes through both dispatches on this host. Sizes cover growth and shrink (different
|
||||
* tap counts), both pass orders, odd widths/tails, and a 1-pixel side. */
|
||||
TEST(avx2_preprocessing_is_bit_identical_to_scalar) {
|
||||
const struct { int32_t ih, iw, oh, ow; } cases[] = {
|
||||
{ 53, 67, 35, 40 }, { 53, 67, 55, 57 }, { 64, 64, 1024, 1024 },
|
||||
{ 1024, 1024, 640, 640 }, { 200, 100, 50, 200 }, { 97, 129, 96, 128 },
|
||||
{ 1, 1, 7, 5 }, { 71, 131, 70, 130 }, { 17, 31, 9, 8 },
|
||||
{ 300, 500, 299, 501 },
|
||||
};
|
||||
int seed = 11;
|
||||
for (const auto& c : cases) {
|
||||
Frame in = frame(seed++, c.ih, c.iw);
|
||||
Frame sv, sm, tv, tm;
|
||||
setenv("RAD_MM_NO_AVX2", "1", 1);
|
||||
resize_bicubic(in, c.ow, c.oh, &sv);
|
||||
resize_bicubic_torch(in, c.ow, c.oh, &tv);
|
||||
unsetenv("RAD_MM_NO_AVX2");
|
||||
resize_bicubic(in, c.ow, c.oh, &sm);
|
||||
resize_bicubic_torch(in, c.ow, c.oh, &tm);
|
||||
CHECK_EQ(sm.w, sv.w);
|
||||
CHECK_EQ(sm.h, sv.h);
|
||||
CHECK(sm.rgb == sv.rgb);
|
||||
CHECK(tm.rgb == tv.rgb);
|
||||
if (sm.rgb != sv.rgb) {
|
||||
for (size_t i = 0; i < sv.rgb.size(); ++i)
|
||||
if (sm.rgb[i] != sv.rgb[i]) {
|
||||
std::fprintf(stderr, " %dx%d -> %dx%d: first byte %zu differs (%d vs %d)\n",
|
||||
c.iw, c.ih, c.ow, c.oh, i, (int)sv.rgb[i], (int)sm.rgb[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Patch/LUT staging (the Unlimited-OCR append path), through the whole processor so the
|
||||
* segment order and both views are covered. */
|
||||
Processor p;
|
||||
REQUIRE_EQ(p.init(uocr_cfg(), [](const std::string&) { return std::vector<int32_t>{}; },
|
||||
uocr_marker), RAD_OK);
|
||||
const struct { int32_t seed, h, w; } imgs[] = { { 3, 640, 640 }, { 4, 900, 1400 } };
|
||||
for (const auto& g : imgs) {
|
||||
Frame in = frame(g.seed, g.h, g.w);
|
||||
for (int kind = 0; kind < 2; ++kind) {
|
||||
ImageMode mode;
|
||||
mode.kind = kind ? ImageMode::Base : ImageMode::Gundam;
|
||||
std::shared_ptr<Item> a, b;
|
||||
std::string why;
|
||||
setenv("RAD_MM_NO_AVX2", "1", 1);
|
||||
REQUIRE_EQ(p.image_from(in, &a, &why, mode), RAD_OK);
|
||||
unsetenv("RAD_MM_NO_AVX2");
|
||||
REQUIRE_EQ(p.image_from(in, &b, &why, mode), RAD_OK);
|
||||
REQUIRE(a != nullptr);
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(b->n_patch, a->n_patch);
|
||||
CHECK(b->pixels == a->pixels);
|
||||
CHECK(b->expand == a->expand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
Reference in new issue
Block a user