| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | from typing import TYPE_CHECKING |
| 5 | |
| 6 | from vllm.logger import init_logger |
| 7 | from vllm.models.minimax_m3.nvidia.model import MiniMaxM3SparseAttention |
| 8 | from vllm.platforms import current_platform |
| 9 | from vllm.tracing import instrument |
| 10 | |
| 11 | if TYPE_CHECKING: |
| 12 | from vllm.v1.worker.gpu_worker import Worker |
| 13 | |
| 14 | logger = init_logger(__name__) |
| 15 | |
| 16 | |
| 17 | @instrument(span_name="MiniMax M3 MSA warmup") |
| 18 | def minimax_m3_msa_warmup(worker: "Worker") -> None: |
| 19 | sparse_module = next( |
| 20 | ( |
| 21 | module |
| 22 | for module in worker.get_model().modules() |
| 23 | if isinstance(module, MiniMaxM3SparseAttention) |
| 24 | ), |
| 25 | None, |
| 26 | ) |
| 27 | if sparse_module is None: |
| 28 | return |
| 29 | if not ( |
| 30 | current_platform.is_cuda() and current_platform.is_device_capability_family(100) |
| 31 | ): |
| 32 | return |
| 33 | |
| 34 | logger.info("Warming up MiniMax M3 MSA kernels.") |
| 35 | |
| 36 | # Cover sparse prefill through the normal model path. |
| 37 | worker.model_runner._dummy_run( |
| 38 | num_tokens=16, |
| 39 | skip_eplb=True, |
| 40 | is_profile=True, |
| 41 | force_attention=True, |
| 42 | create_mixed_batch=True, |
| 43 | ) |