ThunderKittens kernels for hopper - #1
Open
kesavanramakrishnan wants to merge 2 commits into
Open
Conversation
Owner
|
Cool! Will review this soon. Is it possible to have this build at runtime using optional CUDA packages from PyPI instead of requiring it to be prebuilt? Do you also know what the gains are from optimizing out the additional pass in Pallas? |
Owner
|
Also if you can provide an NCU profile (with the Pallas as a baseline) and comment on where the savings are that would be great |
Collaborator
Author
|
Hey! Just updated the commit to allow for runtime build w pypi and will address rest in dms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wrote TK kernels to replace the slower pallas path targeting the hopper arch.
Kernels are pretty straightforward, they are warp spec, 2 consumer 1 producer, using wgmma and tma and deeper pipelining than the pallas kernels.
Stage 1 kernel:
Identical to pallas kernel, except we only do 2 passes over the k-dim per query vs the 3.
we are able to decompose B into the sum of (dPa - dP*dD - ddS * D + dP * ddS) which we can expand and see these terms are independent of each other allowing us to do the reductions in the first sweep and then do the output in the second sweep (since these are just row-wise scalars it doesn't introduce much memory overhead we can keep in registers)
Stage 2 kernel:
algorithmically identical to pallas kernel
shapes supported are:
causal only
head dim: 64 (can be expanded to 128 just reduce pipeline depth)
seq len: seq % 128 == 0
performance:
end-to-end HVP times (fwd + bwd + double-backward)
usage: see Readme
work done by me and @nick-rui