Commit Graph
2 Commits
Author SHA1 Message Date
Niko1221 cab47f3d2c Image generation, VAE decoder: f16 headroom for the block-4 shortcut (fixed shift 11), GEMM blocks on the picture's pixel grid (row bands byte-identical on HIP too), and no broken picture on a non-finite value
Operand range (strata-vae-decode --stats over the 16 gate latents, merged per convolution): the only layer within
16x of the f16 maximum under stable-diffusion.cpp's 2^-7 is up_blocks.4.resnets.0.conv_shortcut (largest input
3.48e6, 2.4x headroom); it gets the fixed shift 11 (38.5x).  The shift is a constant per layer (conv_shift()), never
from the picture's data; vae_ref.py carries the same table and a test checks they agree.  Next closest layers:
62.8x and 113x, kept at 7.

The row bands were not byte-identical on HIP (R9700: 8 of 16 differed; hipBLAS gives a row another reduction order
at another row position of the call).  Every convolution now runs its GEMM blocks on the picture's pixel grid, also
in a row window (rows outside the window are zero and dropped), so a pixel sits in the same row of a same-shape call
in both paths.  wan_vae_set_band_rows / --band-rows: vae_identity.py also checks band heights 48 and 100.

A picture with a non-finite value is an error (the sd-cli hook then logs "...; using stable-diffusion.cpp's decoder,
which may fail the same way", the approved line).  Test-only: wan_vae_set_range_stats / wan_vae_range_report.

Gates: identity (bands of 128, 48 and 100 rows against one pass, bands run to run) PASS 16 of 16 on CUDA
(dgxspark-20261110-1832-ea13) and on HIP (p620-20261110-1832-6e66).  Against sd.cpp's CUDA pictures, PSNR worst /
mean: CUDA 56.80 / 57.72, 56.20 / 57.50, 57.02 / 57.37 dB at 512, 1024, 1536x1024 (vae_same_tiling pass);
HIP 56.81 / 57.71, 56.21 / 57.50, 57.02 / 57.37 dB.  Against the previous commit's pictures 79.4-81.2 dB (max 1).
Stress, 1024 p4's latent x2 / x4: ours finite, 65.36 / 63.99 dB from the numpy f32 reference (sd.cpp's decoder
53.91 / 49.59 dB); the shortcut's headroom 113x / 133x.  Decode (bands) CUDA 0.46-0.48 / 1.03-1.08 / 1.46-1.50 s,
HIP 0.82-0.84 / 1.19-1.23 / 1.49-1.50 s.  CPU tests 98 passed with the other image tests (boston-20261110-1837-287a).
2026-11-10 18:52:32 +01:00
Niko1221 d7611e03ca Image gate: a numpy reference of Qwen-Image-2.1's VAE decoder (vae_ref.py), as stable-diffusion.cpp 2988060 runs it for one picture
Test-only oracle for our own VAE decode (OWN-5 step 2): pixel-major float32, the Wan2.2-style residual decoder
(post_quant_conv, conv_in, mid resnet/attention/resnet, five up blocks with nearest-2x and the DupUp shortcut,
norm_out, SiLU, conv_out to RGBA), two modes: "f32" (exact weights, float32) and "f16op" (the f16 operands sd.cpp
and our GPU decoder use, accumulated exactly).  sd.cpp's 8-bit conversion and the latent denormalization are in
it too.  test_vae_ref.py checks DupUp against the Wan Python form, the 3x3 conv against direct loops, the RMS
norm by hand, the bf16 reader, and a tiny random decoder end to end (8 passed on p1004).
2026-11-10 17:22:34 +01:00