-
Notifications
You must be signed in to change notification settings - Fork 2.8k
TRTLLM Gen MLA Decode Kernel Integration #7938
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
TRTLLM Gen MLA Decode Kernel Integration #7938
Conversation
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.
Summary of Changes
Hello @farazkh80, 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 is an initial work-in-progress commit to integrate and enable TensorRT-LLM (TRTLLM) Multi-Head Latent Attention (MLA) kernels within the system. The primary objective is to enhance attention computation performance, particularly on Blackwell architectures, by utilizing these specialized kernels from FlashInfer. This lays the foundational groundwork for future performance improvements in decode operations.
Highlights
- New Attention Backend: Introduced a new
TRTLLMMLABackend
to integrate TensorRT-LLM (TRTLLM) Multi-Head Latent Attention (MLA) kernels, leveraging the FlashInfer library for optimized decode operations. - Blackwell Optimization: The system now intelligently prioritizes the use of the new
trtllm_mla
attention backend on Blackwell (SM100) architectures, provided the specific FlashInfer kernels are available, aiming for improved performance. - Dependency Update: The
flashinfer_python
dependency inpyproject.toml
has been updated to point to a specific Git commit, likely to access the necessary TRTLLM MLA features that are not yet in a released version. - Unit Testing: A new comprehensive test suite (
test_trtllm_mla_backend.py
) has been added to validate the functionality and correctness of the TRTLLM MLA backend across various configurations.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
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 .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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 support for TRT-LLM MLA kernels. My review has identified a few areas for improvement:
- The project now depends on a personal fork of
flashinfer
, which should be addressed for better maintainability. - The new
TRTLLMMLABackend
has some hardcoded values for model dimensions and workspace size that could be made more flexible. - There's a critical bug in
TRTLLMMLABackend
where an assertion will fail for MLA use cases. - The backend selection logic in
model_runner.py
uses a bareexcept
clause which should be more specific.
/gemini review |
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 the trtllm_mla
attention backend, integrating TensorRT-LLM's Multi-Head Latent Attention kernels. The changes include the backend implementation, integration with the model runner, and a new test suite. Key areas for improvement include dependency management, KV cache preparation, and ensuring robustness for quantized models.
PR should be ready for an initial review. Only pending changes are waiting for flashinfer-ai/flashinfer#1289 to deduplicate kv-cache. Duplication of the kv-cache is the main bottleneck for e2e perf. As seen in, nsys kernel-wise comparision capture below. Left hand-side is the flashinfer |
The kv-cache deduplication is merged now on flashinfer side flashinfer-ai/flashinfer#1289. I have reflected the changes in this PR and now at high concurrency we have 40% throughput improvement. This is currently using bf16 kv-cache for MLA, there will be a seperate PR in future to support fp8 kv-cache and query which should allows us to further improve perf and concurrency.
|
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.
please fix the lint
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 possible, can you also attach a torch profile. Just to check whether the overlap scheduler works and there is no any cpu-gpu sync
fd9b07f
to
8f8c478
Compare
Signed-off-by: Faraz Khoubsirat <58580514+farazkh80@users.noreply.github.com>
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.
Please fix the file permissions for files that were modified to 755
Signed-off-by: Faraz Khoubsirat <58580514+farazkh80@users.noreply.github.com>
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.
LGTM, thanks!
…gl-project#8632) Signed-off-by: Faraz Khoubsirat <58580514+farazkh80@users.noreply.github.com>
…gl-project#8632) Signed-off-by: Faraz Khoubsirat <58580514+farazkh80@users.noreply.github.com>
…gl-project#8632) Signed-off-by: Faraz Khoubsirat <58580514+farazkh80@users.noreply.github.com>
…gl-project#8632) Signed-off-by: Faraz Khoubsirat <58580514+farazkh80@users.noreply.github.com>
Motivation
This PR integrates TRTLLM-GEN MLA Decode kernel from flashinfer to sglang.
Modifications
Intorduced new mla backend option
TRTLLMMLABackend
inpython/sglang/srt/layers/attention/trtllm_mla_backend.py
.Benchmarking
Low Concurrency Results TP=4 (4xB200)
Server Command:
python -m sglang.launch_server --model-path deepseek-ai/DeepSeek-R1 --trust-remote-code --attention-backend trtllm_mla/flashinfer/cutlass_mla --page-size 32/64/128 --tp-size 4 --max-running-requests 1 --cuda-graph-max-bs 1 -mem-fraction-static 0.90
|Client Command:
python -m sglang.bench_serving --backend sglang --host 0.0.0.0 --port 30000 --dataset-name random --random-input-len 1024 --random-output-len 8192 --num-prompts 1 --max-concurrency 1
High Concurrency Results
Server Command:
python -m sglang.launch_server --model-path deepseek-ai/DeepSeek-R1 --trust-remote-code --attention-backend trtllm_mla/flashinfer --page-size 32/64 --tp-size 8 --max-running-requests 512 --cuda-graph-max-bs 512 -mem-fraction-static 0.90
|Client Command:
python -m sglang.bench_serving --backend sglang --host 0.0.0.0 --port 30000 --dataset-name random --random-input-len 1024 --random-output-len 8192 --num-prompts 1024 --max-concurrency 512
Checklist