Skip to content

[bugfix]: fix VAE temporal tiling blend corruption in tiled_encode - #1181

Merged
mergify[bot] merged 6 commits into
hao-ai-lab:mainfrom
FoundationResearch:bugfix/train/hunyuanvae
Mar 29, 2026
Merged

mergify[bot] merged 6 commits into
hao-ai-lab:mainfrom
FoundationResearch:bugfix/train/hunyuanvae

Conversation

@alexzms

@alexzms alexzms commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fix tiled_encode() using pixel-space blend_num_frames in latent space, causing severe quality loss (PSNR 25.7 → 38.6 dB after fix)
  • Add HunyuanVideo overfit config and preprocessing script

Details

blend_num_frames was computed in pixel space (16 - 12 = 4) but used directly as latent-space blend extent in tiled_encode(). With 4x temporal compression, only ~1 latent frame overlaps between tiles, but 4 were blended, thus overwriting unrelated content. Fix: divide by temporal_compression_ratio when blending in latent space. Decode paths are unaffected (they blend in pixel space).
Other models vae will not get affected theoretically

Test plan

  • VAE round-trip encode→decode PSNR: 25.74 → 38.57 dB (spatial-only reference: 39.30 dB)
  • HunyuanVideo overfit training with preprocessed data

alexzms added 5 commits March 25, 2026 20:13
HunyuanVideo is ~13B params and OOMs with replicate-only FSDP.
Switch to hsdp_shard_dim=8 to shard across all GPUs. Add smoke
test config that uses Wan data (shapes match) for quick iteration.
…ript

- Replace smoke test config with overfitting config (500 steps,
  higher LR, validation every 100 steps, precondition_outputs)
- Add preprocess_hunyuan_overfit.py for encoding small video sets
  with HunyuanVideo VAE + LLaMA + CLIP into parquet format
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical bug in the VAE's temporal tiling encoding process that was causing severe corruption and quality loss in generated videos. By ensuring that temporal blending in latent space correctly accounts for the temporal_compression_ratio, the change significantly enhances the fidelity of VAE outputs. Additionally, it provides new tools for validating the HunyuanVideo training pipeline through dedicated overfitting tests, improving overall system robustness and development efficiency.

Highlights

  • Bug Fix: VAE Temporal Tiling Blending: Corrected an issue in the tiled_encode() function where pixel-space blend_num_frames was incorrectly applied in latent space, leading to significant quality degradation. The fix involves dividing blend_num_frames by the temporal_compression_ratio for accurate latent space blending.
  • Improved VAE Encoding Quality: The bug fix dramatically improved the VAE's round-trip encode-decode PSNR from 25.74 dB to 38.57 dB, bringing it closer to the spatial-only reference of 39.30 dB.
  • HunyuanVideo Overfit Configuration: Introduced a new configuration file and a preprocessing script to support overfitting tests for the HunyuanVideo model, ensuring the end-to-end functionality of the training pipeline.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

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

Copy link
Copy Markdown
Contributor

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 introduces a new configuration for HunyuanVideo T2V overfitting and a new preprocessing script for this data. It also includes a change in the VAE's tiled_encode method to adjust blending frames based on temporal compression. Review comments suggest moving imports to the top of the preprocessing script for better organization and removing an unused variable (num_latent_t) for clarity.

Comment on lines +98 to +100
from transformers import AutoTokenizer, CLIPTextModel, LlamaModel
from fastvideo.configs.pipelines.hunyuan import (
HunyuanConfig, LlamaConfig, CLIPTextConfig)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For improved code organization and to adhere to standard Python style conventions (PEP 8), all imports should be placed at the top of the file. This makes dependencies clear and avoids potential issues with delayed imports. Please move these transformers and fastvideo imports to the top-level of the script.

Comment on lines +171 to +172
# Compute latent frames
num_latent_t = latent.shape[1]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The variable num_latent_t is assigned but never used. The accompanying comment is also slightly misleading. To improve code clarity, this unused variable and its comment should be removed.

@SolitaryThinker SolitaryThinker added the ready PR is ready to merge label Mar 26, 2026
@mergify mergify Bot added the vae label Mar 29, 2026
@mergify

mergify Bot commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Pre-commit checks failed

Hi @alexzms, the pre-commit checks have failed. To fix them locally:

# Install pre-commit if you haven't already
uv pip install pre-commit
pre-commit install

# Run all checks and auto-fix what's possible
pre-commit run --all-files

Common fixes:

  • yapf: yapf -i <file> (formatting)
  • ruff: ruff check --fix <file> (linting)
  • codespell: codespell --write-changes <file> (spelling)

After fixing, commit and push the changes. The checks will re-run automatically.

For future commits, pre-commit will run automatically on changed files before each commit.

@mergify mergify Bot added the pipeline label Mar 29, 2026
Remove unused variable num_latent_t, add type annotations for mypy,
and apply yapf formatting.
@mergify
mergify Bot merged commit 2085a4f into hao-ai-lab:main Mar 29, 2026
8 checks passed
Satyam-53 pushed a commit to Satyam-53/FastVideo that referenced this pull request Apr 4, 2026
shijiew555 pushed a commit to Gary-ChenJL/FastVideo that referenced this pull request Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready PR is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants