test(ref2va): device-input-anchored audio-encoder parity harness (#14 value-parity)

Unblocked by the on-box torch env. ref_aenc_parity.py loads the reference HF audio
VAE (fp32) under ComfyUI's --cpu branch (no GPU context — the TP2 server holds both
cards), and compares the device's b_enca normalised latent to the reference encode()
run on the device's OWN staged enc_samples buffer. Device-input-anchored => removes
every decode/normalise/pad confound; a kernel bug shows gross, a correct fp8 port
shows at/below the ~1.6e-3 convert quant floor. --selftest validates the reshape /
slot / metric logic without a device (perfect->0, temporal-misalign->0.24).

Driver side: extend the R4D_ENC_DEBUG scaffolding to raw-dump the staged enc_samples
(host buffer at stage time) and the b_enca / b_evc readback to R4D_ENC_DUMPDIR.
Inert unless R4D_ENC_DEBUG + R4D_ENC_DUMPDIR are both set; host tier green.
Reference model.py re-baked golden.json byte-identical (no reference drift).
This commit is contained in:
gearwave00001 committed 2026-10-19 15:56:35 -05:00
1 parent 7f4bc9c3a4
commit 393d5416b0
2 files changed
+192

No files matched your search

+20
View File
@@ -7,6 +7,7 @@
#include <chrono>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -1116,6 +1117,20 @@ const RadBatch* VideoDriver::build_chunk(Job& j, int step) {
return &out_[0];
}
/* Debug-only raw dump (R4D_ENC_DEBUG + R4D_ENC_DUMPDIR): write the encoder's input / output bytes to
* a file so tests/data/ref2va/ref_aenc_parity.py can compare the device's encode kernels against the
* reference HF encoder on the SAME input. Inert unless both environment variables are set — a normal
* run never enters here. Part of the R4D_ENC_DEBUG scaffolding, stripped at PR time. */
static void enc_dbg_dump_file(const std::string& tag, const void* p, size_t bytes) {
const char* dir = std::getenv("R4D_ENC_DUMPDIR");
if (!dir || !p || bytes == 0) return;
const std::string path = std::string(dir) + "/" + tag + ".f32";
if (std::FILE* f = std::fopen(path.c_str(), "wb")) {
std::fwrite(p, 1, bytes, f);
std::fclose(f);
}
}
/* One media item through its VAE encoder: stage its encoder-ready bytes and the encode geometry
* the plugin's rad_arch_encode_geom derives from them, then name the pass's kind and slot so the
* encoder folds the latents into the lane's fixed slot rows. The server sends the NATURAL decoded
@@ -1159,6 +1174,9 @@ const RadBatch* VideoDriver::build_encode(Job& j, int step) {
std::memcpy(sm + (size_t)c * stage_samples, m.enc_samples.data() + (size_t)c * n,
(size_t)n * 4);
reg_[R_ENCSM].used = stage_samples * ch * 4;
if (enc_dbg_)
enc_dbg_dump_file("encsm_" + std::to_string((int)it.kind) + "_" +
std::to_string((int)it.slot), sm, (size_t)stage_samples * ch * 4);
} else {
const int64_t nf = m.enc_frames, H = m.enc_h, W = m.enc_w;
if (nf <= 0 || H <= 0 || W <= 0)
@@ -1248,6 +1266,8 @@ int VideoDriver::done() {
pass_.kind == RAD_GEN_PASS_AENCODE ? "AENCA(b_enca)" : "VENCV(b_evc)",
(int)enc_dbg_used_, (unsigned long long)h, (long long)nf, (long long)nz,
(double)mx, sum, (double)z[0], (double)z[1], (double)z[2], (double)z[3]);
enc_dbg_dump_file(pass_.kind == RAD_GEN_PASS_AENCODE ? "enca" : "evc",
enc_dbg_host_, (size_t)enc_dbg_used_);
}
++j->enc_next;
break;