vllm.v1.attention.backends.mla.amx_mla ¶
AMX-only, high-performance MLA backend for DeepSeek V2/V3/R1 on CPU.
Built on the AMX decode/extend/bmm kernels vendored under csrc/cpu/sgl-kernels/, plugged into vLLM's MLACommonBackend/ MLACommonImpl abstraction the same way every other concrete MLA backend (TritonMLAImpl, etc.) does.
This is a separate backend from the reference CPUMLABackend (vllm/v1/attention/backends/mla/cpu_mla.py): that one targets every CPU (any dtype, block_size=16, mla_decode_kvcache decode kernel + inherited SDPA-style prefill) as a functional/CI reference, not performance. This backend instead requires AMX (bf16 only, block_size a multiple of 32) and is selected by the platform layer in preference to the reference backend whenever the host supports it -- see CpuPlatform.get_attn_backend_cls.
Two points where this backend differs structurally from the GPU backends, both explained in the CPU MLA design plan:
forward_mhais fully overridden (not inherited fromMLACommonBaseImpl): the GPU "compute-friendly" prefill path depends on a pluggableMLAPrefillBackendand CUDA-only chunked-context gather ops, neither of which exist on CPU. Instead, this attends directly in latent-MQA space via theextend_attention_cpukernel, which handles cached-prefix continuation and fresh prefill in one causal pass (the KV cache already contains the new tokens by the time this runs, sincedo_kv_cache_updateexecutes first).- Weight absorption for the prefill path is done with this impl's own VNNI-packed copies of
W_UK/W_UV(computed inprocess_weights_after_loading, usingbmm_cpu), rather than reading the genericlayer.W_UK_T/layer.W_UV/layer._v_up_projthe way GPU backends do, sinceforward_mha's abstract signature has nolayerparameter (onlyforward_mqadoes) and that signature is left untouched. The decode path needs no such packing:MLAAttention.forward_implalready absorbs/de-absorbs Q around theforward_mqacall using the generic (unpacked)layer.W_UK_T/layer._v_up_proj, soforward_mqahere only has to invoke the decode kernel.
_compute_num_kv_splits(max_seq_len, num_threads) ¶
Mirrors TritonMLAImpl's _compute_num_kv_splits, using the CPU thread count in place of SM count.
Source code in vllm/v1/attention/backends/mla/amx_mla.py
_expand_block_table(block_table, block_size) ¶
Adapter: vLLM's block-table paging -> the flat per-(request, position) physical row index the decode/extend kernels expect. Called once per step from AMXMLAMetadataBuilder.build, not per layer.