GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(vae): batch spatial padding in Hunyuan causal convolutions by losewayy · Pull Request #2374 · leejet/stable-diffusion.cpp

Conversation

@losewayy

@losewayy losewayy commented Nov 17, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

Fold frames and channels into one dimension ([W, H, T * C]) via ggml_ext_cont and ggml_reshape_3d during spatial replicate_pad in Hunyuan's shared CausalConv3d, then restore the 4D shape before convolution. This avoids per-channel CUDA CONCAT kernel launches while keeping temporal padding and carry unchanged.

Related Issue / Discussion

N/A

Additional Information

Tested on RTX 5070 Ti Laptop (sm_120, CUDA 13.4, Vulkan 1.4, Windows Release) against 532d2c1. Standalone CausalConv3d checks (10 edge cases including non-contiguous views and temporal carry, plus 4 larger spatial shapes) are byte-identical on CPU, CUDA, and Vulkan separately. FP16 HunyuanVideo 1.5 VAE runs (512x288, 5 frames; 1 warmup + mean of 2 runs) produce byte-identical latents and decoded pixels on both CUDA and Vulkan.

backend / stage (512x288, 5 frames, FP16) baseline batched diff
CUDA encode 2.835 s 1.925 s -32.1%
CUDA decode 5.499 s 3.172 s -42.3%
CUDA combined 8.334 s 5.098 s -38.8%
Vulkan encode 27.002 s 26.907 s -0.4%
Vulkan decode 43.110 s 42.993 s -0.3%
Vulkan combined 70.112 s 69.900 s -0.3%

Full video generation and Metal were not tested.

Checklist

  • I have read and confirmed this PR follows the contribution guidelines.
  • If this PR adds or changes model support, I have added or updated its usage guide and relevant model index/README entries following the model documentation requirements.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of spatial padding during video processing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@losewayy
perf(vae): batch spatial padding in Hunyuan causal convolutions
021d382
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

CausalConv3d::forward now makes its input contiguous and combines frame and channel dimensions before spatial replicate padding. It restores the tensor shape after padding. Temporal padding and convolution behavior remain unchanged.

Changes: Hunyuan VAE spatial padding

Layer / File(s) Summary
Prepare the tensor for spatial padding
src/model/vae/hunyuan_vae.hpp
CausalConv3d::forward combines the frame and channel dimensions before spatial replicate padding, then restores the four-dimensional shape.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related PRs

  • leejet/stable-diffusion.cpp#2369: Applies the same frame-and-channel reshape technique to spatial padding in the H3 encoder.

Suggested reviewers: leejet

Merge Risk: Minimal · up to 021d3

This change batches spatial padding in the Hunyuan VAE convolutions to speed up CUDA encode and decode. No concrete defect was found, and the author reports identical outputs on the platforms tested. Merge risk is minimal, though Metal was not tested.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: batching spatial padding in the Hunyuan causal convolutions for performance. The raw summary confirms that CausalConv3d::forward now folds frames and channels into one…
Description check Passed The description follows the template. It has a Summary that explains the change and why it was made. It has a Related Issue / Discussion section marked N/A. It has an Additional Information section wi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: batching spatial padding in the Hunyuan causal convolutions for performance. The raw summary confirms that CausalConv3d::forward now folds frames and channels into one dimension for spatial replicate padding, then restores the 4D shape. The title follows the conventional commit format and is specific enough for a scan of the history.

Full details: Description check

Explanation

The description follows the template. It has a Summary that explains the change and why it was made. It has a Related Issue / Discussion section marked N/A. It has an Additional Information section with detailed test hardware, backends, edge-case coverage, and a timing table. The Checklist is complete and both items are checked. The description does not include an HTML comment placeholder, and the template's comments were removed, which is expected.

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.

Share

  • X
  • Mastodon
  • Reddit
  • LinkedIn
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0ae6cb56-f70c-4471-9711-bbca8670a706
Commits

Reviewing files that changed from the base of the PR and between 532d2c1 and 021d382.

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; 6 remain after this review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@leejet
leejet merged commit 6874e49 into leejet:master Nov 22, 2026
12 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@leejet

leejet commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Thank you for your contribution.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@milton-mla milton-mla Bot mentioned this pull request Nov 22, 2026
chore(container): update image ghcr.io/leejet/stable-diffusion.cpp ( 99fe301 → 981d147 ) 1Solon/Home-Server-Configuration#3065
Merged
1 task
filve pushed a commit to filve/diffusione-in-tempo-reale that referenced this pull request Nov 24, 2026
@claude
Merge leejet/stable-diffusion.cpp 9e7eed7 into fork-pull (sync 4/4, p…
bfefd6a
…art 1)

The last step towards upstream master comes in three parts. This first
one takes the commits before the Diffusion Graph Language rewrite:

- two unused ggml compat functions removed, so the library links
  against a shared libggml 1.0.0 (leejet#2363);
- asym_w4a8_int8 defaults to group size 16, as in ComfyUI (leejet#2388);
- batched spatial padding in the Hunyuan causal convolutions (leejet#2374)
  and fewer CUDA launches in the H3 VAE encoder (leejet#2369);
- documentation: Windows ROCm 0xC0000135, Off Grid AI, the server's
  browser notification (leejet#2356, leejet#2372, leejet#2318).

The merge is clean; no fork code changes.

Verified with a CPU build: the library, sd-cli and sd-server build, and
all nine unit-test programs pass.

Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
@losewayy losewayy mentioned this pull request Nov 25, 2026
perf(hunyuan_vae): fold spatial dims before 4D temporal padding and concat #2421
Open
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@losewayy @leejet
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.