You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix HunyuanImage refiner VAE tiling mixing latent and sample space - #15455
AutoencoderKLHunyuanImageRefiner mixes latent-space and sample-space quantities in both tiling paths.
tiled_encode cuts its tiles out of the sample tensor but advances with a latent-space step:
overlap_height=int(tile_latent_min_height* (1-self.tile_overlap_factor)) # 256 // 16 * 0.75 == 12
...
foriinrange(0, height, overlap_height): # height is a sample-space dimensiontile=x[..., i : i+self.tile_sample_min_height, ...]
With the default tile of 256 samples and a stride of 192 samples, the loop advances 12 samples instead of 192. That encodes ~16x more tiles than needed and concatenates them into a latent far larger than the input, so encode returns the wrong shape.
tiled_decode does the opposite: it walks the latent tensor correctly, but blends and crops the decoded tiles with latent-space numbers:
Each decoded tile keeps 12 pixels and drops the other 244, so decode returns a fraction of the image.
Both paths also ignore tile_sample_stride_height/tile_sample_stride_width, which enable_tiling stores and which every other tiled VAE (AutoencoderKLHunyuanVideo15, AutoencoderKLWan, ...) uses.
Reproduction
Tiny model, spatial compression 2, 32x32 input (16x16 latent), tiles of 16 samples with a stride of 12:
tiled_encode: advance by self.tile_sample_stride_height/width (sample space, matching the cut), and derive the latent blend/crop from tile_latent_min_* minus the latent stride.
tiled_decode: keep stepping by the latent stride, but blend by tile_sample_min_* - tile_sample_stride_* and crop to tile_sample_stride_*, because the blend happens on decoded tiles.
The defaults are unchanged: with tile_sample_min = 256, tile_sample_stride = 192 and tile_overlap_factor = 0.25, the latent blend is 16 - 12 = 4 and the sample-space blend is 256 - 192 = 64, i.e. exactly what the old int(size * factor) produced in the right space.
Test
New tests/models/autoencoders/test_models_autoencoder_hunyuanimage_refiner.py with two shape assertions (tiled encode/decode vs the non-tiled paths). Both fail on main (29x29 != 16x16 and 18x18 != 32x32) and pass with the fix.
Hi @newcloud123, thanks for the PR! It does not appear to link an issue it fixes.
If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked.
If you are the author of the model/pipeline this PR relates to, or part of the team we work with on it, tick the Are you the author (or part of the team we work with) of the model/pipeline this PR relates to? box in the PR description (if you removed the template, paste that line back, checked). This reminder then no longer applies.
Otherwise there is nothing you need to do: a maintainer will look at the PR and add the no-issue-needed label to silence this reminder if it should stay open without an issue.
Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice.
Once the PR links an existing issue, the author box is ticked, or the no-issue-needed label is added, you can ignore this message — it stays here as a comment, but it no longer applies.
Same situation as #15454 re the pr-link-issue-reminder: this is a self-found bug with no pre-existing issue. The PR body has the minimal reproduction and a shape table (encoded latent 16x16 vs 29x29, decoded image 32x32 vs 18x18 before the fix), plus regression tests.
Could a maintainer add no-issue-needed, or should I open an issue and add a closing keyword? Happy to do whichever fits the workflow. Thanks!
This branch has not been deployed
No deployments
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
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.
The bugs
AutoencoderKLHunyuanImageRefinermixes latent-space and sample-space quantities in both tiling paths.tiled_encodecuts its tiles out of the sample tensor but advances with a latent-space step:With the default tile of 256 samples and a stride of 192 samples, the loop advances 12 samples instead of 192. That encodes ~16x more tiles than needed and concatenates them into a latent far larger than the input, so
encodereturns the wrong shape.tiled_decodedoes the opposite: it walks the latent tensor correctly, but blends and crops the decoded tiles with latent-space numbers:Each decoded tile keeps 12 pixels and drops the other 244, so
decodereturns a fraction of the image.Both paths also ignore
tile_sample_stride_height/tile_sample_stride_width, whichenable_tilingstores and which every other tiled VAE (AutoencoderKLHunyuanVideo15,AutoencoderKLWan, ...) uses.Reproduction
Tiny model, spatial compression 2,
32x32input (16x16latent), tiles of16samples with a stride of12:(1, 4, 1, 16, 16)(1, 3, 1, 32, 32)main(1, 4, 1, 29, 29)(1, 3, 1, 18, 18)(1, 4, 1, 16, 16)(1, 3, 1, 32, 32)The fix
tiled_encode: advance byself.tile_sample_stride_height/width(sample space, matching the cut), and derive the latent blend/crop fromtile_latent_min_*minus the latent stride.tiled_decode: keep stepping by the latent stride, but blend bytile_sample_min_* - tile_sample_stride_*and crop totile_sample_stride_*, because the blend happens on decoded tiles.The defaults are unchanged: with
tile_sample_min = 256,tile_sample_stride = 192andtile_overlap_factor = 0.25, the latent blend is16 - 12 = 4and the sample-space blend is256 - 192 = 64, i.e. exactly what the oldint(size * factor)produced in the right space.Test
New
tests/models/autoencoders/test_models_autoencoder_hunyuanimage_refiner.pywith two shape assertions (tiled encode/decode vs the non-tiled paths). Both fail onmain(29x29 != 16x16and18x18 != 32x32) and pass with the fix.