[Model] Add DeepSeek-V4 CPU backend (#55355)
Signed-off-by: jiang1.li <jiang1.li@intel.com>
This commit is contained in:
+46
-4
@@ -203,14 +203,26 @@ class CpuPlatform(Platform):
|
||||
|
||||
cache_config = vllm_config.cache_config
|
||||
|
||||
is_deepseek_v4 = (
|
||||
model_config is not None
|
||||
and getattr(model_config.hf_config, "model_type", None) == "deepseek_v4"
|
||||
)
|
||||
|
||||
# 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. 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
|
||||
# excluded from this override. DeepSeek-V4 is also excluded here and
|
||||
# handled in its own branch below: its sparse-MLA and indexer
|
||||
# backends declare block_size=256 as their only supported kernel
|
||||
# block size (DeepseekV4SparseMLABackend/DeepseekV4IndexerBackend),
|
||||
# so it needs the same override-regardless-of-preference treatment
|
||||
# as CPU MLA, just with a different value.
|
||||
cpu_mla_enabled = (
|
||||
not is_deepseek_v4
|
||||
and model_config is not None
|
||||
and getattr(model_config, "use_mla", False)
|
||||
)
|
||||
amx_mla_enabled = (
|
||||
cpu_mla_enabled
|
||||
@@ -219,6 +231,21 @@ class CpuPlatform(Platform):
|
||||
and vllm_config.attention_config.backend != AttentionBackendEnum.CPU_MLA
|
||||
)
|
||||
reference_cpu_mla_enabled = cpu_mla_enabled and not amx_mla_enabled
|
||||
# DeepSeek-V4's CPU attention/indexer kernels
|
||||
# (csrc/cpu/sgl-kernels/{flash_mla,store_cache,compressor,
|
||||
# paged_mqa_logits,topk}.cpp) are AMX-kernel-backed and built on the
|
||||
# same paged/position-indexed conventions as the GPU/XPU backends
|
||||
# (block_table/slot_mapping addressing throughout, chunk metadata
|
||||
# that already carries per-token causal offsets for partial/extend
|
||||
# continuation) -- so they support chunked prefill and prefix
|
||||
# caching the same way. `amx_mla_enabled` above deliberately
|
||||
# excludes DeepSeek-V4 (it has its own block-size requirements,
|
||||
# unrelated to chunked-prefill support), so it can't be reused here.
|
||||
amx_mla_or_dsv4_enabled = amx_mla_enabled or (
|
||||
is_deepseek_v4
|
||||
and cls.get_cpu_architecture() == CpuArchEnum.X86
|
||||
and torch.cpu._is_amx_tile_supported()
|
||||
)
|
||||
if reference_cpu_mla_enabled:
|
||||
if cache_config.user_specified_block_size and cache_config.block_size != 16:
|
||||
logger.warning(
|
||||
@@ -227,6 +254,17 @@ class CpuPlatform(Platform):
|
||||
cache_config.block_size,
|
||||
)
|
||||
cache_config.block_size = 16
|
||||
elif is_deepseek_v4:
|
||||
if (
|
||||
cache_config.user_specified_block_size
|
||||
and cache_config.block_size != 256
|
||||
):
|
||||
logger.warning(
|
||||
"DeepSeek-V4 CPU backend requires block_size=256, "
|
||||
"overriding user-specified block_size=%s.",
|
||||
cache_config.block_size,
|
||||
)
|
||||
cache_config.block_size = 256
|
||||
elif not cache_config.user_specified_block_size:
|
||||
cache_config.block_size = 128
|
||||
|
||||
@@ -439,7 +477,11 @@ class CpuPlatform(Platform):
|
||||
vllm_config.parallel_config.tensor_parallel_size
|
||||
)
|
||||
|
||||
if model_config is not None and model_config.use_mla and not amx_mla_enabled:
|
||||
if (
|
||||
model_config is not None
|
||||
and model_config.use_mla
|
||||
and not amx_mla_or_dsv4_enabled
|
||||
):
|
||||
logger.info_once(
|
||||
"MLA is enabled on a non-GPU platform; forcing chunked "
|
||||
"prefill and prefix caching to be disabled."
|
||||
|
||||
Reference in New Issue
Block a user