Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Performance 2/6] Replace einops.rearrange with torch native ops#15804

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
AUTOMATIC1111 merged 1 commit intoAUTOMATIC1111:devfromhuchenlei:rearrange_fix
Jun 8, 2024

Conversation

@huchenlei
Copy link
Contributor

@huchenleihuchenlei commentedMay 15, 2024
edited
Loading

Description

According tolllyasviel/stable-diffusion-webui-forge#716 (comment),einops.rearrange calls in crossattn is causing extra overhead. Replacing it with torch native ops can save ~55ms/it.

Screenshots/videos:

image

TODO

There are other places whereeinops.rearrange can be replaced by torch native ops, but this one in CrossAttn is the most critical one. Instrument the usage ofeinops.rearrange elsewhere might also yield some improvements.

Checklist:

NXTler reacted with thumbs up emoji
"""
b,n,_=t.shape# Get the batch size (b) and sequence length (n)
d=t.shape[2]//h# Determine the depth per head
returnt.reshape(b,n,h,d)
Copy link
Contributor

Choose a reason for hiding this comment

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

t.reshape(b,n,h,-1) should achieve similar result without having to explicitly calculated


q=_reshape(q_in)
k=_reshape(k_in)
v=_reshape(v_in)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be done in 1 line withq, k, v = (_reshape(t) for t in (q_in, k_in, v_in))

@AUTOMATIC1111AUTOMATIC1111 merged commitde7f5cd intoAUTOMATIC1111:devJun 8, 2024
lllyasviel added a commit to lllyasviel/stable-diffusion-webui-forge that referenced this pull requestAug 8, 2024
wkpark added a commit to wkpark/stable-diffusion-webui that referenced this pull requestSep 8, 2024
 * replace rearrange to viewAUTOMATIC1111#15804   * see alsolllyasviel/stable-diffusion-webui-forge@79adfa8 * conditional use torch.rms_norm for torch 2.4 * fix RMSNorm() for clear: use torch.ones()
wkpark added a commit to wkpark/stable-diffusion-webui that referenced this pull requestSep 8, 2024
 * replace rearrange to viewAUTOMATIC1111#15804   * see alsolllyasviel/stable-diffusion-webui-forge@79adfa8 * conditional use torch.rms_norm for torch 2.4 * fix RMSNorm() for clear: use torch.ones()
ruchej pushed a commit to ruchej/stable-diffusion-webui that referenced this pull requestSep 30, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@AUTOMATIC1111AUTOMATIC1111AUTOMATIC1111 approved these changes

+2 more reviewers

@wfjswwfjswwfjsw left review comments

@gel-crabsgel-crabsgel-crabs left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@huchenlei@wfjsw@AUTOMATIC1111@gel-crabs

[8]ページ先頭

©2009-2025 Movatter.jp