Skip to content

Improvement in WAN VAE Performance - #464

Open
Toshi-31 wants to merge 1 commit into
AI-Hypercomputer:mainfrom
Toshi-31:clean-vae-pr
Open

Improvement in WAN VAE Performance#464
Toshi-31 wants to merge 1 commit into
AI-Hypercomputer:mainfrom
Toshi-31:clean-vae-pr

Conversation

@Toshi-31

@Toshi-31 Toshi-31 commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Improvement in WAN VAE Performance

Changes made:

  1. Using jnp.repeat in WAN Upsample instead of resize
  2. VAE Spatial and Temporal Parallelism (vae_spatial=8 & vae_decode_chunk=5)
  3. Host Formatting Changes: Pushes Classifier-Free Guidance (CFG) tensor duplication inside the JIT-compiled device graph to completely eliminate Python host overhead.

Performance Impact:
Tested on v6e-8 for 720p, 81-frame video. These changes reduced step timings from:

Before:

  • VAE Decode: 3.2s
    • TPU Compute: 2.8s
    • Host Formatting: 0.4s

After:

  • VAE Decode: 0.8s
    • TPU Compute: 0.8s
    • Host Formatting: 0.0s

Leading to a 75% improvement in latency.

For v7x-8, the observations are below. The improvement is not as significant as that in v6e-8.
Before:
VAE Decode: 3.6s
- TPU Compute: 2.9s
- Host Formatting: 0.7s
After:
VAE Decode: 2.9s
- TPU Compute: 2.9s
- Host Formatting: 0.0s

@Toshi-31
Toshi-31 requested a review from entrpn as a code owner August 19, 2026 05:48

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Wan pipeline and autoencoder models to support conditional sharding constraints, optimize classifier-free guidance by avoiding redundant latent concatenations, and adapt the caching logic in inference pipelines to be fully compatible with JAX tracing. The review feedback highlights several critical areas for improvement: removing @nnx.jit from VAE encoding/decoding may cause silent performance regressions in the VACE pipeline; the new nearest-neighbor upsampling using jnp.repeat needs to guard against non-integer scale factors; the use of addressable_data should be replaced with standard JAX APIs like addressable_shards to avoid slow fallbacks; and cache_count must be updated within the JAX-compatible caching loops to ensure accurate cache ratio logging.

Comment thread src/maxdiffusion/models/wan/autoencoder_kl_wan.py
Comment thread src/maxdiffusion/models/wan/autoencoder_kl_wan.py Outdated
Comment thread src/maxdiffusion/pipelines/wan/wan_pipeline.py Outdated
Comment thread src/maxdiffusion/pipelines/wan/wan_pipeline_2_2.py
Comment thread src/maxdiffusion/pipelines/wan/wan_pipeline_i2v_2p2.py
Comment thread src/maxdiffusion/models/wan/autoencoder_kl_wan.py
Comment thread src/maxdiffusion/pipelines/wan/wan_pipeline.py
@Toshi-31
Toshi-31 requested a review from csgoogle August 19, 2026 11:03

@Perseus14 Perseus14 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor changes requested.

Please squash the commits.

Comment thread src/maxdiffusion/models/wan/autoencoder_kl_wan.py Outdated
Comment thread src/maxdiffusion/models/wan/autoencoder_kl_wan.py Outdated
Comment thread src/maxdiffusion/models/wan/autoencoder_kl_wan.py
Comment thread src/maxdiffusion/models/wan/autoencoder_kl_wan.py
- Implement spatial/temporal parallelism for WAN VAE
- Replace resize with jnp.repeat for upsampling
- Resolve eager execution regression in VACE pipeline using vae_encode_pass
- Add comprehensive sharding validation and fallbacks in VAE with max_logging
- Fix multi-host addressable data logic and TeaCache tracking bugs
- Optimize pipeline formatting to reduce host overhead
- Restore profiler trace dumping functionality in generate_wan.py

@Perseus14 Perseus14 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ninatu Could you also PTAL?

@ninatu ninatu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants