PIN ref2va: verified device differential + ref-count gate (revert anchor)

Ref2VA ref-image conditioning verified on-device: ref step runs all steps no
fault; output differs ref-present vs ref-absent (by log). 6-9 images rejected
cleanly at submit (no engine crash). Merged-cell modulation (<=9) tracked next.
NOTE: placeholder author -- re-author before any push. Do NOT push this branch.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gearwave00001andClaude committed 2026-10-19 12:04:47 -05:00
1 parent 816e24bd46
commit 490d4c604a
73 files changed
+16484 -432

No files matched your search

+98
View File
@@ -2266,6 +2266,84 @@ void upscaler_cases(std::vector<Hand>& hs) {
.pi("M", R).pi("cin", ci).pi("cout", co).pi("k", 2).pi("kt", 3).ps("dtype", dn)
.refuses(RAD_E_SHAPE);
hs.push_back(std::move(e));
/* The video encoder's CausalConv3d forms: the cube's geoms never stride, never
* mirror and never pad one side, so the downsample, a mirror-everywhere res block
* and the one-frame case are built by hand. */
{
/* (3 + 2 - 3) / 2 + 1 = 2 frames, (4 + 1 - 3) / 2 + 1 = 2 rows, (5 + 1 - 3) / 2
* + 1 = 2 columns: the bottom/right-only pad and both stride axes, with the
* frame drop and a column of reflected taps. */
Hand h(("3 x 4 x 5 causal, stride 2 down reflect" + sfx).c_str(),
"conv3d_ndhwc", tol);
h.dense(dt, { 3 * 4 * 5, ci }, hfill(960))
.dense(dt, { co, ci, 3, 3, 3 }, hfill(961, 0.3f))
.dense(dt, { co }, hfill(962, 0.5f))
.idx({ 3, 4, 5 })
.none()
.dense(dt, { 8, co }, hfill(963), true)
.pi("M", 8).pi("cin", ci).pi("cout", co).pi("k", 3).pi("kt", 3).ps("dtype", dn)
.pi("stride", 2).pi("stride_t", 2).pi("causal", 1).ps("pad", "down")
.pi("reflect", 1);
hs.push_back(std::move(h));
Hand g(("2 x 2 x 3 causal reflect, a mirror on every edge" + sfx).c_str(),
"conv3d_ndhwc", tol);
g.dense(dt, { 12, ci }, hfill(964))
.dense(dt, { co, ci, 3, 3, 3 }, hfill(965, 0.3f))
.dense(dt, { co }, hfill(966, 0.5f))
.idx({ 2, 2, 3 })
.none()
.dense(dt, { 12, co }, hfill(967), true)
.pi("M", 12).pi("cin", ci).pi("cout", co).pi("k", 3).pi("kt", 3).ps("dtype", dn)
.pi("causal", 1).pi("reflect", 1);
hs.push_back(std::move(g));
/* One frame in, one out: the causal pad's front zeros are the reference's tap
* truncation; the residual is the output itself. */
Hand q(("one frame, causal reflect, residual in place" + sfx).c_str(),
"conv3d_ndhwc", tol);
q.dense(dt, { 4, ci }, hfill(968))
.dense(dt, { co, ci, 3, 3, 3 }, hfill(969, 0.3f))
.dense(dt, { co }, hfill(970, 0.5f))
.idx({ 1, 2, 2 })
.dense(dt, { 4, co }, hfill(971), true)
.alias(4)
.pi("M", 4).pi("cin", ci).pi("cout", co).pi("k", 3).pi("kt", 3).ps("dtype", dn)
.pi("causal", 1).pi("reflect", 1);
hs.push_back(std::move(q));
/* The refusals, held to libref's error codes: a 5-wide kernel with a stride, a
* pad that is neither `same` nor `down`, a reflect whose one-px pad reaches an
* axis of 1, y short of the strided output and a zero stride. */
const auto refusal = [&](const char* what, const std::vector<int64_t>& g3,
int k, const char* pad, int stride, int causal,
int reflect, int64_t yrows) {
Hand z((std::string(what) + sfx).c_str(), "conv3d_ndhwc", tol);
z.dense(dt, { 12, ci }, hfill(972))
.dense(dt, { co, ci, (uint32_t)k, (uint32_t)k, (uint32_t)k }, hfill(973))
.dense(dt, { co }, hfill(974))
.idx(g3)
.none()
.dense(dt, { yrows, co }, zero, true)
.pi("M", yrows).pi("cin", ci).pi("cout", co).pi("k", k).pi("kt", k)
.ps("dtype", dn);
if (stride != 1) z.pi("stride", stride);
if (pad && *pad) z.ps("pad", pad);
if (causal) z.pi("causal", causal);
if (reflect) z.pi("reflect", reflect);
z.refuses(RAD_E_SHAPE);
hs.push_back(std::move(z));
};
refusal("a stride with a 5-wide kernel is refused", { 2, 2, 3 }, 5, nullptr, 2, 0,
0, 12);
refusal("a reflect pad reaching an axis of 1 is refused", { 2, 1, 2 }, 3, nullptr,
1, 1, 1, 4);
refusal("a mirror pad is refused", { 2, 2, 3 }, 3, "mirror", 1, 0, 0, 12);
refusal("y short of the strided output is refused", { 3, 4, 5 }, 3, "down", 2, 1,
1, 7);
refusal("a zero stride is refused", { 2, 2, 3 }, 3, nullptr, 0, 0, 0, 12);
}
}
/* ---- group_norm: stats f32 of exactly groups (2 + 3 1024) values --------------------- */
@@ -3782,6 +3860,26 @@ void audio_cases(std::vector<Hand>& hs) {
.pi("causal", 1).ps("dtype", dn);
hs.push_back(std::move(h));
}
if (dt == (uint32_t)RAD_BF16) {
/* The strided downsample (an encoder's), bf16 only: one sequence, kernel 2 stride,
* pad stride / 2, so 16 input rows give exactly 16 / stride output rows. */
const int64_t cin = 20, cout = 13;
for (const int64_t s : { 2, 4 }) {
const int64_t k = 2 * s, in = 16, out = in / s;
Hand h(("stride " + std::to_string(s) + ", even kernel, one sequence" + sfx)
.c_str(),
"conv1d", norm_tol);
h.dense(dt, { in, cin }, hfill(350 + s))
.dense(dt, { cout, cin, k }, hfill(356, 0.3f))
.idx({ 0, in })
.none()
.dense(dt, { out, cout }, zero, true)
.dense(dt, { cout }, hfill(357, 0.5f))
.pi("M", in).pi("cin", cin).pi("cout", cout).pi("k", k).pi("dil", 1)
.pi("stride", s).pi("pad", s / 2).ps("dtype", dn);
hs.push_back(std::move(h));
}
}
for (const int64_t s : { 5, 3 }) {
/* A codec's odd strides at kernel 2 stride, causal, over sequences of 3, 1 and 5 rows
* from row 1. */