[Model] Add MiniMax M3 support (#45381)
Signed-off-by: youkaichao <youkaichao@gmail.com> Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn> Signed-off-by: Bugen Zhao <i@bugenzhao.com> Signed-off-by: Jee Jee Li <pandaleefree@gmail.com> Signed-off-by: functionstackx <47992694+functionstackx@users.noreply.github.com> Signed-off-by: Yongye Zhu <zyy1102000@gmail.com> Signed-off-by: Jee Jee Li <jeejeelee@inferact.ai> Co-authored-by: OpenAI Codex <codex@openai.com> Co-authored-by: Isotr0py <mozf@mail2.sysu.edu.cn> Co-authored-by: Thien Tran <gau.nernst@yahoo.com.sg> Co-authored-by: Bugen Zhao <i@bugenzhao.com> Co-authored-by: Jee Jee Li <pandaleefree@gmail.com> Co-authored-by: Roger Wang <hey@rogerw.io> Co-authored-by: functionstackx <47992694+functionstackx@users.noreply.github.com> Co-authored-by: Yongye Zhu <zyy1102000@gmail.com> Co-authored-by: Jee Jee Li <jeejeelee@inferact.ai>
This commit is contained in:
co-authored by
OpenAI Codex
Isotr0py
Thien Tran
Bugen Zhao
Jee Jee Li
Roger Wang
functionstackx
Yongye Zhu
Jee Jee Li
parent
a3195fab7b
commit
0a1c5034f5
@@ -336,9 +336,24 @@ class FlashInferBackend(AttentionBackend):
|
||||
|
||||
@staticmethod
|
||||
def get_supported_kernel_block_sizes() -> list[int | MultipleOf]:
|
||||
# Note: Not sure for all platforms, but on Blackwell,
|
||||
# only support a page size of 16, 32, 64.
|
||||
return [16, 32, 64]
|
||||
# Page sizes >= 128 only run on the trtllm-gen dynamic kernel (GQA/MQA
|
||||
# on Blackwell); advertise them only when usable so selection never
|
||||
# picks a large kernel block we cannot serve.
|
||||
use_large_pages = False
|
||||
vllm_config = get_current_vllm_config_or_none()
|
||||
if vllm_config is not None and vllm_config.model_config is not None:
|
||||
pc = vllm_config.parallel_config
|
||||
mc = vllm_config.model_config
|
||||
num_qo_heads = mc.get_num_attention_heads(pc)
|
||||
num_kv_heads = mc.get_num_kv_heads(pc)
|
||||
use_large_pages = (
|
||||
num_kv_heads > 0
|
||||
and num_qo_heads // num_kv_heads > 1
|
||||
and can_use_trtllm_attention(num_qo_heads, num_kv_heads)
|
||||
)
|
||||
if not use_large_pages:
|
||||
return [16, 32, 64]
|
||||
return [16, 32, 64, 128, 256, 512, 1024]
|
||||
|
||||
@staticmethod
|
||||
def get_name() -> str:
|
||||
@@ -647,6 +662,12 @@ class FlashInferMetadataBuilder(AttentionMetadataBuilder[FlashInferMetadata]):
|
||||
# if TRTLLM attention kernel is not used when building attn metadata
|
||||
can_use_trtllm = can_use_trtllm_attention(self.num_qo_heads, self.num_kv_heads)
|
||||
|
||||
# Page sizes >= 128 require the trtllm-gen GQA/MQA path (guaranteed by
|
||||
# get_supported_kernel_block_sizes).
|
||||
assert self.page_size <= 64 or (
|
||||
can_use_trtllm and self.num_qo_heads // self.num_kv_heads > 1
|
||||
), f"Unexpected FlashInfer page size {self.page_size} without trtllm-gen GQA"
|
||||
|
||||
if (
|
||||
can_use_trtllm
|
||||
and not vllm_config.attention_config.disable_flashinfer_q_quantization
|
||||
@@ -917,6 +938,10 @@ class FlashInferMetadataBuilder(AttentionMetadataBuilder[FlashInferMetadata]):
|
||||
# - Decode (FI native or TRTLLM)
|
||||
use_cascade = common_prefix_len > 0
|
||||
uses_spec_reorder = self.reorder_batch_threshold > 1
|
||||
# Page sizes >= 128 must use trtllm-gen; force it for prefill too.
|
||||
prefill_force_trtllm = (
|
||||
True if page_size >= 128 else self.attention_config.use_trtllm_attention
|
||||
)
|
||||
prefill_use_trtllm = use_trtllm_attention(
|
||||
self.num_qo_heads,
|
||||
self.num_kv_heads,
|
||||
@@ -926,7 +951,7 @@ class FlashInferMetadataBuilder(AttentionMetadataBuilder[FlashInferMetadata]):
|
||||
self.cache_dtype,
|
||||
self.q_data_type,
|
||||
is_prefill=True,
|
||||
force_use_trtllm=self.attention_config.use_trtllm_attention,
|
||||
force_use_trtllm=prefill_force_trtllm,
|
||||
has_sinks=self.has_sinks,
|
||||
has_spec=uses_spec_reorder,
|
||||
)
|
||||
|
||||
@@ -91,6 +91,9 @@ class AttentionBackendEnum(Enum, metaclass=_AttentionBackendEnumMeta):
|
||||
"vllm.models.deepseek_v4.amd.rocm.DeepseekV4ROCMAiterMLASparseBackend"
|
||||
)
|
||||
FLASH_ATTN_MLA = "vllm.v1.attention.backends.mla.flashattn_mla.FlashAttnMLABackend"
|
||||
MINIMAX_M3_SPARSE = (
|
||||
"vllm.models.minimax_m3.common.sparse_attention.MiniMaxM3SparseBackend"
|
||||
)
|
||||
NO_ATTENTION = "vllm.v1.attention.backends.no_attention.NoAttentionBackend"
|
||||
FLEX_ATTENTION = "vllm.v1.attention.backends.flex_attention.FlexAttentionBackend"
|
||||
ROCM_AITER_UNIFIED_ATTN = (
|
||||
|
||||
@@ -7,6 +7,7 @@ import numpy as np
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm.compilation.breakable_cudagraph import BreakableCUDAGraphWrapper
|
||||
from vllm.config import (
|
||||
CUDAGraphMode,
|
||||
VllmConfig,
|
||||
@@ -250,6 +251,13 @@ class SpecDecodeBaseProposer:
|
||||
DeepseekV4ROCMAiterMLASparseMetadata,
|
||||
DeepseekV4ROCMAiterSparseSWAMetadata,
|
||||
)
|
||||
|
||||
# MiniMax-M3 sparse (lightning-indexer) attention. The multi-step
|
||||
# drafting machinery is shared code at num_speculative_tokens>1.
|
||||
# this just opts the metadata into the ROCm allowlist.
|
||||
from vllm.models.minimax_m3.common.sparse_attention import (
|
||||
MiniMaxM3SparseMetadata,
|
||||
)
|
||||
from vllm.v1.attention.backends.mla.indexer import (
|
||||
DeepseekV32IndexerMetadata,
|
||||
)
|
||||
@@ -265,6 +273,7 @@ class SpecDecodeBaseProposer:
|
||||
DeepseekV4ROCMAiterMLASparseMetadata,
|
||||
DeepseekV4ROCMAiterSparseSWAMetadata,
|
||||
DeepseekV32IndexerMetadata,
|
||||
MiniMaxM3SparseMetadata,
|
||||
]
|
||||
# ROCM_AITER_FA is an optional backend
|
||||
# We check is_enabled() here to avoid importing the backend module during
|
||||
@@ -457,8 +466,11 @@ class SpecDecodeBaseProposer:
|
||||
batch_size = common_attn_metadata.batch_size()
|
||||
|
||||
if self.method in ("eagle3", "dflash"):
|
||||
model = self.model
|
||||
if isinstance(model, BreakableCUDAGraphWrapper):
|
||||
model = model.unwrap()
|
||||
assert isinstance(
|
||||
self.model,
|
||||
model,
|
||||
(
|
||||
Eagle3LlamaForCausalLM,
|
||||
Eagle3DeepseekV2ForCausalLM,
|
||||
|
||||
@@ -322,7 +322,7 @@ class MultiGroupBlockTable:
|
||||
return self.block_tables[idx]
|
||||
|
||||
|
||||
@triton.jit
|
||||
@triton.jit(do_not_specialize=["num_tokens", "max_num_tokens"])
|
||||
def _compute_slot_mapping_kernel(
|
||||
num_tokens,
|
||||
max_num_tokens,
|
||||
|
||||
Reference in New Issue
Block a user