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
+8
-5
@@ -3610,11 +3610,12 @@ static const RadConstraint cAttnPrefillH64G4Bf16[] = {
|
||||
C_EQ("window", 0), C_EQ("head_dim", 64), C_EQ("gqa", 4), C_EQ("block_size", 16),
|
||||
C_EQ("causal", 1), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", "bf16"),
|
||||
};
|
||||
/* The windowed kernels (r4d_attn_paged_window.hip): head_dim 256 and 512, 1/2/4/8 queries per KV
|
||||
* head, any window, causal or not. Gemma 4's sliding layers are h256/gqa2 with a 1024-token
|
||||
* window, its full layers h512 at gqa 8 (TP1/TP2), 4 (TP4) or 2 (TP8). One kernel serves every
|
||||
* q_len (splitting the key range when there are too few tiles to fill the card), so `q_len` cuts
|
||||
* no band. `causal` and `window` are runtime fields; block_size is derived: 16.
|
||||
/* The windowed kernels (r4d_attn_paged_window.hip): head_dim 128, 256 and 512, 1/2/4/8 queries per
|
||||
* KV head, any window, causal or not. Gemma 4's sliding layers are h256/gqa2 with a 1024-token
|
||||
* window, its full layers h512 at gqa 8 (TP1/TP2), 4 (TP4) or 2 (TP8); h128/gqa1 is Unlimited-OCR's
|
||||
* MHA decoder. One kernel serves every q_len (splitting the key range when there are too few tiles
|
||||
* to fill the card), so `q_len` cuts no band. `causal` and `window` are runtime fields; block_size
|
||||
* is derived: 16.
|
||||
*
|
||||
* h256 at gqa 4 and 8 take a window only (C_GE 1), leaving the window-0 band to the gqa4 / gqa8
|
||||
* legs above. At h256/gqa2 these rows overlap the sliding leg's bands and rank below it
|
||||
@@ -3624,6 +3625,7 @@ static const RadConstraint cAttnPrefillH64G4Bf16[] = {
|
||||
C_EQ("head_dim", HD), C_EQ("gqa", G), C_EQ("block_size", 16), C_GE("causal", 0), \
|
||||
C_GE("window", WMIN), C_IN("q_dtype", "bf16"), C_IN("kv_dtype", KV), \
|
||||
};
|
||||
R4D_WIN_C(cWinH128G1Bf16, 128, 1, "bf16", 0) R4D_WIN_C(cWinH128G1Fp8, 128, 1, "fp8_e4m3", 0)
|
||||
R4D_WIN_C(cWinH256G1Bf16, 256, 1, "bf16", 0) R4D_WIN_C(cWinH256G1Fp8, 256, 1, "fp8_e4m3", 0)
|
||||
R4D_WIN_C(cWinH256G2Bf16, 256, 2, "bf16", 0) R4D_WIN_C(cWinH256G2Fp8, 256, 2, "fp8_e4m3", 0)
|
||||
R4D_WIN_C(cWinH256G4Bf16, 256, 4, "bf16", 1) R4D_WIN_C(cWinH256G4Fp8, 256, 4, "fp8_e4m3", 1)
|
||||
@@ -6027,6 +6029,7 @@ static const RadKernelInfo kKernels[] = {
|
||||
#define R4D_WIN_PAIR(HD, GQ) \
|
||||
R4D_WIN_ROW(HD, GQ, bf16kv, bf16, cWinH##HD##G##GQ##Bf16, "bf16") \
|
||||
R4D_WIN_ROW(HD, GQ, fp8kv, fp8, cWinH##HD##G##GQ##Fp8, "fp8-e4m3 (per-(seq,head) descales)")
|
||||
R4D_WIN_PAIR(128, 1)
|
||||
R4D_WIN_PAIR(256, 1) R4D_WIN_PAIR(256, 2) R4D_WIN_PAIR(256, 4) R4D_WIN_PAIR(256, 8)
|
||||
R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512, 8)
|
||||
#undef R4D_WIN_PAIR
|
||||
|
||||
Reference in new issue
Block a user