This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/core/runtime/kvbind.cpp
T
Juup fad4ba7f1a 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).
2026-10-20 07:04:01 +00:00

63 lines
2.3 KiB
C++

/* kvbind.cpp -- see kvbind.h. */
#include "kvbind.h"
#include "mem/kv.h"
namespace rad {
void bind_kv_pools(const Program& p, const std::function<const KVGroupPlan*(int32_t)>& plan_of,
std::vector<KVPoolBinding>* out) {
out->assign(p.kv_groups.size(), KVPoolBinding{});
for (size_t g = 0; g < p.kv_groups.size(); ++g) {
const KVGroupPlan* gp = plan_of((int32_t)g);
if (!gp) continue;
KVPoolBinding& b = (*out)[g];
b.base = gp->base;
b.layer_stride = gp->layer_stride();
b.bytes = gp->pool_bytes;
b.dtype = p.kv_groups[g].decl.dtype;
/* The position of every bound layer, indexed by its absolute number. */
const std::vector<int32_t>& ls = p.kv_groups[g].layers;
int32_t hi = -1;
for (int32_t l : ls) if (l > hi) hi = l;
b.layer_slot.assign((size_t)(hi + 1), -1);
for (size_t i = 0; i < ls.size(); ++i) b.layer_slot[(size_t)ls[i]] = (int32_t)i;
/* One layer's cache shape, in the layout libref/ref_ops.h defines. Built here because only
* this point has both the plugin's declaration (heads, head_dim, state_dim, conv_width)
* and the block manager's decisions (block_size, n_blocks, n_states, conv_slots); a
* kernel cannot derive the conv depth or slot count from op parameters. */
const RadKVGroupDecl& d = p.kv_groups[g].decl;
switch (gp->kind) {
case RAD_KV_FULL:
case RAD_KV_WINDOW:
case RAD_KV_RING:
b.rank = 4;
b.shape[0] = gp->n_blocks;
b.shape[1] = d.n_head_kv;
b.shape[2] = gp->block_size;
b.shape[3] = 2 * d.head_dim;
break;
case RAD_KV_LINEAR:
b.rank = 4;
b.shape[0] = gp->n_states;
b.shape[1] = d.n_head_kv;
b.shape[2] = d.state_dim[0];
b.shape[3] = d.state_dim[1];
break;
case RAD_KV_CONV:
b.rank = 3;
b.shape[0] = gp->n_states;
b.shape[1] = d.n_head_kv * d.head_dim;
b.shape[2] = gp->conv_slots;
break;
default:
b.rank = 0; /* the null sentinel at handle 0; nothing issues against it */
break;
}
}
}
} /* namespace rad */