fix(ltx2): Fix VAE timing regression for large batch sizes#421
Merged
Conversation
Fixes a massive execution time regression (68s) in VAE decode by explicitly replicating VAE weights even when latents are batch-sharded. This forces XLA into an optimal data-parallel path, restoring the fast ~2s execution time while retaining batch-sharding OOM protections.
27eda58 to
96e9d82
Compare
prishajain1
approved these changes
Jun 17, 2026
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.
Fix VAE timing regression for large batch sizes
Root Cause:
In commit 7b28885, an optimization was added to prevent OOM errors for large batch sizes (
batch_size > 2) by batch-sharding the latents and disabling sequential slicing. However, this logic used anelif replicate_vae:block, which caused the explicit replication of VAE weights to be entirely skipped for large batch sizes.Without explicit weight replication, the XLA SPMD partitioner attempts to match the sharding of the input
latents(which are batch-sharded) with the VAE decode computation. Becausevae.decodeinvolves fully-replicated noise injection and massive 3D convolutions, XLA heuristically decides to insert enormous amounts of cross-device communication (AllGather/AllReduce) to shard the weights or activations, ballooning the execution time from ~2.8s to ~68.5s for non-upsampled latents.(Note: For upsampled latents, the memory layout generated by the JIT-compiled upsampler bypasses this XLA heuristic trap, allowing it to execute quickly in ~1.5s, which masked the issue).
Fix:
This PR decouples the batch-sharding of
latentsfrom the replication of VAE weights. It explicitly applies a full replication constraintNamedSharding(mesh, P())to the VAE weights in all cases wherereplicate_vaeis True, even iflatentsare batch-sharded. This forces XLA into the optimal data-parallel compilation path, restoring the fast ~1.5s - ~2.8s execution time for all scenarios without risking the concatenation-related OOMs.