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
perf(hunyuan_vae): fold spatial dims before 4D temporal padding and concat - #2421
Fold spatial dimensions together before temporal padding in CausalConv3d and before temporal concats in Downsample and Decoder, then restore the 4D shape. This avoids per-channel CUDA CONCAT kernel launches on the 3rd dimension.
When the current chunk is shorter than pad_t, build the temporal carry directly from previous and input instead of slicing the temporary prefix, so the prefix buffer can be freed before the next chunk runs.
Tested on Windows with an RTX 5070 Ti Laptop GPU and CUDA 13.4 using FP16 HunyuanVideo 1.5 VAE weights. All tested CUDA, Vulkan, and CPU outputs match master bit-for-bit.
CUDA FP16 HunyuanVideo 1.5 VAE
master (enc / dec / total)
PR (enc / dec / total)
Speedup
512x288, 5 frames
1.96 s / 3.27 s / 5.23 s
0.81 s / 1.25 s / 2.06 s
2.54x
256x144, 33 frames
6.66 s / 13.82 s / 20.48 s
1.32 s / 2.00 s / 3.32 s
6.17x
1280x720, 17 frames, 256x144 tile
109.61 s / 216.83 s / 326.44 s
24.82 s / 39.28 s / 64.10 s
5.09x
Under nsys on 256x144 with 33 frames, total CUDA kernel launches drop from 1,130,904 to 5,598, and dim-2 concat_cont launches drop from 1,125,822 to 0. On Vulkan at 512x288 with 5 frames, warm runtime stays around 13 s and decode workspace stays at 7.15 GB on both master and this branch. CPU at 256x144 with 1 frame matches master. Full video generation and Metal were not tested.
No actionable comments were generated in the recent review.
Walkthrough
The Hunyuan VAE now uses flattened tensor operations for temporal padding and carry in causal convolution. Downsampling and decoding use a helper to concatenate temporal segments and restore video dimensions.
Changes: Hunyuan VAE temporal frame handling
Layer / File(s)
Summary
Causal convolution padding and carry src/model/vae/hunyuan_vae.hpp
CausalConv3d::forward forms temporal padding and continuation carry with flattened tensor operations. It validates carry dimensions and handles chunks shorter than the padding length.
Downsample and decoder concatenation src/model/vae/hunyuan_vae.hpp
Downsample::forward and Decoder::forward use concat_video_frames to join temporal segments.
This change reduces CUDA kernel launches in the Hunyuan VAE temporal handling while reporting identical outputs on the tested backends. No concrete defect was found. Metal and full video generation were not tested.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names a performance change (folding spatial dimensions before temporal padding and concat in the HunyuanVAE code). The raw summary and objectives confirm this is the main change: CausalConv3…
Description check
The description follows the repository template in substance. It has a Summary that explains what changed and why (fewer per-channel CUDA CONCAT launches, and a shorter-than-pad_t carry built from pre…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names a performance change (folding spatial dimensions before temporal padding and concat in the HunyuanVAE code). The raw summary and objectives confirm this is the main change: CausalConv3d, Downsample and Decoder now flatten spatial dims before temporal operations and restore the 4D shape. The title is specific, concise and matches the changeset.
Full details: Description check
Explanation
The description follows the repository template in substance. It has a Summary that explains what changed and why (fewer per-channel CUDA CONCAT launches, and a shorter-than-pad_t carry built from previous and input). It has a Related Issue section linking follow-up to #2374. It has an Additional Information section with test hardware, benchmark tables, nsys counts, and untested areas. The Checklist is present with the contribution guidelines item checked. The model-documentation checklist item is absent, but this PR changes internal VAE performance code rather than adding model support, so that omission is non-critical.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 64bdb405-66f8-45a4-92b8-c856f782db8f
Commits
Reviewing files that changed from the base of the PR and between 5fa203c and 98ce463.
Files selected for processing: 1
src/model/vae/hunyuan_vae.hpp
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
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.
Summary
Fold spatial dimensions together before temporal padding in
CausalConv3dand before temporal concats inDownsampleandDecoder, then restore the 4D shape. This avoids per-channel CUDACONCATkernel launches on the 3rd dimension.When the current chunk is shorter than
pad_t, build the temporal carry directly frompreviousandinputinstead of slicing the temporary prefix, so the prefix buffer can be freed before the next chunk runs.Related Issue / Discussion
Follow-up to #2374.
Additional Information
Tested on Windows with an RTX 5070 Ti Laptop GPU and CUDA 13.4 using FP16 HunyuanVideo 1.5 VAE weights. All tested CUDA, Vulkan, and CPU outputs match
masterbit-for-bit.master(enc / dec / total)512x288, 5 frames256x144, 33 frames1280x720, 17 frames,256x144tileUnder
nsyson256x144with 33 frames, total CUDA kernel launches drop from 1,130,904 to 5,598, and dim-2concat_contlaunches drop from 1,125,822 to 0. On Vulkan at512x288with 5 frames, warm runtime stays around 13 s and decode workspace stays at 7.15 GB on bothmasterand this branch. CPU at256x144with 1 frame matchesmaster. Full video generation and Metal were not tested.Checklist
Summary by CodeRabbit