[CPU] Add AMX-only high-performance MLA backend for DeepSeek V2/V3/R1 (#52616)

Signed-off-by: jiang1.li <jiang1.li@intel.com>
This commit is contained in:
Li, Jiang
2026-08-19 10:28:52 +08:00
committed by GitHub
parent f485081e8b
commit e4d61d0d22
20 changed files with 4156 additions and 6 deletions
+31 -5
View File
@@ -89,13 +89,30 @@ class CpuPlatform(Platform):
if attn_selector_config.use_sparse:
raise NotImplementedError("Sparse Attention is not supported on CPU.")
if attn_selector_config.use_mla:
amx_available = (
cls.get_cpu_architecture() == CpuArchEnum.X86
and torch.cpu._is_amx_tile_supported()
)
if amx_available and selected_backend != AttentionBackendEnum.CPU_MLA:
# Prefer AMX when available, unless CPU_MLA was explicitly requested.
if (
selected_backend
and selected_backend != AttentionBackendEnum.AMX_MLA
):
logger.info("Cannot use %s backend on CPU.", selected_backend)
logger.info_once("Using %s backend.", AttentionBackendEnum.AMX_MLA.name)
return AttentionBackendEnum.AMX_MLA.get_path()
# Reference MLA implementation on CPU. Performance is not the
# goal here; the backend simply wires the CPU decode kernel
# (`mla_decode_kvcache`) and an SDPA-based prefill together with
# the shared MLA scaffolding so that DeepSeek-style models can
# execute on CPU.
if selected_backend and selected_backend != AttentionBackendEnum.CPU_MLA:
if selected_backend and selected_backend not in (
AttentionBackendEnum.CPU_MLA,
AttentionBackendEnum.AMX_MLA,
):
logger.info("Cannot use %s backend on CPU.", selected_backend)
logger.info_once("Using %s backend.", AttentionBackendEnum.CPU_MLA.name)
return AttentionBackendEnum.CPU_MLA.get_path()
if selected_backend and selected_backend != AttentionBackendEnum.CPU_ATTN:
logger.info("Cannot use %s backend on CPU.", selected_backend)
@@ -134,11 +151,20 @@ class CpuPlatform(Platform):
# The CPU MLA decode kernel only compiles with block_size=16 today
# (see csrc/cpu/mla_decode.cpp). If the model uses MLA we override
# the default block size regardless of user preference to avoid a
# runtime kernel dispatch failure.
# runtime kernel dispatch failure. AMX MLA has no such constraint
# (same AMX-available condition as get_attn_backend_cls), so it's
# excluded from this override.
cpu_mla_enabled = model_config is not None and getattr(
model_config, "use_mla", False
)
if cpu_mla_enabled:
amx_mla_enabled = (
cpu_mla_enabled
and cls.get_cpu_architecture() == CpuArchEnum.X86
and torch.cpu._is_amx_tile_supported()
and vllm_config.attention_config.backend != AttentionBackendEnum.CPU_MLA
)
reference_cpu_mla_enabled = cpu_mla_enabled and not amx_mla_enabled
if reference_cpu_mla_enabled:
if cache_config.user_specified_block_size and cache_config.block_size != 16:
logger.warning(
"CPU MLA backend requires block_size=16, overriding "
@@ -149,7 +175,7 @@ class CpuPlatform(Platform):
elif not cache_config.user_specified_block_size:
cache_config.block_size = 128
if not cpu_mla_enabled and cache_config.block_size % 32 != 0:
if not reference_cpu_mla_enabled and cache_config.block_size % 32 != 0:
logger.warning(
"CPU backend prefers block_size is multiples of 32, "
"otherwise the performance is not optimized."
@@ -342,7 +368,7 @@ class CpuPlatform(Platform):
vllm_config.parallel_config.tensor_parallel_size
)
if model_config is not None and model_config.use_mla:
if model_config is not None and model_config.use_mla and not amx_mla_enabled:
logger.info_once(
"MLA is enabled on a non-GPU platform; forcing chunked "
"prefill and prefix caching to be disabled."