Read code changes as Git diffs. Identifying strings are masked; binary files are listed by their full relative names.
vllm_ascend · 1 changed files
Base commit: f649187194c44d86415d1ddfa49359e824932c9a
diff --git a/vllm_ascend/patch/platform/patch_mamba_config.py b/vllm_ascend/patch/platform/patch_mamba_config.pyindex 775e54743769e9f48de6fa316f05a48816b79f7d..bfcb0a73da89bfc70951e00237e2564bda5707b4 100644--- a/vllm_ascend/patch/platform/patch_mamba_config.py+++ b/vllm_ascend/patch/platform/patch_mamba_config.py@@ -33,6 +33,11 @@ def verify_and_update_config(cls, vllm_config) -> None: else: kv_cache_dtype = STR_DTYPE_TO_TORCH_DTYPE[cache_config.cache_dtype] + # NOTE(zxr): because of the limit of Ascend Hardware, we need to keep+ # all cache tensors contiguous, so we align the page size of ssm_block+ # and single attn_block. The minimum alignment is 128 tokens, which+ # is the kernel block size required by the Ascend attention kernels+ # (see vllm_ascend/worker/block_table.py: ``kernel_sizes = [128]``). kernel_block_size = 128 # get attention block size attn_num_kv_heads = model_config.get_num_kv_heads(parallel_config)@@ -52,11 +57,24 @@ def verify_and_update_config(cls, vllm_config) -> None: mamba_sizes.append(math.prod(shape) * get_dtype_size(dtype)) ssm_block_page_size, conv_block_page_size = max(mamba_sizes), min(mamba_sizes) - # NOTE(zxr): because of the limit of Ascend Hardware, we need to keep- # all cache tensors contiguous, so we align the page size of ssm_block- # and single attn_block- attn_block_size = kernel_block_size * cdiv(ssm_block_page_size, kernel_block_size * attn_single_token_k_page_size)- assert attn_single_token_k_page_size * attn_block_size == ssm_block_page_size, (+ # Choose the minimum attention block size that is a multiple of+ # ``kernel_block_size`` and large enough that the resulting attention+ # KV page can hold the largest mamba cache state. This is a relaxed+ # version of the previous strict-equality requirement: we no longer+ # require ``attn_single_token_k_page_size * attn_block_size`` to equal+ # ``ssm_block_page_size`` exactly, because for small mamba states+ # (e.g. LFM2.5 with conv_dim=2048, conv_L_cache=3) the per-rank+ # mamba state (4096 bytes) is much smaller than the attention+ # single-token K page (512 bytes per rank on TP=2), and the ratio+ # is not a multiple of 128. The mamba page size is then padded to+ # the attn page size below.+ attn_block_size = kernel_block_size * cdiv(+ ssm_block_page_size, kernel_block_size * attn_single_token_k_page_size+ )+ # Guard against rounding edge cases: ensure the attn page is at+ # least as large as the ssm page (the underlying hardware alignment+ # requirement).+ assert attn_single_token_k_page_size * attn_block_size >= ssm_block_page_size, ( "Cannot align ssm_page_size and attn_page_size." )