test(ref2va): correct aenc parity device slice + record measured audio-encoder divergence (#14)

The device stores a slot's stereo latent channel-major with per-channel row
stride MAXA=625 (ch1 at base+625), not contiguous after ch0; the harness sliced
contiguous rows and thus compared reference-ch1 against device zeros. Fix the
slice to vstack the two channel blocks. With the correct slice the audio encoder
measures relative Frobenius 0.79 / corr 0.67 / device std 0.23 vs ref 0.59 — a
real encoder-network divergence, not fp8 precision (unbiased, floor ~1.6e-3),
not preprocessing (device-input-anchored), not the reference export (97 shared
encoder tensors bit-identical to the HF source), not the norm constants
(identical). Recorded honestly in NOTE-REF2VA: measured on audio; video/image
VAE is a separate kernel family, not yet measured; functional conditioning is
unaffected; kernels deliberately not blind-fixed.
This commit is contained in:
gearwave00001 committed 2026-10-19 16:10:03 -05:00
1 parent 393d5416b0
commit 04daf51e42
2 files changed
+29 -13

No files matched your search

+24 -11
View File
@@ -190,17 +190,30 @@ as point 6 / point 4. Nothing here claims to match ComfyUI's timings.
and read exactly the slot region the encode pass wrote this job — no stale-neighbor read.
What remains is **strict numeric value-parity** of the encoder latents against the reference HF
encoder (a per-tensor golden), not *whether* the encoders are live. **This is now actionable, not
environment-blocked**: a `torch` environment is present on the box (`comfyui-rocm10-venv`,
torch 2.13.0+rocm; it also re-bakes the pack `golden.json`, whose keyframe cases came out
byte-identical). The genuine reference sources are present (`MiniMax-H3-ref2va-src`, `MiniMax-H3/vae`,
`MiniMax-H3/audio_vae`), so a per-tensor encoder value golden *can* be produced here — it simply has
not been yet. The crux is matching preprocessing bit-for-bit (decode / resize / normalization /
frame-sampling), not the encoder weights, which the convert log already showed are real. The discipline
stands: content-control + determinism + a bit-exact pack is the strongest *parity* evidence produced so
far, and the per-tensor value match is left open rather than asserted, so a change is never made merely
to make latents *differ* when they could be made *wrong*. A clean parity number, once produced, should
start from the audio encoder (no spatial preprocessing to confound it) before the video VAE.
encoder (a per-tensor golden), not *whether* the encoders are live. **This has now been measured on
the audio path.** A device-input-anchored check — feed the reference HF audio VAE (fp32) the device's
*own* staged `enc_samples`, then compare its latent to the device's `b_enca`; the reference and the
container use byte-identical encoder weights and `latents_mean/std`, verified, so only the kernels
can differ — gives a **relative Frobenius error ~0.79, correlation 0.67**, with the device latent's
std ~2.5× smaller than the reference's (0.23 vs 0.59). That is far beyond the fp8 floor: fp8
quantisation is unbiased (it neither collapses std nor anti-correlates channels) and the convert log's
own audio-quant error is ~1.6e-3. The causes are individually **ruled out** — precision (fp8 would
keep corr ~0.99), preprocessing (device-input-anchored), reference export (the 97 shared encoder
tensors are bit-identical to the HF source, and the `latents_mean/std` match to the last digit), and
normalisation constants (identical). Per-channel shape error stays ~0.77 even after removing scale and
a few channels are negatively correlated, so the gap is in the network *transform* (strided conv1d /
per-frame GroupNorm / the `AttnProjection` head), not a single scale. Localising it fully needs
stage-by-stage activation dumps of the device encoder against the reference module-by-module —
substantial work on kernels the live image / video paths also share, and deliberately **not**
blind-fixed. The audio result is measured; the **video / image VAE encoders are a separate kernel
family** (`conv3d_ndhwc`) and have not yet been measured this way. Functional conditioning is
unaffected — the DiT is internally consistent with the latents it is fed — but *numerical* fidelity to
the reference encoder is not achieved on the audio path, so audio-reference output is not guaranteed to
match ComfyUI latent-for-latent. Reproduce: dump with `R4D_ENC_DEBUG=1 R4D_ENC_DUMPDIR=<dir>` over one
`ref_audio` request, then `ref_aenc_parity.py --enca enca.f32 --encsm encsm_4_1.f32 --kind audio
--slot 1` (its `--selftest` validates the reshape / slot / metric logic with no device). The audio
encoder is the cleanest first measurement because it has no spatial preprocessing to confound it; the
video VAE remains the harder, still-unmeasured half.
What still differs from the DaSiWa reference (hence not pixel-for-pixel reproducible):
- **The text encoder only *names* a moving picture; it never sees its pixels.** DaSiWa also shows
+5 -2
View File
@@ -55,6 +55,7 @@ AUDIO_C = 32
AUDIO_CH = 2
ENC_MAX_SAMPLES = 500000
SLOT_ROWS_A = AUDIO_CH * (ENC_MAX_SAMPLES // AUDIO_HOP) # 1250
MAXA = SLOT_ROWS_A // AUDIO_CH # per-channel row stride within a slot (625)
VAE_SAFETENSORS = os.path.join(
os.environ.get("COMFYUI_HOME", "/home/dustin/AI/ComfyUI"),
"models/vae/minimax_h3_audio_vae_fp32.safetensors")
@@ -74,7 +75,7 @@ def ref_latent(model, staged, ch, T):
z = model.encode(wave) # [1, 32, ch, T']
assert z.shape[1] == AUDIO_C and z.shape[2] == ch, tuple(z.shape)
zp = z[0].permute(1, 2, 0) # [ch, T', 32]
out = zp.reshape(ch * z.shape[3], AUDIO_C) # channel-major rows
out = zp.reshape(ch * z.shape[3], AUDIO_C) # channel-major rows (contiguous)
return out[:ch * T].numpy() # used rows only
@@ -107,7 +108,9 @@ def do_parity(m, enca_f, encsm_f, kind, slot, n):
ref = ref_latent(m, staged, ch, T) # [ch*T, 32]
enca = np.fromfile(enca_f, dtype=np.float32).reshape(-1, AUDIO_C)
base = slot_row(kind, slot)
dev = enca[base:base + ch * T] # device normalised latent
# Device layout: within a slot, channel c occupies rows [c*MAXA, c*MAXA+T). Stack them back to
# the reference's contiguous channel-major [ch*T, 32] so the two sides align row for row.
dev = np.vstack([enca[base:base + T], enca[base + MAXA:base + MAXA + T]])
if dev.shape != ref.shape:
sys.exit(f"device slice {dev.shape} vs reference {ref.shape}; check --kind/--slot/--n")
rf, mx = rel_frobenius(dev, ref)