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 MagVIT tiled encoding dropping the last tile row and column - #15454
latent_height/latent_width are height // spatial_compression_ratio and width // spatial_compression_ratio of the whole input, i.e. the size of the final latent, not the size of one tile's contribution. Once the input is bigger than one tile, the crop is a no-op, the overlapping borders survive, and torch.cat(..., dim=4) places tile k at min_height * k instead of stride * k. The final crop then keeps the first latent_height entries, so the last tile row/column is silently discarded.
The neighbouring tiled_decode in the same file already crops to self.tile_sample_stride_height/width, and AutoencoderKLLTXVideo.tiled_encode crops to tile_latent_stride_*. Only the MagVIT encode path uses the full latent size.
Reproduction
Tiny MagVIT VAE (spatial compression 2, so a 16x16 input becomes an 8x8 latent), 2x2 tiles with half-tile overlap:
The final [:latent_height, :latent_width] crop stays, as it removes the tail padding.
Test
test_tiled_encode_keeps_the_last_tile in tests/models/autoencoders/test_models_autoencoder_magvit.py builds a tiny model, enables 2x2 tiling, and asserts that perturbing only the bottom-right tile changes the latent. It fails on main (max delta == 0) and passes with the fix.
Note: _encode/_decode also compare x.shape[-1] against tile_sample_min_height (height and width swapped) when deciding whether tiling is needed. That only affects when tiling triggers for non-square tiles, not correctness, so I left it out to keep this PR focused — happy to send it separately.
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.
Re the pr-link-issue-reminder: this is a self-found bug — there is no existing issue for it, so I didn't invent a Fixes #N link. The PR body contains a minimal reproduction and before/after numbers (bottom-right tile sensitivity 0.000000 -> 0.212866; tiled-vs-nontiled MAE 0.0698 -> 0.0380), plus a regression test.
If a maintainer could add the no-issue-needed label, that should silence the reminder. Happy to open an issue and link it instead if that's the preferred workflow — just let me know. Thanks!
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 bug
AutoencoderKLMagvit.tiled_encodecrops every tile to the full-image latent size instead of the tile stride:latent_height/latent_widthareheight // spatial_compression_ratioandwidth // spatial_compression_ratioof the whole input, i.e. the size of the final latent, not the size of one tile's contribution. Once the input is bigger than one tile, the crop is a no-op, the overlapping borders survive, andtorch.cat(..., dim=4)places tile k atmin_height * kinstead ofstride * k. The final crop then keeps the firstlatent_heightentries, so the last tile row/column is silently discarded.The neighbouring
tiled_decodein the same file already crops toself.tile_sample_stride_height/width, andAutoencoderKLLTXVideo.tiled_encodecrops totile_latent_stride_*. Only the MagVIT encode path uses the full latent size.Reproduction
Tiny MagVIT VAE (spatial compression 2, so a
16x16input becomes an8x8latent), 2x2 tiles with half-tile overlap:main0.000000(bottom-right tile never reaches the latent)0.212866Tiled-vs-non-tiled error on a
16x16input withtile_min=12, stride=8also drops from0.0698mean abs to0.0380.The fix
Crop each tile to its stride, so the concatenation advances by
strideand every tile lands where it belongs:The final
[:latent_height, :latent_width]crop stays, as it removes the tail padding.Test
test_tiled_encode_keeps_the_last_tileintests/models/autoencoders/test_models_autoencoder_magvit.pybuilds a tiny model, enables 2x2 tiling, and asserts that perturbing only the bottom-right tile changes the latent. It fails onmain(max delta == 0) and passes with the fix.Note:
_encode/_decodealso comparex.shape[-1]againsttile_sample_min_height(height and width swapped) when deciding whether tiling is needed. That only affects when tiling triggers for non-square tiles, not correctness, so I left it out to keep this PR focused — happy to send it separately.