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

+10 -3
View File
@@ -42,6 +42,10 @@ SamplingParams GenSampling::onto(SamplingParams base) const {
return base;
}
/* The one-line statement of a served sampling configuration. The wording is pinned by
* gen_config_test.cpp (gen_config_reads_the_ngram_ban) -- change it there in the same change.
* It spells the values out for a log reader; `onto` fills the fields from defaults. The two
* share values, not logic, and the duplication of the ban clause is a string, not a rule. */
std::string GenSampling::describe(const SamplingParams& sp) {
char buf[320];
std::snprintf(buf, sizeof buf, "temperature %.2f, top_k %d%s, top_p %.2f, min_p %.2f",
@@ -132,11 +136,14 @@ bool gen_sampling_parse(const std::string& json_text, const char* src, GenSampli
* Values are warned about and dropped, like every other field here: an id is a vocabulary
* coordinate, so a negative one is not a value at all. */
it = j.find("no_repeat_ngram_whitelist");
if (it == j.end() || !it->is_array()) {
if (it != j.end())
if (it != j.end() && !it->is_array()) {
/* The legacy key is only a problem when nothing rescues it: a config that states a bad
* reference name beside a good sampler-spelled one reads the good one, silently. */
const auto own = j.find("ngram_whitelist");
if (own == j.end() || !own->is_array())
RAD_WARN("%s states a no_repeat_ngram_whitelist that is not an array; ignoring it",
src);
it = j.find("ngram_whitelist");
it = own;
}
if (it != j.end() && it->is_array()) {
for (const auto& v : *it) {