Archived
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:
1 parent
1f661bf2e0
commit
859efc7208
35 files changed
+799
-399093
No files matched your search
@@ -386,8 +386,8 @@ int ref_act_mul(const RadArgs* a, RadStream) {
|
||||
if (n <= 0) return RAD_E_SHAPE;
|
||||
const int64_t rows = rows_of(Y, n);
|
||||
if (rows <= 0 || numel(A) < rows * n || numel(B) < rows * n) return RAD_E_SHAPE;
|
||||
static const char* kActs[] = { "silu", "gelu", "gelu_tanh", "sigmoid" };
|
||||
const int act = p_enum(a, "act", kActs, 4, -1);
|
||||
static const char* kActs[] = { "silu", "gelu", "gelu_tanh", "sigmoid", "quick_gelu" };
|
||||
const int act = p_enum(a, "act", kActs, 5, -1);
|
||||
if (act < 0) return RAD_E_INVAL;
|
||||
|
||||
REF_PAR_FOR(rows * n)
|
||||
@@ -396,8 +396,13 @@ int ref_act_mul(const RadArgs* a, RadStream) {
|
||||
const int64_t as = laststride(A), bs = laststride(B), ys = laststride(Y);
|
||||
for (int64_t i = 0; i < n; ++i) {
|
||||
const float g = ldt(A, ab + i * as);
|
||||
/* quick_gelu is x * sigmoid(1.702 x) with the scaled value rounded to y's dtype
|
||||
* first, exactly the unfused mul-then-act_mul pair this replaces. */
|
||||
const float v = act == 0 ? act_silu(g) : act == 1 ? act_gelu(g)
|
||||
: act == 2 ? act_gelu_tanh(g) : act_sigmoid(g);
|
||||
: act == 2 ? act_gelu_tanh(g)
|
||||
: act == 3 ? act_sigmoid(g)
|
||||
: act_sigmoid(round_dt(Y->dtype,
|
||||
g * round_dt(RAD_BF16, 1.702f)));
|
||||
stt(Y, yb + i * ys, round_dt(Y->dtype, v) * ldt(B, bb + i * bs));
|
||||
}
|
||||
}
|
||||
@@ -625,9 +630,7 @@ int ref_conv2d_unfold(const RadArgs* a, RadStream) {
|
||||
if (T <= 0) continue;
|
||||
const int64_t To = (T + 2 * pad - kh) / st + 1, o0 = t0 / st;
|
||||
if (To <= 0) continue;
|
||||
if (t0 + T > Min || (o0 + To) * Wo > Mout) {
|
||||
return RAD_E_SHAPE;
|
||||
}
|
||||
if (t0 + T > Min || (o0 + To) * Wo > Mout) return RAD_E_SHAPE;
|
||||
if (V && numel(V) < (t0 + T - 1) * vst + 1) return RAD_E_SHAPE;
|
||||
|
||||
REF_PAR_FOR(To * Wo * K)
|
||||
|
||||
Reference in new issue
Block a user