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
@@ -1,5 +1,9 @@
|
||||
/* r4d_attn_paged_window.hip -- paged attention at head_dim 256 and 512, 1/2/4/8 queries per KV
|
||||
* head, any sliding window, causal or not, bf16 or fp8-e4m3 cache, q at any row pitch.
|
||||
/* r4d_attn_paged_window.hip -- paged attention at head_dim 128, 256 and 512, 1/2/4/8 queries per
|
||||
* KV head, any sliding window, causal or not, bf16 or fp8-e4m3 cache, q at any row pitch.
|
||||
*
|
||||
* head_dim 128 is Unlimited-OCR's decoder (10 query heads over 10 KV heads): the plain MHA case,
|
||||
* served here so its q slice of the fused q|k|v plane is read in place (attn_paged_qrow) instead
|
||||
* of being lifted into a dense buffer.
|
||||
*
|
||||
* Gemma 4's text layers: sliding layers are 16 query heads over 8 KV heads at head_dim 256 with a
|
||||
* 1024-token window (gqa 2 at every TP); full layers are 16 over 2 at head_dim 512 (gqa 8 at
|
||||
@@ -61,7 +65,8 @@ constexpr int kMaxSplit = 64;
|
||||
|
||||
template <int HD> struct Geo;
|
||||
/* R query rows per workgroup (R / 8 per wave), BK keys per tile. BK * 2 * HD bf16 = 32 KiB of LDS
|
||||
* either way: two paged blocks at 256, one at 512. */
|
||||
* either way: two paged blocks at 256, one at 512, four at 128. */
|
||||
template <> struct Geo<128> { static constexpr int R = 32, BK = 32; };
|
||||
template <> struct Geo<256> { static constexpr int R = 32, BK = 32; };
|
||||
template <> struct Geo<512> { static constexpr int R = 16, BK = 16; };
|
||||
|
||||
@@ -1104,12 +1109,14 @@ extern "C" {
|
||||
int r4d_rad_attn_window_h##HD##_gqa##G##_fp8(const RadArgs* a, RadStream s) { \
|
||||
return r4d_win::launch_attn<HD, G, true>(a, s); \
|
||||
}
|
||||
R4D_WIN_DEF(128, 1)
|
||||
R4D_WIN_DEF(256, 1) R4D_WIN_DEF(256, 2) R4D_WIN_DEF(256, 4) R4D_WIN_DEF(256, 8)
|
||||
R4D_WIN_DEF(512, 1) R4D_WIN_DEF(512, 2) R4D_WIN_DEF(512, 4) R4D_WIN_DEF(512, 8)
|
||||
#undef R4D_WIN_DEF
|
||||
|
||||
/* Called at declare with no tensors. Partials are capped at kPartBudget (tile, head, split)
|
||||
* triples for any batch, so the size is a constant. */
|
||||
int64_t r4d_rad_attn_window_h128_scratch(const RadArgs*) { return r4d_win::scratch_need<128>(); }
|
||||
int64_t r4d_rad_attn_window_h256_scratch(const RadArgs*) { return r4d_win::scratch_need<256>(); }
|
||||
int64_t r4d_rad_attn_window_h512_scratch(const RadArgs*) { return r4d_win::scratch_need<512>(); }
|
||||
|
||||
|
||||
Reference in new issue
Block a user