Archived
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).
55 lines
2.3 KiB
C++
55 lines
2.3 KiB
C++
/* item.cpp -- the parts of Item the step path uses. The batch builder links only this unit from
|
|
* core/mm, so a test that fakes the device layer does not pull in the processor and, through its
|
|
* metadata reader, the real device layer. */
|
|
#include "mm/processor.h"
|
|
|
|
namespace rad {
|
|
namespace mm {
|
|
|
|
void Item::coords(int64_t first, int64_t count, int32_t* planes) const {
|
|
/* An audio clip is 1-D (RadBatch::enc): frame index, whether the frame takes part in the
|
|
* convolution, the clip's real frame count and its staged frame count. A clip staged in
|
|
* chunks (AudioFamily::Qwen3ASR) reads each chunk's first `chunk_read` frames; the rest of the
|
|
* chunk is alignment the encoder reads as zero. */
|
|
if (kind == Kind::Audio) {
|
|
for (int64_t k = 0; k < count; ++k) {
|
|
const int64_t f = first + k;
|
|
planes[k] = (int32_t)f;
|
|
planes[count + k] = chunk_staged > 0 ? (f % chunk_staged < chunk_read ? 1 : 0)
|
|
: (f < valid ? 1 : 0);
|
|
planes[2 * count + k] = valid;
|
|
planes[3 * count + k] = grid_h;
|
|
}
|
|
return;
|
|
}
|
|
/* Merge-block order inverted: a patch's index within its segment is
|
|
* ((block_row * blocks_w + block_col) * merge + in_row) * merge + in_col. */
|
|
const int32_t merge = grid_h / rows_h;
|
|
int32_t s = 0;
|
|
while (s + 1 < n_seg && patch_at(s + 1) <= first) ++s;
|
|
for (int64_t k = 0; k < count; ++k) {
|
|
while (s + 1 < n_seg && patch_at(s + 1) <= first + k) ++s;
|
|
const int64_t within = first + k - patch_at(s);
|
|
const int64_t bw = seg_w(s) / merge;
|
|
int64_t row, col;
|
|
if (patch_raster) {
|
|
/* Raster order is its own inverse: patch i is row i / w, column i % w. */
|
|
row = within / seg_w(s);
|
|
col = within % seg_w(s);
|
|
} else {
|
|
const int64_t in_col = within % merge;
|
|
const int64_t in_row = (within / merge) % merge;
|
|
const int64_t blk = within / (merge * merge);
|
|
row = (blk / bw) * merge + in_row;
|
|
col = (blk % bw) * merge + in_col;
|
|
}
|
|
planes[k] = (int32_t)row;
|
|
planes[count + k] = (int32_t)col;
|
|
planes[2 * count + k] = seg_h(s);
|
|
planes[3 * count + k] = seg_w(s);
|
|
}
|
|
}
|
|
|
|
} /* namespace mm */
|
|
} /* namespace rad */
|