Repository navigation
fix(qwen-image): implement tiled encode and decode in QwenImageVAE - #1720
Merged
Merged
Conversation
QwenImagePipeline passes `tiled`, `tile_size` and `tile_stride` to QwenImageVAE.encode / decode, but both methods accepted them through **kwargs and ignored them, so `tiled=True` had no effect and high resolution encoding / decoding used the full amount of memory. Implement spatial tiling in the same way as WanVideoVAE: `tile_size` and `tile_stride` are measured in latent pixels, overlapping tiles are blended with linear masks, and the last tile in each direction is clipped to the image border. Tiles without overlap (`tile_stride == tile_size`) are not blended, and a `tile_stride` that is not in `(0, tile_size]` raises a ValueError. The number of output channels is taken from the first tile, so the RGBA VAE of Qwen-Image-Layered works as well. The default path (`tiled=False`) is unchanged. Fixes modelscope#1069
fusheng-ji
force-pushed
the
fix/qwen-image-vae-tiled
branch
from
October 2, 2026 20:26
e04597c to
12bf35f
Compare
Collaborator
|
@fusheng-ji Thank you for your suggestion. We will go ahead and merge this PR. |
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.
Fixes #1069
QwenImagePipelinepassestiled,tile_sizeandtile_strideto the VAE (e.g. qwen_image.py#L194, #L282), butQwenImageVAE.encode/decodeaccept them through**kwargsand ignore them. Sotiled=Truehas no effect, and high-resolution encoding and decoding always use the full amount of memory.This PR implements spatial tiling the same way
WanVideoVAEdoes:tile_sizeandtile_strideare measured in latent pixels (the pipeline defaults 128 / 64 mean 1024 / 512 image pixels).image_channels=4) works too.The default path (
tiled=False) is unchanged.Checking
Setup: real
Qwen/Qwen-ImageVAE weights, bf16, 1× B200, 2048×2048 input:tiled=True(128 / 64)tiled=True(128 / 64)tiled=True(64 / 32)Before this PR,
tiled=Truepeaked at 8.57 GiB for encode + decode, the same as non-tiled.Other shapes:
QwenImageVAE(image_channels=4)with batch 2 also works.tile_stride == tile_size(no overlap, e.g. 64 / 64, 32 / 32, or 64×48 tiles), tiled encode and decode match the non-tiled result exactly; atile_strideoutside(0, tile_size]raises aValueError. (Checked with stand-in encode / decode functions.)WanVideoVAE.build_1d_maskhas the same zero-overlap problem onmain; I left it unchanged here.End-to-end with
QwenImagePipeline. Setup:Qwen/Qwen-Imageweights, bf16, 2048×2048, 30 steps, torch 2.11.0+cu130, 1× B200. I ran text-to-image (decode) and then image-to-image from that image withdenoising_strength=0.6(encode + decode), each withtiled=Falseandtiled=True(pipeline defaults 128 / 64). Peak memory is measured above the memory already in use when the VAE call starts:tiled=Falsetiled=Truetiled=Falsetiled=Truetiled=Falsetiled=False, outputs are bit-identical before and after this PR.Qwen/Qwen-Imageat 2048×2048, 30 steps, with this PR. Top: full images (downscaled). Bottom: 512×512 crops at 1:1 from the image center, where tiles overlap. Tiled outputs match the non-tiled ones (PSNR 54.9 dB t2i, 50.2 dB i2i) with no visible seams, while VAE peak memory drops about 4×. Onmain,tiled=Trueis ignored: its output is bit-identical to non-tiled and uses the same memory.Tiled decoding is a bit slower (0.52 s vs 0.36 s at 2048²).