review: apply the Unlimited-OCR code-review findings

The 2a1ca01..f308216 range's 45 review findings (12 performance, 33 quality)
are applied: ABI 23 for the RadBatch append, the fused q|k|v projection, the
batched patch-embed GEMM and pitched layout copies, the sam_attn w-dot hoist
with an alignment-gated vector row path and NaN poisoning for malformed
segments, the fused quick_gelu act, and the R-SWA/scheduler/drafting gates.

Quality items: stale comments corrected, env reads hoisted, the ngram_window
negative refusal, the parts-form chat template instruction, the whitelist
fallback warning, and the segmented R-SWA refusal of the fixed/runtime window
mix.

The 3.2 MB generated resample header becomes a 9.6 MB little-endian blob
(tests/data/golden/uocr_resample_golden.bin) read by a small loader;
resample_golden.py emits and round-trip-verifies it.

One perf-med item (AVX2 bicubic passes/LUT patch staging in the processor) is
left as the follow-up the review itself recommends; the code says why.

Verified: ninja -C build-review -k 0; host ctest 89/89; GPU r4d_selftest
0 failures, kbench/kbench_moe and the card tests pass.
This commit is contained in:
Juup committed 2026-10-20 07:06:18 +00:00
1 parent 1f661bf2e0
commit 859efc7208
35 files changed
+799 -399093

No files matched your search

+8 -3
View File
@@ -943,10 +943,11 @@ int Sampler::build_greedy(int64_t n) {
cur_stage_ = greedy_stage_;
/* A drafter's rows run the argmax only, so the n-gram plane is cleared: `run` reads it from
* the staging, and a stale pair from an earlier request's build must not issue the ban over
* history that was not staged this step. The exemption plane goes with it: cleared for the
* rows `run` would upload, so no build that does issue the ban reads a stale exemption. */
* history that was not staged this step. The exemption plane needs no clear: `run` uploads
* it only beside an issued ban, every row that runs the ban has its words rewritten in full
* by the build that staged the pair (build_step), and rows below a zeroed pair are skipped
* by the op before they read a word. */
std::memset(ngram_stage_, 0, (size_t)cap * 2 * sizeof(int32_t));
std::memset(ngram_wl_stage_, 0, (size_t)n * mask_words_ * 4);
if (greedy_ready_) return RAD_OK;
for (int64_t i = 0; i < cap; ++i) {
DeviceSampleParams& p = greedy_stage_[i];
@@ -977,6 +978,10 @@ int Sampler::run(RadCtx* c, rad_buf logits, rad_buf out_tokens) {
any_penalty |= (p.flags & RAD_SP_PENALTY) != 0;
any_dry |= (p.flags & RAD_SP_DRY) != 0;
any_xtc |= (p.flags & RAD_SP_XTC) != 0;
/* The pair plane is read directly, not through cur_stage_: it is per-step staging the
* LAST builder filled (build_step writes a row's pair, build_greedy zeroes every pair),
* so it agrees with cur_stage_ by builder contract. A new builder must keep that
* contract: stage the pair with the params, zero it with the greedy ones. */
any_ngram |= ngram_stage_[2 * i] > 0;
if (p.flags & RAD_SP_GREEDY) any_greedy = true;
else {