Llama Kernel integration#37092
Conversation
|
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the |
ArthurZucker
left a comment
There was a problem hiding this comment.
Love the updates for rms and mlp!
Attention needs a bit more tinkering !
🤗 happy to hear your opinion as well!
| class LlamaAttention(nn.Module): | ||
| """Multi-headed attention from 'Attention Is All You Need' paper""" | ||
|
|
||
| use_kernel: bool = False |
There was a problem hiding this comment.
to remove!
Using kernels for that layer should IMO still be done via the attn_implementation!
it should give a bit more freedom to use kernels for the rest, and use sdpa or flex or paged or whatever here!
Attn is something that can change very easily, which is why I thought ALL_ATTENTION_FUNCTIONS was a better entry point!
There was a problem hiding this comment.
Do you mean we pass something like attn_implementation="use_kenrel" in from_pretrained and then add a decorator with the name of the layer to use in the attention class ?
There was a problem hiding this comment.
Yes something along those lines. Or you can just say attn_implementation="kernels-community/paged-attention" something like this. (with extra (kernel_config = "...")
I don't know the answer but the simpler the better!
There was a problem hiding this comment.
I changed the implementation so that we need to pass attn_implementation="use_kernel" and a kernel_config following the structure :
kernel_config={ "repo_id": "medmekk/triton-flash-attn", "kernel_name": "attention" }
| _CONFIG_FOR_DOC = "LlamaConfig" | ||
|
|
||
|
|
||
| @use_kernel_forward_from_hub("LlamaRMSNorm") |
|
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. |
ArthurZucker
left a comment
There was a problem hiding this comment.
Missing some docs a but marvelous
| ' We recommend to just use `attn_implementation="flash_attention_2"` when loading the model.' | ||
| ) | ||
|
|
||
| if config._attn_implementation == "use_kernel": |
There was a problem hiding this comment.
I would allso support for example passing a repo _id directly no? We can get the device ourselves, this way its easy to just use 1 arg for simplicity!
There was a problem hiding this comment.
We can create:
"cuda": LayerRepository(
repo_id="medmekk/triton-llama-mlp",
layer_name="TritonLlamaMLP",
)base on the cls name for example
There was a problem hiding this comment.
we can have a func wrapper in integration / hub kernels or something
There was a problem hiding this comment.
And if repo is not supper we juste use eager + warning!
5611313 to
61de8e5
Compare
|
Flag to disable is coming1 |
7ab8096 to
bf5f602
Compare
|
I believe the implementation should be compatible with torch.compile. Suggestions: |
|
Yeah that's right, once we have a stable api, we can think about how to make it compatible with torch.compile, but for now using kernels can be deactivated, by uninstalling the kernels library or just setting the |
* initial commit * style * update * change approach attention * clean up * fix import * update * update * fix style * change method * attention * add mlp back * change name * update name * fix copies * fix config * fix
* initial commit * style * update * change approach attention * clean up * fix import * update * update * fix style * change method * attention * add mlp back * change name * update name * fix copies * fix config * fix
What does this PR do?
PoC of Integrating kernels into the llama model. The kernels used are for
attn,mlp, andrmsnorm