h3.c icon indicating copy to clipboard operation
h3.c copied to clipboard

Rectangular mosaic texture in dense fur at 1344x768 is h3.c-specific (independent impl renders clean strands)

Open dominicletz opened this issue 2 months ago • 3 comments

Human Preamble

I've experienced a very heavy mosaic structure on the generated videos using h3.c on my hardware. I'm surprised that nobody else reported this yet, as I couldn't really find a work-around configuration wise. I wonder if this is related to my Apple hardware or my copy of the model? Every video has those. I've generated below report on this and attached a sample side-by-side of the issue.

Summary

Dense fox-fur regions at 1344x768 render with a rectangular mosaic texture: squarish dark blotches with hard axis-aligned edges instead of coherent fur strands. It is present in the raw pre-encode output (--frames-dir PPM), so it is not x264. A second, independent Metal implementation (vpipe, own kernels, own VAE decode) renders the same prompt/geometry/seed with clean directional fur strands — so this looks h3.c-specific (DiT kernels or the video-VAE decode path), not model-inherent.

Repro

  • Commit: 8974cc0 (predates PR #63)
  • Device: Apple M5 Pro, 48 GB, Metal 4 (h3 --info: applegpu_g17s, GPU family 10)
  • Model: MiniMax-H3 FL2VA, -d ~/models/MiniMax-H3
  • Must run with cwd at the shader dir (h3 loads h3_shaders.metal from cwd)
cd ~/src/h3.c && ./h3 --profile -d ~/models/MiniMax-H3 \
  -p "A red fox walks through fresh snow in a pine forest. Medium tracking shot, natural winter light, realistic fur, soft footsteps and wind." \
  --width 1344 --height 768 --frames 22 --seed 42 \
  --steps 20 --layers 50 --reuse 1 --use-slower-bf16-mlp \
  --frames-dir /tmp/raw-frames -o /tmp/fox.mp4

Look at the fox tail in any raw frame (e.g. frame 21): the mid-tail fur breaks into discrete dark squarish spots with visible block edges, roughly 15-30 px, instead of strands. Also visible (weaker) in exact-default and balanced configs.

Ruled out

  • Denoising steps: identical mosaic at 4 / 20 / 50 steps (50-step sample kept).
  • Precision: int8 default and BF16-MLP (--use-slower-bf16-mlp) show identical structure.
  • Encoder: raw PPM frames show it; the old x264 defaults (fast/CRF 18) added extra blocking on top, fixed separately by encoding slow/CRF 14 — the underlying mosaic remains.
  • VAE tile seams: documented tiles are 256-320 px with 64 px overlap, an order of magnitude coarser than these blocks.
  • Model: vpipe cross-check below.

Cross-check: vpipe renders clean fur

vpipe (tgo-app-dev/vpipe, independent Metal kernels, own MiniMax-H3 loader/VAE decode) at the same prompt, 1344x768, 22 frames, seed 42, 16 steps, DiT + text encoder quantized to 8-bit group-64 from the same local weights (registered the diffusers dir directly, skipped the Comfy repack download). Its raw pre-encode PNGs show coherent directional fur strands with smooth tonal gradation in the same tail region — no blocks. Note vpipe runs lower effective precision (8-bit + lossy i8_gemm) than the h3.c BF16-MLP run that shows the mosaic, so precision cannot explain the difference either. (Poses differ between the two implementations, so this compares texture character, not pixels.)

Suspects

Remaining candidates on the h3.c side: DiT attention/MLP Metal kernels (note this checkout predates the PR #63 GQA-barrier fix — I also observe same-seed output variance consistent with issue #52) or the video-VAE decoder path at 768p. The related texture artifacts already documented in the README (woven texture in rejected schedules, 256 lattice fixed via RoPE halving) suggest this could be another member of that family.

dominicletz avatar Sep 26 '26 17:09 dominicletz

Side-by-side, as promised — same tail region, raw pre-encode frames, full-res crop on top with 2x nearest-neighbor zoom below:

h3.c (left, blocks) vs vpipe (right, strands), raw tail crops

Left: h3.c bf16-mlp frame 21 — mid-tail fur breaks into discrete squarish blotches with axis-aligned edges. Right: vpipe 8-bit frame 21 — coherent directional strands, smooth gradation. (Poses differ between implementations, so compare texture character, not pixels. Full frames + clips available on request.)

dominicletz avatar Sep 26 '26 17:09 dominicletz

Additional data point, same symptom (16×16 patch mosaic, fixed to the frame grid, visible in raw frames before encoding), on M5 Max 128 GB, h3.c @ 8974cc0, weights MiniMaxAI/MiniMax-H3 @ 0919fb6 (all FL2VA/Ref2VA files match the Hub sha256).

Measurement. Lossless frames via --frames-dir. On smooth areas (|∂x|,|∂y| < 1.5 levels) I average the absolute neighbour difference per phase mod 16 (from the frame origin) and report the 15|0 boundary relative to the median phase. A clean image should sit near 0 %.

Run (512×512, 56 frames, 8 steps, seed 7, FL2VA) seam 15|0, x / y
default +57 % / +52 %
H3_VAE_TILE_PIXELS=256 +53 % / +54 %
H3_VAE_TILE_PIXELS=512 (single tile) +60 % / +64 %
--use-slower-bf16-mlp --use-slower-bf16-qkv --use-slower-bf16-attention-output +54 % / +51 %

768×1344, 158 frames, Ref2VA, 10 steps, --layers 45 --reuse 2, seed 101: +49 % / +38 % in the PPM frames; the libx264 crf 18 MP4 roughly doubles it (+94 % / +95 %) and adds an 8-px component.

Ruled out so far

  • VAE tile size / tile blending (256, 288, 512 identical).
  • int8 DiT paths (full BF16 gives the same seam).
  • A static additive per-patch pattern: averaging the high-passed 16×16 patch over all 637k patches of a clip gives only ~0.34 levels RMS (peak ~1 level), so the seam is content-dependent, not a fixed offset.
  • The video-VAE decoder vs. the reference vae_vit.py / klvae.py / func.py: normalized (t,h,w) RoPE with +0.5 offsets, 2π·100^(−k/8), rotate-half pairs (i, i+24) on the first 48 of 64 dims, QK RMS norm before RoPE, registers + zero cls token at position 0, (c, pt, ph, pw) unpatchify, ImageNet de-normalization, and tile blending all look equivalent to me.

The seams show up as per-patch shading on flat backgrounds and as small discontinuities across patch edges in detail (nose, fur), and stay put when the content moves. Happy to run more variants or share frames/scripts if useful.

Eldirfar avatar Nov 20 '26 11:11 Eldirfar

Follow-up with a direct A/B against vpipe on identical weights.

Setup

  • MiniMaxAI/MiniMax-H3 @ 0919fb6 (FL2VA, BF16 snapshot), M-series Mac, macOS 26.6
  • h3.c @ 8974cc0, DiT forced to BF16: --use-slower-bf16-mlp --use-slower-bf16-qkv --use-slower-bf16-attention-output
  • vpipe @ 4dc36b7 (minimax-h3-text-to-video pipeline, i8_gemm: false)
  • Same prompt, seed 7, 56 frames, video shift 12 / audio shift 3
  • Lossless output on both sides: h3.c --frames-dir (PPM), vpipe FFV1 yuv444p full range. No H.264 involved.

Metric Mean absolute luma gradient on smooth pixels (|gx| and |gy| < 1.5/255), bucketed by position mod 16. The value is bucket 15 (the 15|0 patch boundary) relative to the median bucket. 0% = no grid. Averaged over frames 5, 15, 25, 35, 45, 54.

run h3.c x / y vpipe x / y
512x512, 8 steps +53% / +48% +34% / +35%
768x1344, 20 steps +39% / +42% +23% / +25%

All other buckets stay within about ±10% in both implementations. The boundary bucket is the only outlier.

Takeaways

  1. The 16-px seam is present in vpipe too: on a high-passed background crop, both show the same 16x16 blocks. So part of it seems inherent to the patch-based video VAE decoder, and vpipe output is not fully clean.
  2. h3.c consistently shows ~1.6-1.7x more seam energy than vpipe on the same weights and settings, in both runs. That excess looks implementation-specific.
  3. Higher resolution and more steps reduce the seam in both implementations.

Caveat: the two runners use different RNGs, so the frames differ in content. This compares seam strength statistically, not pixel by pixel.

Happy to share the PPM frames or the measurement script if useful.

Eldirfar avatar Nov 20 '26 15:11 Eldirfar