Skip to content
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

reduce transpose operations to speedup #589

Merged
merged 4 commits into from
Feb 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ def forward(
"""
# 1. Input
batch_frames, _, height, width = hidden_states.shape
hidden_states_in = hidden_states
num_frames = image_only_indicator.shape[-1]
batch_size = batch_frames // num_frames

Expand All @@ -382,9 +381,11 @@ def forward(
# height * width, batch_size, 1, time_context.shape[-1]
# )
# Rewrite for onediff SVD dynamic shape
broadcast_tensor = hidden_states.flatten(2, 3).permute(2, 0, 1)
time_context = torch._C.broadcast_dim_like(
time_context_first_timestep[None, :], broadcast_tensor, dim=0
time_context_first_timestep[None, :],
hidden_states.flatten(2, 3),
dim=0,
like_dim=2,
)
# time_context = time_context.reshape(height * width * batch_size, 1, time_context.shape[-1])
# Rewrite for onediff SVD dynamic shape
Expand Down Expand Up @@ -450,7 +451,9 @@ def forward(
# hidden_states = hidden_states.reshape(batch_frames, height, width, inner_dim).permute(0, 3, 1, 2).contiguous()
# Rewrite for onediff SVD dynamic shape
hidden_states = (
hidden_states.permute(0, 2, 1).reshape_as(hidden_states_in).contiguous()
hidden_states.reshape_as(residual.permute(0, 2, 3, 1))
.permute(0, 3, 1, 2)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reshape后面的permute得保留,避免破坏NCHW->NHWC转换后permute消除的优化。

.contiguous()
)

output = hidden_states + residual
Expand Down
Loading