Make WanTransformer3DModel hidden states contiguous before the block loop#14236
Conversation
…s before the block loop.
|
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. |
| # flatten+transpose produces a non-contiguous tensor; make it contiguous before the block loop. | ||
| hidden_states = hidden_states.contiguous() |
There was a problem hiding this comment.
So the pattern is that we identify the first occurrence of ops that can render the tensor in a non-contiguous layout and call contiguous() on it?
There was a problem hiding this comment.
Yes, the pattern is to ensure the inputs (especially hidden_states) are contiguous before entering the transformer block loop (see also #14186, #14203). We observed that ops like flatten+transpose or pos_embed can leave tensors in a non-contiguous memory layout, and calling .contiguous() before the loop can improve performance. The benefit is most significant on ROCm.
|
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. |
What does this PR do?
Similar to #14186
The non-contiguous tensor originates from
hidden_states.flatten(2).transpose(1, 2)produces a non-contiguous layout whose overhead accumulates across transformer blocks inWanTransformer3DModel.This patch improves performance on both CUDA and ROCm, though the gain is more pronounced on ROCm.
Benchmarks (Wan-AI/Wan2.2-TI2V-5B-Diffuser, 1280x704, 50 steps, bf16):
Before submitting
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@sayakpaul
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.