unlimitedocr: the DeepEncoder tower, R-SWA ring KV and the n-gram ban

DeepEncoder (arch/common/rad_block_sam.h): the checkpoint's SAM ViT-B/16,
neck and CLIP ViT-L/14 producing its 16x17+1 row layout, with a new
`sam_attn` op for the windowed, zero-padded SAM attention and its
decomposed relative-position bias (libref oracle, libavx kernel, libr4d
kernel and selftest). The plugin declares the tower when the container
records `radiance.encoder`, and splices its rows over the placeholders
after embed_lookup.

BOS: the chat path adds BOS when the rendered template does not already
start with it. This checkpoint's template is a bare concatenation and its
tokenizer states add_bos_token, so without it every position was off by
one and the det boxes came out wrong. A media run's placeholders shift
with it.

R-SWA: RAD_KV_RING, paged like a window group but with a per-sequence
floor armed at admission. adv_groups now computes the same clamped
seqused and modulo ring slots the builder stages; the mismatch read the
block table's -1 padding and faulted the card. Prefill stays causal;
prefix cache, checkpoints and speculation are off for the group.

Sampling: sample_ngram_ban in libref/libavx/libr4d and the host chain,
the request knobs, and the container's generation config (35 over 128).

Processor: the checkpoint's grid/mode selection, its tall-last tie order,
Pillow's bicubic pass order, and goldens generated from its own code.

Tools: --mm-max-patches auto-detection accepts a tower stated as per-width
tables under vision_config.image_size, and rad-convert records
radiance.encoder.

Verified: tower stages match the checkpoint's code (rows cos 0.9998), the
device sam_attn selftest is within tolerance, the R-SWA device repro
returns text, a GPU e2e reproduces the reference's first det block, and
the host suite is 88/89 (known webp decode baseline).
This commit is contained in:
Juup committed 2026-10-20 07:04:01 +00:00
1 parent 543cba7416
commit fad4ba7f1a
63 files changed
+6162 -169

No files matched your search

+10
View File
@@ -517,11 +517,13 @@ static inline void h_sampler_rows(Prepared& pr, const Case& c) {
if (std::strncmp(c.op, "sample_", 7) != 0) return;
Opd* params = nullptr;
Opd* hist = nullptr;
Opd* ngram = nullptr;
for (size_t k = 0; k < pr.opd.size(); ++k) {
const char* nm = pr.schema->operands[k].name;
if (!nm || pr.opd[k].absent || pr.opd[k].d.rank != 2) continue;
if (!std::strcmp(nm, "params")) params = &pr.opd[k];
if (!std::strcmp(nm, "history") && pr.opd[k].d.dtype == RAD_I32) hist = &pr.opd[k];
if (!std::strcmp(nm, "ngram") && pr.opd[k].d.shape[1] == 2) ngram = &pr.opd[k];
}
const int64_t words = (int64_t)(sizeof(RadSampleParams) / 4);
if (!params || rad_dtype_bits(params->d.dtype) != 32 || params->d.shape[1] != words) return;
@@ -549,6 +551,14 @@ static inline void h_sampler_rows(Prepared& pr, const Case& c) {
sp.hist_off = 0;
sp.hist_len = (int32_t)hw;
sp.mask_row = r % 2 ? (int32_t)r : -1;
/* The n-gram ban's per-row pair: n 1 to 3 over windows short of the 64-token history, so
* the window boundary and the n == 1 form (an empty prefix) both run. Only the op whose
* schema has the `ngram` plane reads it. */
if (ngram) {
int32_t* v = (int32_t*)ngram->master.data();
v[2 * r] = 1 + (int32_t)(r % 3);
v[2 * r + 1] = 12 + 8 * (int32_t)(r % 4);
}
sp.flags = RAD_SP_PENALTY | RAD_SP_XTC | RAD_SP_DRY | RAD_SP_LOGPROBS |
(sp.mask_row >= 0 ? RAD_SP_MASK : 0);
if (r == M - 1 && M > 1) sp.flags = RAD_SP_GREEDY;