Repository navigation
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
Conversation
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.
…d seam-free tiled encode
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
…studio/vae-tile-seams-followup
…studio/q21-line-artifacts
# 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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
# 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
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
1 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.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.
Change
diffusion_vae_tiling.pynow 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:tile_sample_min_*andtile_sample_stride_*.tile_latent_min_sizeandtile_overlap_factor.compression_ratio(vae)reads the ratio from the attribute, the config, or the pixel / latent tile sides.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: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)._tiled_encode.KEEP_STOCKlists classes that must keep stock tiles, each with its measured reason. It is empty: every VAE the rule engages measured better or the same.UNSLOTH_DIFFUSION_VAE_WIDE_TILES=0is unchanged.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:
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_infocapped, no allocator slack). Median of 7 interleaved runs, in seconds:vae_tile_side.Tests
tests/test_diffusion_vae_tiling_general.py(304 tests, CPU, tiny diffusers VAEs of each class):KEEP_STOCK, and an unreadable geometry keeping stock;vaeannotation) is one the rule reads, or is listed inKEEP_STOCK.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.tiled_decodeistorch.equalat the floor, at a 40x40 cap and at the free-VRAM budget, and picks the same tile;vae.decodeandvae._encodearetorch.equal;Not covered