Skip to content

head, seq, batch grid order for triton flash attention bwd. #141

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

Merged
merged 1 commit into from
May 16, 2025

Conversation

Chi-Chu319
Copy link

Change the grid order for triton flash attention bwd.

The grid is changed to head, seq, batch. It provides the following benefits

  1. having head as the first dim with the assumption of head % 8 (number of XCD) == 0 keeps each entire sequence on one XCD so good causal load balancing between XCDs. and good sequence locality
  2. having the batch as the last makes sure all the XCD gets all the batches so the THD load balancing is achieved.

suppose we have head // num_XCD = x
each XCD would get (xcd_id * x + (xcd_id + 1) * x, ..., ...), with the grid (head, seq, batch) (we know that the first dim moves the first).

perf on Mi300:
main_perf:
image
this branch:
image

perf on mi350:
main_perf:
image
this branch:
image

@Chi-Chu319 Chi-Chu319 self-assigned this May 15, 2025
@Chi-Chu319 Chi-Chu319 changed the title head, seq, batch head, seq, batch grid order for triton flash attention bwd. May 15, 2025
@Chi-Chu319 Chi-Chu319 marked this pull request as ready for review May 16, 2025 03:06
@micmelesse micmelesse merged commit ed85dc8 into main_perf May 16, 2025
3 of 4 checks passed
micmelesse pushed a commit that referenced this pull request Jul 18, 2025
micmelesse pushed a commit that referenced this pull request Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants