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

+6 -3
View File
@@ -87,6 +87,7 @@ const char* bld_kv_kind_name(int k) {
case RAD_KV_WINDOW: return "window";
case RAD_KV_LINEAR: return "linear";
case RAD_KV_CONV: return "conv";
case RAD_KV_RING: return "ring";
default: return "?";
}
}
@@ -336,7 +337,7 @@ rad_buf Builder::decl_buffer(const char* name, const RadBufDecl* d) {
rad_kvgroup Builder::decl_kv_group(const char* name, const RadKVGroupDecl* d) {
if (finished_) return err(RAD_E_STATE, "decl_kv_group('%s') after declare finished", name ? name : "");
if (!name || !*name || !d) return err(RAD_E_INVAL, "decl_kv_group: null name or declaration");
if (d->kind < RAD_KV_FULL || d->kind > RAD_KV_CONV)
if (d->kind < RAD_KV_FULL || d->kind > RAD_KV_RING)
return err(RAD_E_INVAL, "kv group '%s': unknown kind %d", name, d->kind);
std::string n = scoped(name);
@@ -923,7 +924,7 @@ int Builder::kv_group_zero(rad_kvgroup h) {
* state is saved and cleared on every rank, so a zero-sized one would mismatch those
* copies. */
const int kind = prog_.kv_groups[h].decl.kind;
if (kind != RAD_KV_FULL && kind != RAD_KV_WINDOW) {
if (kind != RAD_KV_FULL && kind != RAD_KV_WINDOW && kind != RAD_KV_RING) {
err(RAD_E_INVAL, "kv group '%s': kv_group_zero on a group that is not paged",
prog_.kv_groups[h].name.c_str());
return RAD_E_INVAL;
@@ -1964,7 +1965,8 @@ void Builder::finish_kv_groups() {
KVGroupInfo& gi = prog_.kv_groups[g];
const RadKVGroupDecl& d = gi.decl;
if ((d.kind == RAD_KV_FULL || d.kind == RAD_KV_WINDOW) && gi.block_size == 0) {
if ((d.kind == RAD_KV_FULL || d.kind == RAD_KV_WINDOW || d.kind == RAD_KV_RING) &&
gi.block_size == 0) {
/* The plugin may never have asked; the manifest still needs the answer. */
kv_block_size((rad_kvgroup)g);
}
@@ -1977,6 +1979,7 @@ void Builder::finish_kv_groups() {
switch (d.kind) {
case RAD_KV_FULL:
case RAD_KV_WINDOW:
case RAD_KV_RING:
/* One block holds K and V for block_size tokens, the block manager's unit. */
gi.bytes_per_block =
rad_dtype_bytes(d.dtype, 2 * gi.block_size * elem_n_head * d.head_dim) * n_bound;