[Feature]: AutoDeploy: linear attention pattern matching
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.7k
- Forks
- 2.8k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 489
Description
🚀 The feature, motivation and pitch
Currently, AutoDeploy supports the following attention types:
- Quadratic (sdpa) attention
- Causal conv
- Mamba2 (SSM)
- DeltaNet
However, only sdpa attention comes with a set of pattern matcher transforms to automatically detect the attention pattern from a given source model, see the following transforms:
https://github.com/NVIDIA/TensorRT-LLM/blob/3a894951e7defa7fd44c4b972953b327c9cd8047/tensorrt_llm/_torch/auto_deploy/config/default.yaml#L33-L45
For other attention types, the model currently needs to be patched with the torch.ops.auto_deploy.torch_* reference op in order for the compiler to correctly recognize the attention op for later transforms such as sharding and caching.
For example, here is an example patch:
https://github.com/NVIDIA/TensorRT-LLM/blob/ae8f74b6206fb74d7924dacf69017e3491ec2812/tensorrt_llm/_torch/auto_deploy/models/patches/bamba.py#L87-L98
The goal of this ticket is to develop pattern matching transforms akin of the quadratic attention pattern matchers for our linear attention support.
Roughly, the implementation plan could look as follows:
- Develop an initial pattern matcher with 1-2 patterns and 1-2 example models
- Write a unit test to check if pattern matcher works as expected
- Put together a list of relevant hybrid models
- Collect all linear attention patterns present in these models
- Extent the pattern matcher to handle more patterns
- Extend and validate with extended unit test
- Test e2e with a couple of integration tests and by removing patches that are now covered by the pattern matcher
Alternatives
No response
Additional context
No response
Before submitting a new issue...
- Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.