Skip to content

Conversation

@DefTruth
Copy link
Contributor

@DefTruth DefTruth commented Nov 4, 2025

enable attention dispatch for huanyuan video, adapted from:

https://github.com/huggingface/diffusers/blob/ac5a1e28fc9cc233863bcfb2abb9eef6807f156f/src/diffusers/models/transformers/transformer_hunyuanimage.py#L46C7-L46C32

Example

import torch
from diffusers import HunyuanVideoPipeline
from diffusers.utils import export_to_video

pipe: HunyuanVideoPipeline = HunyuanVideoPipeline.from_pretrained(
    "hunyuanvideo-community/HunyuanVideo",
    torch_dtype=torch.bfloat16,
)

pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()

def run_pipe():
    prompt = "A cat walks on the grass, realistic"
    output = pipe(
        prompt,
        height=320,
        width=512,
        num_frames=61,
        num_inference_steps=30,
        generator=torch.Generator("cpu").manual_seed(0),
    ).frames[0]
    return output

video = run_pipe()
export_to_video(video, "huanyuan_video.mp4", fps=15)
w/o this PR w/ this PR
huanyuan_video_ori huanyuan_video

@yiyixuxu pipelines

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

thanks!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Thanks! It would be nice to have some explanation of the change of dims being introduced in this PR.

[
apply_rotary_emb(query[:, :, : -encoder_hidden_states.shape[1]], image_rotary_emb),
query[:, :, -encoder_hidden_states.shape[1] :],
apply_rotary_emb(
Copy link
Member

Choose a reason for hiding this comment

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

What's happening here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since transpose is no longer needed, at this point seq_len is located in dim=1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sayakpaul sayakpaul merged commit 9f669e7 into huggingface:main Nov 7, 2025
10 of 11 checks passed
@sayakpaul
Copy link
Member

Thanks for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants