Repository navigation
[Bugfix][Step5] Size the KV block to the CSA tail ring #65153
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
AndreasKaratzas
merged 2 commits into
vllm-project:main
from
akii96:step5-fp8-tail-ring-block-size
Nov 3, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from vllm.config import set_current_vllm_config | ||
| from vllm.model_executor.layers.attention_layer_base import AttentionLayerBase | ||
| from vllm.models.step5.common.csa_tail_ring import Step5CSATailRing | ||
| from vllm.platforms.interface import Platform | ||
| from vllm.v1.attention.backend import AttentionBackend, MultipleOf | ||
| from vllm.v1.kv_cache_interface import FullAttentionSpec | ||
|
|
||
| _HEAD_SIZE = 192 | ||
| _FP8 = torch.uint8 | ||
| _DEFAULT_BLOCK_SIZE = 16 | ||
|
|
||
|
|
||
| class _MultipleOf16(AttentionBackend): | ||
| @staticmethod | ||
| def get_name() -> str: | ||
| return "MULTIPLE_OF_16" | ||
|
|
||
| @staticmethod | ||
| def get_impl_cls(): | ||
| raise NotImplementedError | ||
|
|
||
| @staticmethod | ||
| def get_builder_cls(): | ||
| raise NotImplementedError | ||
|
|
||
| @staticmethod | ||
| def get_supported_kernel_block_sizes(kv_cache_spec=None): | ||
| return [MultipleOf(16)] | ||
|
|
||
|
|
||
| class _MainLayer(AttentionLayerBase): | ||
| def __init__( | ||
| self, num_kv_heads: int, dtype: torch.dtype, page_size_padded: int | None | ||
| ) -> None: | ||
| self.num_kv_heads = num_kv_heads | ||
| self.dtype = dtype | ||
| self.page_size_padded = page_size_padded | ||
|
|
||
| def get_attn_backend(self) -> type[AttentionBackend]: | ||
| return _MultipleOf16 | ||
|
|
||
| def get_kv_cache_spec(self, vllm_config): | ||
| return FullAttentionSpec( | ||
| block_size=vllm_config.cache_config.block_size, | ||
| num_kv_heads=self.num_kv_heads, | ||
| head_size=_HEAD_SIZE, | ||
| dtype=self.dtype, | ||
| page_size_padded=self.page_size_padded, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("num_kv_heads", "dtype", "speculative_tokens", "page_size_padded", "expected"), | ||
| [ | ||
| pytest.param(1, _FP8, 0, None, 32, id="fp8-tp8"), | ||
| pytest.param(2, _FP8, 0, None, 16, id="fp8-tp2"), | ||
| pytest.param(4, _FP8, 0, None, 16, id="fp8-tp1"), | ||
| pytest.param(1, torch.bfloat16, 0, None, 16, id="bf16-tp8"), | ||
| pytest.param(1, _FP8, 6, None, 64, id="fp8-tp8-mtp6"), | ||
| pytest.param(1, _FP8, 0, 13312, 32, id="fp8-tp8-padded"), | ||
| ], | ||
| ) | ||
| def test_block_size_fits_tail_ring( | ||
| num_kv_heads, dtype, speculative_tokens, page_size_padded, expected | ||
| ): | ||
| context: dict = {} | ||
| ring = Step5CSATailRing( | ||
| prefix="layers.0.csa_tail_ring", | ||
| main_layer_name="layers.0.attn", | ||
| num_speculative_tokens=speculative_tokens, | ||
| static_forward_context=context, | ||
| ) | ||
| context["layers.0.attn"] = _MainLayer(num_kv_heads, dtype, page_size_padded) | ||
| config = SimpleNamespace( | ||
| cache_config=SimpleNamespace( | ||
| block_size=_DEFAULT_BLOCK_SIZE, | ||
| user_specified_block_size=False, | ||
| kv_cache_dtype_skip_layers=[], | ||
| ), | ||
| compilation_config=SimpleNamespace(static_forward_context=context), | ||
| model_config=SimpleNamespace(is_hybrid=False), | ||
| ) | ||
| with set_current_vllm_config(config): | ||
| Platform.update_block_size_for_backend(config) | ||
| ring.get_kv_cache_spec(config) | ||
| assert ring.capacity >= ring.required_rows | ||
| assert config.cache_config.block_size == expected | ||
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.
Uh oh!
There was an error while loading. Please reload this page.