Archived
test(ref2va): decompose the encoder parity gap = near-pure ~0.37x under-gain (#14)
Fit a single global affine dev_sorted ~ a*ref_sorted + b to both encoders' value
distributions (both harnesses now print it):
audio (conv1d): a=0.385 b=+0.009 R^2=0.975 relFro 0.79 -> 0.062 after affine
video (conv3d): a=0.369 b=+0.159 R^2=0.912 relFro 0.65 -> 0.114 after affine
Two entirely different encoder networks both reduce to ~0.37x the reference with
R^2 0.91-0.98 -- near-perfect linearity. This overrules the earlier "not a single
scale" and "suspect the strided conv1d temporal reduction" readings: a conv-reduction
or structural transform bug would not collapse to a clean global scale. The device
encoders compute the right SHAPE of latent, damped to ~0.37x amplitude. The scale is
~0.37 for both but not bit-identical (0.385 vs 0.369) => not one shared post-multiply,
but a fixed per-level attenuation compounding over each arch's own depth.
The DiT generates correctly on the same fp8 path and the same normal kernels, so this
is not a global kernel/quant fault -- the under-gain is confined to the encoder pass.
Prime suspect: the encoders' per-level / per-frame GroupNorm (the per-frame CS in
{8,4} template) applying a near-constant sub-unit gain that compounds level-over-level,
or an encoder-path dequant scale mismatch the convert round-trip does not see. If it is
a fixed encoder-norm gain, a fix is confined to the encoder path and never touches the
DiT's norms -- which is why this is worth localising rather than shipping. Not
blind-fixed (encoder kernels are shared with the live image/plain encode paths).
Confirming step is cheap and read-only: dump one encoder block's GroupNorm input AND
output on-device, check whether output std is a fixed fraction of the reference GN.
docs/NOTE-REF2VA.md point 4 corrected (the superseded "not a single scale" clause) and
the affine table + encoder-specific-under-gain hypothesis recorded.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
241629fe8c
commit
04440dd3a9
3 files changed
+60
-3
No files matched your search
@@ -119,6 +119,16 @@ def do_parity(m, enca_f, encsm_f, kind, slot, n):
|
||||
print(f" max abs deviation = {mx:.3e}")
|
||||
print(f" reference latent |mean|={ref.mean():.4f} std={ref.std():.4f}; "
|
||||
f"device |mean|={dev.mean():.4f} std={dev.std():.4f}")
|
||||
# Decompose the gap (see ref_venc_parity.py for the rationale): a single global scale+bias that fits the
|
||||
# two sorted distributions well means the divergence is mostly ONE network-level gain, not structural.
|
||||
sa, sb = np.sort(dev.reshape(-1)), np.sort(ref.reshape(-1))
|
||||
A = np.vstack([sb, np.ones_like(sb)]).T
|
||||
(aa, bb), *_ = np.linalg.lstsq(A, sa, rcond=None)
|
||||
resid = sa - (aa * sb + bb)
|
||||
rf_aff = float(np.linalg.norm(resid)) / (float(np.linalg.norm(sb)) + 1e-12)
|
||||
r2 = 1.0 - float(np.sum(resid ** 2)) / (float(np.sum((sa - sa.mean()) ** 2)) + 1e-30)
|
||||
print(f" global-affine fit dev ~ {aa:.4f}*ref {bb:+.4f}: R^2={r2:.3f} residual(relFro after affine)={rf_aff:.3e}")
|
||||
print(f" (a large rf->rf_aff drop => mostly ONE network gain; rf_aff near rf => structural)")
|
||||
floor = 5e-3 # fp8 audio quant floor is ~1.6e-3; allow headroom for the bf16 activations
|
||||
print(f" verdict: {'MATCH within quant floor' if rf < floor else 'DIVERGED beyond quant floor'} "
|
||||
f"(floor {floor:.0e})")
|
||||
|
||||
@@ -232,6 +232,19 @@ def do_parity(m, evc_f, encpx_f, encg_f, slot):
|
||||
print(f" max abs deviation (sorted) = {mx:.3e}")
|
||||
print(f" reference std={ref.std():.4f} mean={ref.mean():.4f}; "
|
||||
f"device std={dev.std():.4f} mean={dev.mean():.4f}")
|
||||
# Decompose the gap. A single global scale+bias fitting the two sorted distributions well means the
|
||||
# divergence is mostly ONE network-level gain (a fixable mis-scaled norm/weight), not an intractable
|
||||
# structural transform. This scale survives the fold's PER-CHANNEL norm — and those norm constants are
|
||||
# byte-identical to the reference — so a COMMON-across-channels gain must live in the RAW encoder latent
|
||||
# (a network gain), not the fold. The residual relFro after removing the affine is the STRUCTURAL part.
|
||||
sa, sb = np.sort(dev.reshape(-1)), np.sort(ref)
|
||||
A = np.vstack([sb, np.ones_like(sb)]).T
|
||||
(aa, bb), *_ = np.linalg.lstsq(A, sa, rcond=None)
|
||||
resid = sa - (aa * sb + bb)
|
||||
rf_aff = float(np.linalg.norm(resid)) / (float(np.linalg.norm(sb)) + 1e-12)
|
||||
r2 = 1.0 - float(np.sum(resid ** 2)) / (float(np.sum((sa - sa.mean()) ** 2)) + 1e-30)
|
||||
print(f" global-affine fit dev ~ {aa:.4f}*ref {bb:+.4f}: R^2={r2:.3f} residual(relFro after affine)={rf_aff:.3e}")
|
||||
print(f" (a large rf->rf_aff drop => mostly ONE network gain; rf_aff near rf => structural)")
|
||||
# fp8 weights + bf16 activations are far coarser than the fp16 reference, so the floor is well above
|
||||
# the audio path's 5e-3. Interpret against the audio DIVERGENCE (0.79), not an absolute pass/fail.
|
||||
floor = 5e-2
|
||||
|
||||
Reference in new issue
Block a user