-
Notifications
You must be signed in to change notification settings - Fork 227
perf: improve HunyuanVideo1.5 I2V runtime and VAE decode controls #1201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
starrkk
wants to merge
5
commits into
ModelTC:main
Choose a base branch
from
starrkk:codex/hunyuan-vae-i2v-runtime-optimizations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+284
−36
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6031a6f
fix: enable Hygon 8-card Hunyuan 1.5 i2v inference
99a08bb
fix: honor SLA topk environment setting
fe93150
Optimize Hunyuan VAE decode path
4ad81a4
fix: harden Hunyuan VAE runtime edge cases
3a4c4ab
style: format Hunyuan VAE runtime changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import os | ||
|
|
||
| import torch | ||
|
|
||
| from lightx2v_platform.base.global_var import AI_DEVICE | ||
|
|
||
|
|
||
| def env_flag(name, default=False): | ||
| value = os.getenv(name) | ||
| if value is None: | ||
| return default | ||
| return value.strip().lower() in ("1", "true", "yes", "on") | ||
|
|
||
|
|
||
| def has_no_video_payload(video): | ||
| if video is None: | ||
| return True | ||
| if isinstance(video, torch.Tensor): | ||
| return video.numel() == 0 | ||
| return False | ||
|
|
||
|
|
||
| def should_skip_rank_postprocess(video, rank, enabled): | ||
| return enabled and rank != 0 and has_no_video_payload(video) | ||
|
|
||
|
|
||
| def crop_spatial_to_size(video, target_height=None, target_width=None): | ||
| if not isinstance(video, torch.Tensor): | ||
| return video | ||
| if video.numel() == 0: | ||
| return video | ||
| if target_height is None and target_width is None: | ||
| return video | ||
|
|
||
| height_dim, width_dim = _spatial_dims(video) | ||
| height = video.shape[height_dim] | ||
| width = video.shape[width_dim] | ||
| crop_h = min(height, int(target_height)) if target_height is not None else height | ||
| crop_w = min(width, int(target_width)) if target_width is not None else width | ||
| if crop_h == height and crop_w == width: | ||
| return video | ||
|
|
||
| slices = [slice(None)] * video.ndim | ||
| slices[height_dim] = slice(0, crop_h) | ||
| slices[width_dim] = slice(0, crop_w) | ||
| return video[tuple(slices)].contiguous() | ||
|
|
||
|
|
||
| def sync_device_if_available(): | ||
| device_module = getattr(torch, AI_DEVICE, None) | ||
| if device_module is None: | ||
| return | ||
| synchronize = getattr(device_module, "synchronize", None) | ||
| if synchronize is not None: | ||
| synchronize() | ||
|
|
||
|
|
||
| def _spatial_dims(video): | ||
| channel_sizes = (1, 3, 4, 16, 32) | ||
| if video.ndim == 5: | ||
| # B,T,H,W,C after postprocess: last dim is the channel count. | ||
| if video.shape[-1] in (1, 3, 4): | ||
| return 2, 3 | ||
| # B,C,T,H,W before postprocess: dim 1 is latent/image channels. | ||
| if video.shape[1] in channel_sizes: | ||
| return 3, 4 | ||
| elif video.ndim == 4: | ||
| # B,H,W,C image tensor. | ||
| if video.shape[-1] in (1, 3, 4): | ||
| return 1, 2 | ||
| # B,C,H,W tensor. | ||
| if video.shape[1] in channel_sizes: | ||
| return 2, 3 | ||
| return -2, -1 |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.