Skip to content

Studio: seam-free tiled decode for every image VAE whose stock tiles fall under the floor (HunyuanImage-2.1 grid, Qwen-Image, slivers) - #12736

Merged
danielhanchen merged 23 commits into
mainfrom
studio/vae-seamfree-tiles-general
Oct 5, 2026
Merged

danielhanchen merged 23 commits into
mainfrom
studio/vae-seamfree-tiles-general

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Based on #12696 (merged in, not rebased). Generalises its Qwen-Image-2.1 fix to every image VAE Studio can tile.

Problem

Studio's low-VRAM tiers (whole-model and sequential offload, streaming, and the per-call guard's tile verdict) call enable_tiling() and leave diffusers' stock tile geometry in place. #12696 fixed that geometry for Qwen-Image-2.1 only (_VAE_CLASSES = {"AutoencoderKLQwenImage21"}). Here is every VAE class in the image family registry. I measured each one on real weights: the same latent, from the untiled encode of a DIV2K photo (0010 and 0042), decoded with stock tiles and without tiling, in bf16 on a B200 with diffusers 0.41.0.dev0.

VAE class families ratio stock tile / overlap, latents Studio tiles it stock vs untiled, PSNR dB worst 64 px window, levels
AutoencoderKLQwenImage21 Qwen-Image-2.1 16x 16 / 4 above 256 px 32.7 to 38.0 9.1 to 14.1
AutoencoderKLHunyuanImage HunyuanImage-2.1 32x 12 / 3 above 384 px 20.9 to 23.0 36.9 to 54.8
AutoencoderKLQwenImage Qwen-Image, Qwen-Image-Edit, Krea-2 8x 32 / 8 above 256 px 29.9 to 46.3 6.3 to 24.0
AutoencoderKL FLUX.1, Kontext, Z-Image, HiDream, Lumina 2 8x 128 / 32 above 1024 px 35.3 to 43.7 4.5 to 8.7
AutoencoderKL SDXL 8x 128 / 32 above 1024 px 38.7 to 44.0 3.4 to 7.8
AutoencoderKLFlux2 FLUX.2 klein / dev, Ideogram 4 8x 128 / 32 above 1024 px 27.3 to 39.4 8.2 to 22.3

Sizes: 1024x1024, 1328x1328, 1536x1024, 1600x1600 and 2048x2048. Weights pinned to these revisions: Qwen/Qwen-Image-2.1 d26bb612, hunyuanvideo-community/HunyuanImage-2.1-Diffusers 7e7b7a17, Qwen/Qwen-Image 75e0b4be, unsloth/Krea-2-Turbo 2489d0f4, unsloth/FLUX.1-schnell 9df3faa7, Alpha-VLLM/Lumina-Image-2.0 53504abd, stabilityai/stable-diffusion-xl-base-1.0 46216598, black-forest-labs/FLUX.2-klein-4B e7b7dc27, unsloth/FLUX.2-dev 351bbb0e, unsloth/ideogram-4-fp8 518e05e7. FLUX.1, Kontext, Z-Image and HiDream ship the same VAE file. Krea-2 decodes identically to Qwen-Image, and Lumina 2 identically to FLUX.1.

  • HunyuanImage-2.1 is broken whenever it tiles. The 384 px stock tile is 12 latents at 32x, with a 3-latent (96 px) blend. The tiled decode draws a visible grid and over-sharpened texture. That gives 21 to 23 dB against the untiled decode of the same latent, at every size, including 1024x1024.
  • Qwen-Image-2.1 is the Studio: seam-free VAE tiles for Qwen-Image-2.1 on low-VRAM tiers (fixes thin horizontal / vertical lines) #12696 case: 16-latent tiles, 4-latent blends and edge slivers.
  • Qwen-Image, Qwen-Image-Edit and Krea-2 blend over only 8 latents, under ComfyUI's 16-latent decode overlap. No line is visible on these photos. The tiled-vs-untiled difference is texture-level and looks the same with either tile layout. The stock tiled encode (edit and img2img inputs) moves the condition latent by 1.2 to 2.1% RMS.
  • AutoencoderKL and FLUX.2 tiles are 128 latents with 32-latent blends. diffusers starts a tile every 96 latents until the canvas ends, so on some sides the last tile is a sliver: 8 latents at 1600 px, 28 at 1760 px, 8 at 2368 px.

Change

diffusion_vae_tiling.py now decides from the VAE instead of from a class name:

  • stock_tiles(vae) reads diffusers' tile and overlap in latents off the VAE's own attributes:
    • Wan family: tile_sample_min_* and tile_sample_stride_*.
    • AutoencoderKL style: tile_latent_min_size and tile_overlap_factor.
  • compression_ratio(vae) reads the ratio from the attribute, the config, or the pixel / latent tile sides.
  • Each tiled decode keeps diffusers' tiles when every stock tile is at least 32 latents and every overlap at least 16 (stock_layout_ok). Otherwise it takes Studio: seam-free VAE tiles for Qwen-Image-2.1 on low-VRAM tiers (fixes thin horizontal / vertical lines) #12696's wide tiles:
    • The tile floor is 32 latents, or the stock tile when larger. The overlap is 16 latents, or the stock overlap when larger.
    • Tiles are edge-aligned.
    • The blend is unchanged: no weight within 4 latents of a shared edge, then an 8-latent ramp.
    • FLUX.1, FLUX.2 and SDXL therefore stay bit-identical to main at every size except the sliver sizes.
  • Latents may be 4-D (B, C, H, W) as well as 5-D.
  • The decode budget is per output pixel: 1.7 MiB per latent x (ratio / 16)^2. That is Studio: seam-free VAE tiles for Qwen-Image-2.1 on low-VRAM tiers (fixes thin horizontal / vertical lines) #12696's figure at 16x, and it bounds the measured floor-tile peak of every covered VAE (a test pins this).
  • The Wan-family tiled encode (Qwen-Image, Qwen-Image-2.1) gets the same 64-latent tiles. AutoencoderKL-style VAEs keep their private 1024 px _tiled_encode.
  • KEEP_STOCK lists classes that must keep stock tiles, each with its measured reason. It is empty: every VAE the rule engages measured better or the same.
  • A VAE whose tile geometry cannot be read keeps its stock decode.
  • The kill switch UNSLOTH_DIFFUSION_VAE_WIDE_TILES=0 is unchanged.
  • Qwen-Image-2.1 is bit-identical to Studio: seam-free VAE tiles for Qwen-Image-2.1 on low-VRAM tiers (fixes thin horizontal / vertical lines) #12696.

Results

Same latents and photos as above, stock tiles against the wide tiles at their floor (no budget, the worst case), measured against the untiled decode:

VAE sizes the rule changes PSNR dB, stock / this PR worst 64 px window, stock / this PR decode peak MiB, stock / this PR
Qwen-Image-2.1 all tiled 32.7-38.0 / 46.7-52.1 9.1-14.1 / 1.2-2.4 434-473 / 1,697-1,745
HunyuanImage-2.1 all tiled 20.9-23.0 / 27.3-36.3 (1024 px untiled) 36.9-54.8 / 0-28.2 188-214 / 1,280-1,332
Qwen-Image all tiled 29.9-46.3 / 30.3-47.0 6.3-24.0 / 5.8-22.2 275-305 / 278-314
FLUX.1 ae 1600 px (sliver) 38.5-40.1 / 39.8-43.9 4.7-6.1 / 3.5-4.5 2,433 / 2,466
SDXL 1600 px (sliver) 38.8-41.3 / 40.2-43.4 4.4-7.8 / 3.1-6.2 2,433 / 2,467
FLUX.2 1600 px (sliver) 30.0-31.8 / 31.8-32.5 8.9-14.6 / 8.8-9.9 2,434 / 2,467
  • The Qwen-Image tiled encode moves the condition latent by 0.4 to 1.2% RMS here, against 1.2 to 2.1% before. For Qwen-Image-2.1 it is 0 to 11% against 76 to 92%, as in Studio: seam-free VAE tiles for Qwen-Image-2.1 on low-VRAM tiers (fixes thin horizontal / vertical lines) #12696.
  • At 1328, 1536x1024 and 2048 px, FLUX.1, SDXL and FLUX.2 decode through the stock path, bit-identical to main.
  • fp32 decodes give the same picture, so these numbers are not bf16 noise. Qwen-Image moves from 29.9-46.6 to 30.3-47.3 dB, HunyuanImage from 21.0-23.0 to 27.3 dB and up, and the FLUX.1 sliver from 38.5-40.2 to 39.9-43.9 dB.

Decode time with Studio's fused VAE kernels installed in load order (wide tiles first, then diffusion_vae_fused), on an exclusive B200. A card with 4 GiB free is emulated (mem_get_info capped, no allocator slack). Median of 7 interleaved runs, in seconds:

VAE, size stock (fused batched tiles) this PR, 4 GiB free this PR, floor tiles peak MiB, stock / 4 GiB / floor
Qwen-Image 1024 0.190 0.045 (72x72 tiles) 0.244 189 / 925 / 192
Qwen-Image 1328 0.253 0.058 0.537 193 / 1,078 / 201
Qwen-Image 2048 0.741 0.093 1.409 217 / 1,130 / 228
Qwen-Image-2.1 1024 0.284 0.083 0.094 121 / 694 / 450
Qwen-Image-2.1 2048 1.049 0.345 0.497 158 / 791 / 498
HunyuanImage-2.1 1024 0.244 0.084 0.073 188 / 1,280 / 1,280
HunyuanImage-2.1 2048 1.003 0.650 0.647 214 / 1,332 / 1,332
FLUX.1 1600 (sliver) 0.066 0.072 0.069 1,408 / 1,441 / 1,441
FLUX.1 2048 0.107 0.107 (stock path) 0.107 1,429 / 1,429 / 1,429
  • With a few GiB free, the budget-sized tiles make Qwen-Image, Qwen-Image-2.1 and HunyuanImage decode 1.5 to 8x faster than stock. The FLUX.1 sliver size is 6 ms (9%) slower.
  • The floor tiles are the case where the free VRAM at decode time is under about 0.6 GiB for Qwen-Image. There, Qwen-Image decodes 1.3 to 1.9x slower than the fused batched stock tiles, because the wide path does not batch tiles and decodes twice the overlap.
  • The HunyuanImage floor tile peaks at 1.3 GiB against 0.2 GiB stock. The per-call guard now charges it as a 1024 px tile through vae_tile_side.

Tests

  • tests/test_diffusion_vae_tiling_general.py (304 tests, CPU, tiny diffusers VAEs of each class):
    • geometry and ratio read off AutoencoderKLQwenImage (8x), AutoencoderKLQwenImage21 (16x), AutoencoderKLHunyuanImage (32x), AutoencoderKL and AutoencoderKLFlux2 (8x);
    • the stock-layout floor per ratio, including the sliver sides;
    • wide tiles full and edge-aligned, with weights summing to 1, at every length and ratio;
    • seam reduction on Qwen-Image and HunyuanImage;
    • AutoencoderKL bit-identical to stock where its tiles meet the floor, and on the wide path for a sliver;
    • which encodes are replaced, and the Qwen-Image encode closer to untiled;
    • the kill switch per class, KEEP_STOCK, and an unreadable geometry keeping stock;
    • the per-pixel budget, which bounds the measured floor-tile peaks;
    • every image family's VAE class (read from the diffusers pipeline's vae annotation) is one the rule reads, or is listed in KEEP_STOCK.
  • On Studio: seam-free VAE tiles for Qwen-Image-2.1 on low-VRAM tiers (fixes thin horizontal / vertical lines) #12696's head, 35 of them fail. The Qwen-Image, HunyuanImage and AutoencoderKL sliver seam tests fail because install() returns False for those VAEs. On main the module does not exist.
  • tests/test_diffusion_vae_tiling.py (Studio: seam-free VAE tiles for Qwen-Image-2.1 on low-VRAM tiers (fixes thin horizontal / vertical lines) #12696, 580 tests) passes unchanged.
  • The related suites pass: diffusion backend, memory, calibrated activation, speed, fused VAE, single-frame VAE, upscale gate, VAE prebuild, channels-last (1,214 passed, 26 skipped).
  • Qwen-Image-2.1 on real weights, Studio: seam-free VAE tiles for Qwen-Image-2.1 on low-VRAM tiers (fixes thin horizontal / vertical lines) #12696's module against this one, at 1024x1024, 1344x1344, 2048x2048, 2752x1536 and 1184x864:
    • tiled_decode is torch.equal at the floor, at a 40x40 cap and at the free-VRAM budget, and picks the same tile;
    • the installed vae.decode and vae._encode are torch.equal;
    • the budget is identical.

Not covered

  • No end-to-end Studio render on a real 8 to 16 GB card. All numbers are offline decodes of real latents on a B200, with the low-VRAM budget emulated.
  • Measured on diffusers 0.41.0.dev0 and torch 2.12.1 only. The rule reads geometry at runtime, so a diffusers that changes a tile default is followed automatically, but that was not exercised.
  • FLUX.2 (and, less so, FLUX.1 and SDXL) shift colour per tile above 1024 px even where the stock tiles meet the floor: 27.3 dB at 2048 px for FLUX.2, a greener bottom-right tile. It is a per-tile offset, not a line. It is probably the decoder's normalisation statistics being computed per tile, though that was not isolated. The wide tiles would reduce it (30.3 dB) but not remove it, so those sizes keep the stock path here.
  • The boundary-gradient seam score (cross-boundary gradient over its median) does not separate stock from wide on these photos for any VAE, Qwen-Image-2.1 included (stock 1.4 to 3.5 against a content control of 1.4 to 3.3). The PSNR and the worst 64 px window carry the result. A seam detector built on that score alone would miss Studio: seam-free VAE tiles for Qwen-Image-2.1 on low-VRAM tiers (fixes thin horizontal / vertical lines) #12696's lines.
  • The 32x budget figure is about 5x the measured HunyuanImage peak (6.8 against 1.3 MiB per latent), so HunyuanImage rarely gets tiles above the floor. That is safe, but not as fast as it could be.
  • ComfyUI's own OOM fallback for the Qwen-Image VAE uses 32-latent tiles with 8-latent overlaps, as diffusers does. This PR follows its 16-latent 2D decode overlap instead, which measured slightly closer to untiled.
  • AMD, Windows and Apple Silicon were not run.

danielhanchen and others added 19 commits October 4, 2026 08:36
The Qwen-Image-2.1 VAE compresses 16x, but diffusers gives it the Wan VAE's
tile geometry in pixels (256 px tiles, 192 px stride). On this VAE that is a
16-latent tile with a 4-latent (64 px) blend, and the last row and column are
4-latent slivers. The decoder sees further than 4 latents past a tile edge,
so every seam and the right / bottom sliver decode differently from their
neighbours, and the short blend leaves thin vertical and horizontal lines
about one tile long. Every tier that tiles the decode (the 12 GB and 16 GB
streaming / offload plans) has drawn them since the family was added;
resident loads decode untiled and never showed them.

Decode this VAE in 32-latent tiles with at least a 16-latent overlap (the
overlap ComfyUI tiles its decode with), spread evenly so the last tile ends
at the image edge at full size. A tile gets no weight within 4 latents of an
edge it shares with another tile and ramps to full weight over the next 8,
normalised to 1 at every pixel, so the edge of an outer tile never shows
where three tiles overlap (strides under 16 latents). A canvas within one
tile decodes untiled. Tiles decode one at a time, so the decode peak does not
grow with the canvas.

Installed at load for every speed mode, before the fused batched tile decode,
so it covers the fused and stock paths. Only the decode changes: the tiled
encode and the tile attributes stay stock. vae_tile_side and the calibrated
tiled-decode activation report the 512 px tile. Kill switch
UNSLOTH_DIFFUSION_VAE_WIDE_TILES=0 (at load: skip the install; later: stock
tiled decode per call).

Tests cover the tile layout and blend weights at every size the Images page
offers, the per-call memory guard at those sizes, and a tiny random
AutoencoderKLQwenImage21 decoded tiled against untiled.
…w-VRAM tiers

The Qwen-Image-2.1 VAE compresses 16x, but diffusers gives it the Wan VAE's
tile geometry in pixels (256 px tiles, 192 px stride). On this VAE that is a
16-latent tile with a 4-latent (64 px) blend, and the last row and column are
4-latent slivers. The decoder sees further than 4 latents past a tile edge,
so every seam and the right / bottom sliver decode differently from their
neighbours, and the short blend leaves thin vertical and horizontal lines
about one tile long. Every tier that tiles the decode (the 12 GB and 16 GB
streaming / offload plans) has drawn them since the family was added;
resident loads decode untiled and never showed them.

Decode this VAE in 32-latent tiles with at least a 16-latent overlap (the
overlap ComfyUI tiles its decode with), spread evenly so the last tile ends
at the image edge at full size. A tile gets no weight within 4 latents of an
edge it shares with another tile and ramps to full weight over the next 8,
normalised to 1 at every pixel, so the edge of an outer tile never shows
where three tiles overlap (strides under 16 latents). A canvas within one
tile decodes untiled. Tiles decode one at a time, so the decode peak does not
grow with the canvas.

The stock tiled encode (img2img and edit inputs on the same tiers) has the
same geometry and seams; it gets the same tiles, blended in latent space.

Installed at load for every speed mode, before the fused batched tile decode,
so it covers the fused and stock paths. The VAE's tile attributes stay stock. vae_tile_side and the calibrated
tiled-decode activation report the 512 px tile. Kill switch
UNSLOTH_DIFFUSION_VAE_WIDE_TILES=0 (at load: skip the install; later: stock
tiled decode / encode per call).

Tests cover the tile layout and blend weights at every size the Images page
offers, the per-call memory guard at those sizes, and a tiny random
AutoencoderKLQwenImage21 decoded and encoded tiled against untiled.
The 32x32-latent decode tiles with 16-latent overlaps decode about 2.25x the
canvas at 1024x1024 against about 1.7x for the stock tiles, which costs about
0.25 s per decode on an L4. When half the free VRAM holds them, take larger
tiles, down to one untiled decode: fewer tiles decode less overlap, so they
are faster and leave fewer seams. The tile sides are the fewest that cover
each axis with 16-latent overlaps and fit the area budget (1.7 MiB of decode
peak per latent of tile area, measured on 32x32 to 64x64 tiles, plus the fp32
output accumulator). With no room for more, the decode keeps the 32x32 tiles
the planner budgets, so no plan or memory estimate changes.
UNSLOTH_DIFFUSION_VAE_MAX_TILE caps the tile side.
…AM tiers

The 12 / 16 GB tiers tile the VAE encode with diffusers' stock 16-latent tiles. The encoder
attends over each tile, so the condition latent shifts everywhere, not only at the seams, and
edits drift from the resident result. Encode in 64-latent tiles with 32-latent overlaps and the
decode's normalised ramp blend: a 1024 px reference (the default) is one tile and matches the
untiled encode exactly. Same kill switch as the decode.
# Conflicts:
#	studio/backend/core/inference/diffusion_vae_tiling.py
#	studio/backend/tests/test_diffusion_vae_tiling.py
# Conflicts:
#	studio/backend/core/inference/diffusion_vae_tiling.py
#	studio/backend/tests/test_diffusion_vae_tiling.py
This family only encodes edit inputs, at the reference resolution, and the per-call guard charges them as weighted condition pixels. Test that this covers the measured 64-latent encode tile (2,322 MiB unfused) at every reference resolution and output size, and describe the encode geometry in the module docstring.
…fall under the floor

Read the stock tile and overlap off each VAE (Wan-family pixel tiles and
strides, AutoencoderKL-style latent tiles and overlap factor) and its
compression ratio, instead of covering only AutoencoderKLQwenImage21.
Each tiled decode keeps diffusers' tiles when every tile is at least 32
latents and every overlap at least 16, and otherwise takes the wide,
edge-aligned tiles (floor 32 / 16, or the stock tile when larger).

This covers Qwen-Image / Qwen-Image-Edit / Krea-2 (8x, 8-latent blends),
HunyuanImage-2.1 (32x, 12-latent tiles with 3-latent blends) and the
edge-sliver sizes of AutoencoderKL / FLUX.2 (an 8-latent last tile at
1600 px), and keeps Qwen-Image-2.1 bit-identical. 4-D latents are
supported, the decode budget scales per output pixel, and KEEP_STOCK
holds VAEs that must keep stock tiles, with the measured reason.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T15:56:01.035912Z f4f203e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Base automatically changed from studio/q21-line-artifacts to main October 5, 2026 10:45
@danielhanchen danielhanchen self-assigned this Oct 5, 2026
danielhanchen and others added 4 commits October 5, 2026 06:44
# Conflicts:
#	studio/backend/core/inference/diffusion.py
#	studio/backend/core/inference/diffusion_vae_tiling.py
# Conflicts:
#	studio/backend/core/inference/diffusion.py
#	studio/backend/core/inference/diffusion_vae_tiling.py
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 5, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: f4f203ee6d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant