-
Notifications
You must be signed in to change notification settings - Fork 294
add att backend #1165
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
base: main
Are you sure you want to change the base?
add att backend #1165
Conversation
Summary of ChangesHello @hiworldwzj, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant architectural improvement by implementing a modular and extensible attention backend system. It abstracts the underlying attention kernel implementations, allowing for easy integration of various optimized attention methods (like Triton, FA3, or FlashInfer) for both prefill and decode operations. The existing Triton-based ALiBi attention kernels have been refactored into this new common framework, and the core model logic has been updated to utilize this abstraction. This change enhances the flexibility and maintainability of the attention mechanism within the system, preparing it for future performance optimizations and diverse hardware support. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a valuable abstraction for attention backends, which significantly improves the modularity and extensibility of the codebase. The refactoring of Triton-based alibi attention kernels into a common, reusable component is a commendable architectural enhancement. However, I've identified a critical bug in the new Triton backend implementation where the value tensor (v) is not correctly passed to the attention kernel, which will lead to incorrect outputs. Additionally, I've provided several recommendations to enhance code clarity, consistency, and maintainability, such as using a single attribute for the attention backend, improving type hints, and providing more descriptive error messages.
| token_attention_fwd( | ||
| q, | ||
| k, | ||
| k, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a critical bug here. The token_attention_fwd function is being called with k for both the key and value arguments. The v tensor, which is available in this method's scope, is being ignored. This will result in incorrect attention calculations. You should pass the v tensor as the value argument.
| k, | |
| v, |
| k: torch.tensor, | ||
| v: torch.tensor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with q and common Python type hinting practices, it's better to use torch.Tensor for type hints instead of torch.tensor. torch.Tensor refers to the tensor class, whereas torch.tensor is a factory function for creating tensors.
| k: torch.tensor, | |
| v: torch.tensor, | |
| k: torch.Tensor, | |
| v: torch.Tensor, |
| alloc_func=torch.empty, | ||
| use_alibi=False, | ||
| ) -> torch.Tensor: | ||
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| k: torch.tensor, | ||
| v: torch.tensor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if use_alibi: | ||
| return self._alibi_prefill_att(q=q, k=k, v=v, layer_weight=layer_weight, out=out, alloc_func=alloc_func) | ||
| else: | ||
| raise NotImplementedError("error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message "error" is not very descriptive. Consider providing a more informative message to aid in debugging, such as indicating that non-alibi attention is not implemented.
| raise NotImplementedError("error") | |
| raise NotImplementedError("Non-alibi attention is not implemented for the Triton backend.") |
| kv: torch.Tensor, | ||
| infer_state: InferStateInfo, | ||
| layer_weight: BloomTransformerLayerWeight, | ||
| out=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| def _token_attention_kernel( | ||
| self, q, infer_state: InferStateInfo, layer_weight: BloomTransformerLayerWeight, out=None | ||
| self, q: torch.Tensor, infer_state: InferStateInfo, layer_weight: BloomTransformerLayerWeight, out=None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def _init_att_backend(self): | ||
| self.prefill_att_backend = TritonAttBackend() | ||
| self.decode_att_backend = TritonAttBackend() | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lightllm/server/api_cli.py
Outdated
| parser.add_argument( | ||
| "--llm_kv_type", | ||
| type=str, | ||
| choices=[None, ""], | ||
| default=None, | ||
| help="""kv type used in llm""", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| enable_flashinfer_decode: bool = field(default=False) | ||
| llm_prefill_att_backend: str = field(default=None, metadata={"choices": [None, "triton", "fa3", "flashinfer"]}) | ||
| llm_decode_att_backend: str = field(default=None, metadata={"choices": [None, "triton", "fa3", "flashinfer"]}) | ||
| llm_kv_type: str = field(default=None, metadata={"choices": [None, ""]}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f714442 to
90b8084
Compare
No description provided.