-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
[V1] Fixed fp8 kv-cache issues for the FlashInfer attention backend #20746
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
Conversation
This PR fixed fp8 kv-cache issues for the FlashInfer attn backend. Along with vllm-project#17005, got reasonable eval results on B200: ``` $ VLLM_USE_V1=1 VLLM_ATTENTION_BACKEND=FLASHINFER lm_eval --model vllm --model_args pretrained=meta-llama/Llama-3.1-8B-Instruct,kv_cache_dtype=fp8 --trust_remote_code --tasks gsm8k --num_fewshot 5 --batch_size auto ... vllm (pretrained=meta-llama/Llama-3.1-8B-Instruct,kv_cache_dtype=fp8,trust_remote_code=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: auto |Tasks|Version| Filter |n-shot| Metric | |Value | |Stderr| |-----|------:|----------------|-----:|-----------|---|-----:|---|-----:| |gsm8k| 3|flexible-extract| 5|exact_match|↑ |0.7779|± |0.0114| | | |strict-match | 5|exact_match|↑ |0.7582|± |0.0118| ``` compared with bf16 kv-cache ``` $ VLLM_USE_V1=1 VLLM_ATTENTION_BACKEND=FLASHINFER lm_eval --model vllm --model_args pretrained=meta-llama/Llama-3.1-8B-Instruct --trust_remote_code --tasks gsm8k --num_fewshot 5 --batch_size auto ... |Tasks|Version| Filter |n-shot| Metric | |Value | |Stderr| |-----|------:|----------------|-----:|-----------|---|-----:|---|-----:| |gsm8k| 3|flexible-extract| 5|exact_match|↑ |0.7756|± |0.0115| | | |strict-match | 5|exact_match|↑ |0.7498|± |0.0119| ``` Tags: Signed-off-by: Yang Chen <[email protected]>
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
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 @chenyang78, 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 resolves critical issues related to the use of FP8 KV-cache with the FlashInfer attention backend. The changes ensure that FP8 data types are correctly identified, handled, and cast throughout the KV-cache management and attention computation processes, leading to stable and accurate model evaluation results when using FP8 precision.
Highlights
- FP8 Type Mapping Utility: Introduced a new static method
get_fp8_dtype_for_flashinferwithinFlashInferBackendto accurately map string representations of FP8 data types (e.g., "fp8", "fp8_e4m3", "fp8_e5m2") to their correspondingtorch.dtypeobjects, ensuring correct type resolution for FlashInfer. - Correct KV-Cache Type Handling in Build Process: Modified the
buildmethod withinFlashInferBackendto ensure the correcttorch.dtypefor FP8 KV-cache is passed toFlashInferMetadata. This change addresses an issue where thegpu_model_runnermight incorrectly convertfp8touint8, preserving the intended FP8 precision. - Explicit KV-Cache Type Casting in Forward Pass: Added logic to the
forwardmethod ofFlashInferBackendto explicitlyviewthe KV-cache tensor to the correcttorch.float8_e4m3fnortorch.float8_e5m2dtype when FP8 KV-cache is enabled. This ensures that FlashInfer receives the KV-cache data in the precise FP8 format it expects for computation.
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 PR fixes fp8 kv-cache issues for the FlashInfer attention backend. I suggested storing the fp8 dtype in self to avoid re-deriving it, improving efficiency and consistency.
| if cache_dtype.startswith("fp8"): | ||
| kv_cache_dtype = FlashInferBackend.get_fp8_dtype_for_flashinfer( | ||
| cache_dtype) |
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 torch.dtype for fp8 is derived using FlashInferBackend.get_fp8_dtype_for_flashinfer.[^1] Consider storing this dtype in self during initialization to avoid re-deriving it on each call to build. This can improve efficiency.
self.kv_cache_dtype_fp8 = FlashInferBackend.get_fp8_dtype_for_flashinfer(
cache_dtype)| head_dim=self.kv_cache_spec.head_size, | ||
| page_size=page_size, | ||
| data_type=self.kv_cache_spec.dtype, | ||
| data_type=kv_cache_dtype, |
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.
| torch_dtype = FlashInferBackend.get_fp8_dtype_for_flashinfer( | ||
| self.kv_cache_dtype) | ||
| kv_cache = kv_cache.view(torch_dtype) |
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.
|
Thanks for finding this fix! Pavani seemed to uncover the same in her TRTLLM decode integration PR #19825, and since that is high priority I think we'll try to merge it in there today |
Sounds good. Thanks for the heads-up. |
|
Closing this one per discussion. |
This PR fixed fp8 kv-cache issues for the FlashInfer attn backend.
Along with #17005, got reasonable eval results on B200:
compared with bf16 kv-cache
Tags:
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.Purpose
Test Plan
Test Result
(Optional) Documentation Update