-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Feature] Support fp8 e5m2 kv cache with flashinfer #1204
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
Merged
+116
−16
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ada0151
flashinfer fp8 e5m2 kv cache
ispobock 05c96f8
Merge branch 'main' into fp8_kv_cache
ispobock 831e2ab
fix ut
ispobock a403831
Merge branch 'main' into fp8_kv_cache
zhyncs c104cb5
Merge branch 'main' into fp8_kv_cache
zhyncs 47e0d2b
fix comment
zhyncs 065442a
Apply suggestions from code review
merrymercy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -312,15 +312,15 @@ def profile_max_num_token(self, total_gpu_memory: int): | |
| cell_size = ( | ||
| (self.model_config.kv_lora_rank + self.model_config.qk_rope_head_dim) | ||
| * self.model_config.num_hidden_layers | ||
| * torch._utils._element_size(self.dtype) | ||
| * torch._utils._element_size(self.kv_cache_dtype) | ||
| ) | ||
| else: | ||
| cell_size = ( | ||
| self.model_config.get_num_kv_heads(self.tp_size) | ||
| * self.model_config.head_dim | ||
| * self.model_config.num_hidden_layers | ||
| * 2 | ||
| * torch._utils._element_size(self.dtype) | ||
| * torch._utils._element_size(self.kv_cache_dtype) | ||
| ) | ||
| rest_memory = available_gpu_memory - total_gpu_memory * ( | ||
| 1 - self.mem_fraction_static | ||
|
|
@@ -334,6 +334,21 @@ def init_memory_pool( | |
| max_num_reqs: int = None, | ||
| max_total_tokens: int = None, | ||
| ): | ||
| if self.server_args.kv_cache_dtype == "auto": | ||
| self.kv_cache_dtype = self.dtype | ||
| elif self.server_args.kv_cache_dtype == "fp8_e5m2": | ||
| if self.server_args.disable_flashinfer or self.server_args.enable_mla: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, only FlashInfer is supported and not Triton, due to the issue of insufficient smem. This needs to be fixed in another PR. |
||
| logger.warning( | ||
| "FP8 KV cache is not supported for Triton kernel now, using auto kv cache dtype" | ||
| ) | ||
| self.kv_cache_dtype = self.dtype | ||
| else: | ||
| self.kv_cache_dtype = torch.float8_e5m2 | ||
| else: | ||
| raise ValueError( | ||
| f"Unsupported kv_cache_dtype: {self.server_args.kv_cache_dtype}." | ||
| ) | ||
|
|
||
| self.max_total_num_tokens = self.profile_max_num_token(total_gpu_memory) | ||
| if max_total_tokens is not None: | ||
| if max_total_tokens > self.max_total_num_tokens: | ||
|
|
@@ -370,7 +385,7 @@ def init_memory_pool( | |
| ): | ||
| self.token_to_kv_pool = MLATokenToKVPool( | ||
| self.max_total_num_tokens, | ||
| dtype=self.dtype, | ||
| dtype=self.kv_cache_dtype, | ||
| kv_lora_rank=self.model_config.kv_lora_rank, | ||
| qk_rope_head_dim=self.model_config.qk_rope_head_dim, | ||
| layer_num=self.model_config.num_hidden_layers, | ||
|
|
@@ -381,7 +396,7 @@ def init_memory_pool( | |
| else: | ||
| self.token_to_kv_pool = MHATokenToKVPool( | ||
| self.max_total_num_tokens, | ||
| dtype=self.dtype, | ||
| dtype=self.kv_cache_dtype, | ||
| head_num=self.model_config.get_num_kv_heads(self.tp_size), | ||
| head_dim=self.model_config.head_dim, | ||
| layer_num=self.model_config.num_hidden_layers, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
workaround for float8_e5m2