Skip to content

Make HunyuanDiT2DModel and HunyuanDiT2DControlNetModel hidden states contiguous#14203

Open
menglcai wants to merge 1 commit into
huggingface:mainfrom
menglcai:menglcai/update_hunyuan_dit_hunyuan
Open

Make HunyuanDiT2DModel and HunyuanDiT2DControlNetModel hidden states contiguous#14203
menglcai wants to merge 1 commit into
huggingface:mainfrom
menglcai:menglcai/update_hunyuan_dit_hunyuan

Conversation

@menglcai

Copy link
Copy Markdown
Contributor

What does this PR do?

Similar to #14186

The non-contiguous tensor originates from PatchEmbed.forwardflatten(2).transpose(1, 2) (BCHW → BNC) produces a non-contiguous layout whose overhead accumulates across transformer blocks in HunyuanDiT2DModel and HunyuanDiT2DControlNetModel.
Unlike SD3 where the benefit is limited to ROCm, this patch improves performance on both ROCm and NVIDIA for HunyuanDiT, though the gain on NVIDIA is smaller.

Benchmarks (HunyuanDiT-v1.1-Diffusers, 512×512, 50 steps, fp16):

Platform PyTorch Default +contiguous Speedup
NVIDIA RTX 5090 2.12.1+cu132 3.16 it/s 3.29 it/s +4.1%
AMD Radeon AI PRO R9700 (gfx1201) 2.12.0+rocm7.15.0a20260713 1.34 it/s 1.52 it/s +13.4%
AMD Radeon(TM) 8060S Graphics (gfx1151) 2.12.0+rocm7.15.0a20260711 3.23 s/it 3.05 s/it +5.8%

Benchmarks (HunyuanDiT-v1.2-Diffusers, 512×512, 50 steps, fp16):

Platform PyTorch Default +contiguous Speedup
NVIDIA RTX 5090 2.12.1+cu132 3.16 it/s 3.30 it/s +4.4%
AMD Radeon AI PRO R9700 (gfx1201) 2.12.0+rocm7.15.0a20260713 1.35 it/s 1.53 it/s +13.3%
AMD Radeon(TM) 8060S Graphics (gfx1151) 2.12.0+rocm7.15.0a20260711 3.23 s/it 3.05 s/it +5.6%

Benchmarks (HunyuanDiT-v1.2-ControlNet-Diffusers-Canny + HunyuanDiT-v1.2-Diffusers-Distilled, 512×512, 50 steps, fp16):

Platform PyTorch Default +contiguous Speedup
NVIDIA RTX 5090 2.12.1+cu132 2.12 it/s 2.26 it/s +6.6%
AMD Radeon AI PRO R9700 (gfx1201) 2.12.0+rocm7.15.0a20260713 1.13 s/it 1.04 it/s +8.0%
AMD Radeon(TM) 8060S Graphics (gfx1151) 2.12.0+rocm7.15.0a20260711 4.73 s/it 3.79 s/it +19.9%

Before submitting

  • Did you use an AI agent (Claude Code, Codex, Cursor, etc.) to help with this PR? If so:
    • Did you read the Coding with AI agents guide?
    • Did you run the self-review skill on the diff?
    • Did you share the final self-review notes in the PR description or a comment?
  • Did you read the contributor guideline?
  • Did you read our philosophy doc? (important for complex PRs)
  • Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?
  • Are you the author (or part of the team) of the model/pipeline (only applicable for model/pipeline related PRs)?

Who can review?

@sayakpaul @yiyixuxu

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@github-actions github-actions Bot added models size/S PR with diff < 50 LOC labels Jul 16, 2026
@sayakpaul

Copy link
Copy Markdown
Member

Thanks for your PR. Instead of Hunyuan, do we want to treat another model that has popularity and more usage?

@github-actions

Copy link
Copy Markdown
Contributor

Hi @menglcai, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

@menglcai

Copy link
Copy Markdown
Contributor Author

Thanks for your PR. Instead of Hunyuan, do we want to treat another model that has popularity and more usage?

Understood, I'll look into more popular or widely used models and open a follow-up PR if a similar fix applies.

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

Labels

models size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants