Archived
arch: audio pre_block feeds each branch the reference's norm (#14)
The reference AttnProjection (comfy/ldm/minimax/audio_vae.py:267) computes proj(norm3(x)) + attn(norm1(x)), then + mlp(norm2(·)). The two 2048-wide LayerNorms are not interchangeable: norm3's affine |w|mean is 0.60, norm1's 0.27, so the projection branch carries most of the block's magnitude (std 6.6 via norm3 vs 0.4 for the attention via norm1). The device had them wired the other way -- it staged norm1 into the projection and norm3 into the attention (qkv). Feeding the small-affine norm1 to the projection shrank it 6.6 -> 1.8, collapsing the pre_block output and every audio latent downstream to ~0.25-0.27x the reference. Fix: stage norm1 for the attention (feeding p_op_qkv) and norm3 for the projection (feeding p_op_proj). Both LN ops are the same ln(...,2048,b_apb-> b_aln3) kernel, so only the consumer wiring changed -- no kernel touched, no re-convert (norm1.*/norm3.* weights are already loaded correctly). Also adds a gated read-only R4D_ENC_SEL=amb readback (dbg_ae_amb = b_amb, the f32 mean_proj input): the bf16 b_ax2 readback lags the arena and dumps garbage, so b_amb is the reliable pre_block output used to localise the gap. Inert when R4D_ENC_SEL is unset. Device-verified (seed=7 tone, minimax-h3-ref2va-fp8, warm TP2): pre_block out b_amb std 1.65 -> 6.43 (ratio 0.25 -> 0.97); final latent b_enca std 0.23 -> 0.546 vs reference 0.588 (ratio 0.39 -> 0.93), affine slope 0.385 -> 0.923, R^2 0.975 -> 0.989. Host tier green (abi_layout/arch/ref/videos). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
0bfde46414
commit
39602c1c7b
6 files changed
+178
-11
No files matched your search
@@ -1229,8 +1229,25 @@ const RadBatch* VideoDriver::build_encode(Job& j, int step) {
|
||||
pass_.kind = kind;
|
||||
pass_.job = j.id;
|
||||
if (enc_dbg_) {
|
||||
const rad_buf h = audio ? decl_.dbg_enca : decl_.dbg_evc;
|
||||
const int64_t n = audio ? decl_.dbg_enca_bytes : decl_.dbg_evc_bytes;
|
||||
/* R4D_ENC_SEL picks which audio-pass buffer the readback names, so one binary can dump the
|
||||
* whole final chain without a rebuild: "enca" (default, the normalised latent), "mp" (the
|
||||
* mean_proj output, i.e. the latent before the fixed (z-mean)/std norm), "amb" (the mean_proj
|
||||
* INPUT -- the pre_block output cast to f32), or "pre" (the raw bf16 pre_block buffer b_ax2).
|
||||
* The split localises a latent-scale gap: if the gain is already present at "mp"/"amb", the
|
||||
* norm op is innocent and the body carries it. "amb" is the RELIABLE f32 twin of "pre": the
|
||||
* bf16 b_ax2 is arena-rotated scratch whose readback can lag the pass (b_amb2 is finite while
|
||||
* b_ax2 dumps ±1e38 -- a stale read), so the f32 b_amb is what to trust for the pre_block
|
||||
* value. The video pass and the default audio pass are untouched; only an env var selects. */
|
||||
const char* sel = audio ? std::getenv("R4D_ENC_SEL") : nullptr;
|
||||
const bool mp = sel && std::strcmp(sel, "mp") == 0 && decl_.dbg_ae_mp_bytes > 0;
|
||||
const bool amb = sel && std::strcmp(sel, "amb") == 0 && decl_.dbg_ae_amb_bytes > 0;
|
||||
const bool pre = sel && std::strcmp(sel, "pre") == 0 && decl_.dbg_ae_pre_bytes > 0;
|
||||
const rad_buf h = mp ? decl_.dbg_ae_mp : amb ? decl_.dbg_ae_amb : pre ? decl_.dbg_ae_pre
|
||||
: audio ? decl_.dbg_enca : decl_.dbg_evc;
|
||||
const int64_t n = mp ? decl_.dbg_ae_mp_bytes : amb ? decl_.dbg_ae_amb_bytes
|
||||
: pre ? decl_.dbg_ae_pre_bytes
|
||||
: audio ? decl_.dbg_enca_bytes : decl_.dbg_evc_bytes;
|
||||
enc_dbg_sel_ = mp ? "mp" : amb ? "amb" : pre ? "pre" : "";
|
||||
enc_dbg_used_ = 0;
|
||||
if (h && n > 0) {
|
||||
rb_.assign(1, Readback{h, n, enc_dbg_host_});
|
||||
@@ -1267,13 +1284,14 @@ int VideoDriver::done() {
|
||||
if (a > mx) mx = a;
|
||||
sum += z[i];
|
||||
}
|
||||
RAD_ERR("enc_dbg %s slot %d: fnv %016llx floats %lld nonzero %lld maxabs %.6g "
|
||||
std::string tagstr = pass_.kind != RAD_GEN_PASS_AENCODE ? "evc"
|
||||
: *enc_dbg_sel_ ? std::string("enc") + enc_dbg_sel_ : std::string("enca");
|
||||
const char* tag = tagstr.c_str();
|
||||
RAD_ERR("enc_dbg %s: fnv %016llx floats %lld nonzero %lld maxabs %.6g "
|
||||
"sum %.6g head[%.6g %.6g %.6g %.6g]",
|
||||
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,
|
||||
tag, (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_);
|
||||
enc_dbg_dump_file(tag, enc_dbg_host_, (size_t)enc_dbg_used_);
|
||||
}
|
||||
++j->enc_next;
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user