Skip to content

vllm.models.deepseek_v41.amd.akr_warmup

Prefill-size JIT warm-up for DeepSeek-V4.1 with amd_kernels routes on.

FlyDSL 0.5 traces a kernel variant before it looks up the on-disk artifact, so the first launch of every variant in a process costs 0.3-7 s even with a warm cache. Startup only runs the captured decode sizes and one profile step, so the variants only prefill-sized steps select (AITER's MXFP8 GEMMs per tuned M bucket, batched GEMMs, MegaMoE stages, top-k) were traced while serving: one rank stalls for seconds and, the DP ranks being in lockstep, all of them wait. On a fresh DEP8 server that was 289 rank-seconds of tracing in the first five minutes.

prefill_warmup runs from kernel_warmup, after the KV cache exists and before graph capture: 1. each distinct linear layer (target and draft) runs its quant_method.apply at one token count per AITER tuned-GEMM bucket above the captured sizes, and so does the grouped wo_a; no collectives, so each rank runs it on its own; 2. whole-model dummy steps at a few prefill sizes, the same on every rank.

reserve_serving_transient (same call site) floors the torch growth the extensible KV cache keeps free at amd_kernels.serving_transient_gib. Its sizing steps measured 10.65 GiB of growth with the routes on (stock 14.55), which left 17.5 GiB after sizing; a DEP8 step with a 32k-token prefill chunk beside 96 decodes reached 16.7 GiB (8 GiB of it reserved but unallocated) and failed to allocate wq_b's 2 GiB output.

Functions:

  • gemm_sizes –

    One token count per AITER tuned-GEMM bucket in (floor, max_m].

_linear_groups(models)

One linear layer per distinct quant method and weight geometry.

Source code in vllm/models/deepseek_v41/amd/akr_warmup.py
def _linear_groups(models: list[torch.nn.Module]) -> list[torch.nn.Module]:
    """One linear layer per distinct quant method and weight geometry."""
    from vllm.model_executor.layers.linear import LinearBase

    seen: dict[tuple, torch.nn.Module] = {}
    for model in models:
        for mod in model.modules():
            w = getattr(mod, "weight", None)
            if (
                not isinstance(mod, LinearBase)
                or getattr(mod, "quant_method", None) is None
                or not isinstance(w, torch.Tensor)
            ):
                continue
            s = getattr(mod, "weight_scale", None)
            key = (
                type(mod.quant_method).__name__,
                int(getattr(mod, "input_size_per_partition", mod.input_size)),
                tuple(w.shape),
                w.dtype,
                tuple(s.shape) if isinstance(s, torch.Tensor) else None,
                bool(getattr(w, "is_shuffled", False)),
            )
            seen.setdefault(key, mod)
    return list(seen.values())

_warm_wo_a(models, sizes, device)

The stock grouped MXFP8 wo_a is not a LinearBase.apply.

Source code in vllm/models/deepseek_v41/amd/akr_warmup.py
def _warm_wo_a(models: list[torch.nn.Module], sizes: list[int], device) -> int:
    """The stock grouped MXFP8 wo_a is not a `LinearBase.apply`."""
    from vllm.platforms import current_platform
    from vllm.v1.attention.ops.rocm_aiter_mla_sparse import rocm_mxfp8_wo_a_bmm

    seen: set[tuple] = set()
    calls = 0
    for model in models:
        for mod in model.modules():
            wo_a = getattr(mod, "wo_a", None)
            groups = getattr(mod, "n_local_groups", None)
            rank = getattr(mod, "o_lora_rank", None)
            w = getattr(wo_a, "weight", None)
            if not isinstance(w, torch.Tensor) or not groups or not rank:
                continue
            key = (tuple(w.shape), w.dtype, groups, rank)
            if w.element_size() != 1 or key in seen:
                continue
            seen.add(key)
            width = groups * w.shape[1]
            a = torch.zeros(
                sizes[-1], width, dtype=current_platform.fp8_dtype(), device=device
            )
            s = torch.full(
                (sizes[-1], width // 32), 127, dtype=torch.uint8, device=device
            )
            for m in sizes:
                rocm_mxfp8_wo_a_bmm(a[:m], s[:m], wo_a, groups, rank)
                calls += 1
    return calls

gemm_sizes(max_m, floor)

One token count per AITER tuned-GEMM bucket in (floor, max_m].

Source code in vllm/models/deepseek_v41/amd/akr_warmup.py
def gemm_sizes(max_m: int, floor: int) -> list[int]:
    """One token count per AITER tuned-GEMM bucket in (floor, max_m]."""
    return [m for m in _aiter_gemm_m_buckets(max_m) if m > floor]