Repository navigation
[TRTLLM-14123][feat] add ParallelVAE_TrtllmWan for native Wan VAE - #16066
Conversation
402a01c to
3d4d22d
Compare
📝 WalkthroughWalkthroughWan VAE loading now uses environment-controlled backend selection. ChangesWan VAE integration
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Pipeline
participant load_wan_vae
participant ParallelVAEFactory
participant ParallelVAE_TrtllmWan
participant WanVAE
Pipeline->>load_wan_vae: load checkpoint, device, and dtype
load_wan_vae->>WanVAE: construct native backend when env flag is zero
WanVAE->>ParallelVAEFactory: resolve native WanVAE type
ParallelVAEFactory->>ParallelVAE_TrtllmWan: create parallel adapter
ParallelVAE_TrtllmWan->>WanVAE: replace native convolution and attention modules
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tensorrt_llm/_torch/visual_gen/models/wan/vae_loader.py (1)
64-68: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDocument the public loader API.
Line 64 is called across pipeline modules but has no Google-style docstring documenting its backend-selection behavior, arguments, and return value.
As per coding guidelines, externally called functions should have docstrings, and their arguments should be documented.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tensorrt_llm/_torch/visual_gen/models/wan/vae_loader.py` around lines 64 - 68, The public load_wan_vae function lacks API documentation. Add a Google-style docstring to load_wan_vae describing its backend-selection behavior, checkpoint_dir, device, and dtype arguments, and the returned nn.Module.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unittest/_torch/visual_gen/multi_gpu/test_parallel_vae.py`:
- Around line 140-172: Add complete type annotations to the new helper and test
functions, including concrete parameter types and -> None return annotations for
test_* methods; cover the distributed helper functions and all additions through
the referenced range, including _create_small_trtllm_vae and
_create_parallel_trtllm_vae.
- Around line 140-172: Coverage is insufficient in
tests/unittest/_torch/visual_gen/multi_gpu/test_parallel_vae.py: the native VAE
disables attention and directly constructs the wrapper. Add an attention-enabled
WanVAE case to exercise _replace_attention() for WanAttentionBlock, and add a
ParallelVAEFactory test asserting supports(WanVAE) and from_vae(...) return
ParallelVAE_TrtllmWan.
---
Nitpick comments:
In `@tensorrt_llm/_torch/visual_gen/models/wan/vae_loader.py`:
- Around line 64-68: The public load_wan_vae function lacks API documentation.
Add a Google-style docstring to load_wan_vae describing its backend-selection
behavior, checkpoint_dir, device, and dtype arguments, and the returned
nn.Module.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 16e51f25-3f16-4631-b0ee-5a82930318ce
📒 Files selected for processing (6)
tensorrt_llm/_torch/visual_gen/models/wan/parallel_vae.pytensorrt_llm/_torch/visual_gen/models/wan/pipeline_wan.pytensorrt_llm/_torch/visual_gen/models/wan/pipeline_wan_i2v.pytensorrt_llm/_torch/visual_gen/models/wan/vae_loader.pytensorrt_llm/_torch/visual_gen/modules/vae/parallel_vae_interface.pytests/unittest/_torch/visual_gen/multi_gpu/test_parallel_vae.py
2f4f1a1 to
668ac14
Compare
NVShreyas
left a comment
There was a problem hiding this comment.
LGTM overall. Naive question - why is WANVae needed if WAN can use diffusers VAE directly?
|
Thanks @NVShreyas ! The diffusers AutoencoderKLWan is a third-party module we can’t easily optimize, while the native WanVAE lets us directly apply TRT-LLM optimizations (channels-last kernel, FP4 quant, kernel fusion). On single-GPU VAE decode (Wan2.2-TI2V-5B, 720p), channels-last gives 1.29× vs diffusers, and FP4 conv quant + RMSNorm/SiLU→quant fusion (WIP) brings it to ~2.0×. This will matter more for few-step or distilled models (e.g., FastWan) |
|
/bot run |
|
PR_Github #59386 [ run ] triggered by Bot. Commit: |
|
PR_Github #59386 [ run ] completed with state
|
Add a tensor-parallel wrapper (ParallelVAE_TrtllmWan) for the native WanVAE, enabling multi-GPU (parallel_vae_size > 1) VAE decode/encode with the native VAE instead of falling back to the diffusers AutoencoderKLWan. - ParallelVAE_Wan is parameterized on the replaced conv3d/attention module classes (_conv3d_cls/_attn_cls); ParallelVAE_TrtllmWan is a small subclass that overrides only those to target the native wan_vae classes. - vae_loader drops the parallel-VAE gate so the native WanVAE is used when parallel_vae_size > 1; ParallelVAEFactory registers WanVAE -> ParallelVAE_TrtllmWan. - HaloExchangeConv / HaloExchangeConv2dStride2 preserve channels-last across the halo cat (conv.py). The native WanVAE convs run in channels-last (NHWC); the halo exchange built row-major send/recv buffers, so the boundary cat fell back to row-major and every halo'd conv re-converted the full tensor. A shared _spatial_channels_last_format helper materialises the halo slices in x's memory format before the cat, keeping it channels-last so the conv's channels-last conversion becomes a no-op. Bit-identical output; ~23% faster parallel decode (1.31x, Wan2.2-TI2V-5B 720p, 4x GB200). - Tests: the multi-GPU parallel-VAE tests cover the native adapter (decode/encode, width/height split) and route through ParallelVAEFactory so the WanVAE -> ParallelVAE_TrtllmWan registration is exercised; a CPU unit test covers the channels-last halo helper; test_wan_vae is updated for the vae_loader signature change (the visual_gen_mapping parameter was removed). ParallelVAE_Wan is kept for the diffusers AutoencoderKLWan still used by Cosmos3 and the TRTLLM_USE_DIFFUSER_VAE fallback. Verified VAE-only on 4x GB200 (BF16): native-parallel matches diffusers-parallel / single-GPU to ~58-60 dB PSNR (parallelization adds negligible error) and is faster than both the diffusers parallel VAE and the single-GPU native VAE (Wan2.2-TI2V-5B 720p: 2.29x over single-GPU; Wan2.1-T2V-1.3B 480p: 1.24x). Signed-off-by: Taian Zhang <taianz@nvidia.com>
668ac14 to
389bcb9
Compare
|
/bot run |
|
PR_Github #59447 [ run ] triggered by Bot. Commit: |
|
PR_Github #59447 [ run ] completed with state |
Summary by CodeRabbit
New Features
TRTLLM_USE_DIFFUSER_VAEenvironment setting.Bug Fixes
Tests
Description
Adds
ParallelVAE_TrtllmWan, a tensor-parallel (parallel_vae_size > 1) wrapper for the nativeWanVAE(added in #15555), so multi-GPU Wan VAE decode/encode uses the native VAE instead of falling back to the diffusersAutoencoderKLWan. It mirrors the existingParallelVAE_Wanby parameterizing the replaced conv3d / attention module classes (_conv3d_cls/_attn_cls) and overriding only those in a small subclass;vae_loaderno longer forces diffusers underparallel_vae_size > 1;ParallelVAEFactoryregistersWanVAE -> ParallelVAE_TrtllmWan.ParallelVAE_Wanis kept because it wraps the diffusersAutoencoderKLWanstill used by Cosmos3 and theTRTLLM_USE_DIFFUSER_VAEfallback.This PR also includes a channels-last (NHWC) fix in
HaloExchangeConv/HaloExchangeConv2dStride2(conv.py): the halo exchange built row-major send/recv buffers, so the boundarytorch.catfell back to row-major and forced every halo'd conv to re-convert the full tensor. A shared_spatial_channels_last_formathelper now materialises the halo slices inx's memory format before the cat, keeping it channels-last so the native VAE convs (which run in channels-last) skip the re-conversion. Output is bit-identical.Performance & accuracy (4×GB200, BF16, Wan2.2-TI2V-5B, 720p / 81 frames)
Test Coverage
tests/unittest/_torch/visual_gen/multi_gpu/test_parallel_vae.py—TestParallelVAETrtllmDecode/TestParallelVAETrtllmEncode: nativeWanVAEparallel decode/encode match single-GPU (width + height split, 2-GPU). The wrapper is built viaParallelVAEFactory.from_vae, so theWanVAE -> ParallelVAE_TrtllmWanregistry mapping is exercised (with an explicitisinstanceassert). The small test VAE keeps a mid-blockWanAttentionBlock, so_replace_attentionon native attention is covered.tests/unittest/_torch/visual_gen/multi_gpu/test_parallel_conv.py—TestSpatialChannelsLastFormat: CPU unit tests for the channels-last halo helper (memory-format detection +catpreservation).tests/unittest/_torch/visual_gen/test_wan_vae.py— updated_use_native_wan_vae/load_wan_vaetests for the removedvisual_gen_mappingparameter (backend selection is now env-only viaTRTLLM_USE_DIFFUSER_VAE).PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.