Repository navigation
[ROCm][DSv4.1] Warm up AITER FlyDSL MXFP8 GEMM kernels before serving #64637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Fangzhou-Ai
wants to merge
2
commits into
vllm-project:main
from
Fangzhou-Ai:rocm-flydsl-mxfp8-warmup
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,6 +230,14 @@ def kernel_warmup(worker: "Worker", *, process_local_only: bool = False): | |
| ) | ||
|
|
||
| rocm_segmented_attn_autotune_warmup(worker) | ||
| if worker.vllm_config.kernel_config.enable_jit_warmup: | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be gated as ROCm only |
||
| from vllm.model_executor.warmup.rocm_flydsl_mxfp8_warmup import ( | ||
| rocm_flydsl_mxfp8_warmup, | ||
| ) | ||
|
|
||
| rocm_flydsl_mxfp8_warmup( | ||
| worker.get_model(), worker.scheduler_config.max_num_batched_tokens | ||
| ) | ||
|
|
||
| flashinfer_sparse_mla_decode_autotune_warmup(worker) | ||
| deepseek_v4_sparse_mla_attention_warmup(worker) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| """Warm up AITER's FlyDSL GEMM for 32x32-block MXFP8 linears on gfx950. | ||
|
|
||
| AITER picks a FlyDSL kernel per (padded) token count and JIT-compiles it on | ||
| first use. Without a warmup, a cold server compiles several of them inside its | ||
| first long prefill step, which can exceed the execute-model RPC timeout. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import time | ||
|
|
||
| import torch | ||
|
|
||
| from vllm.logger import init_logger | ||
|
|
||
| logger = init_logger(__name__) | ||
|
|
||
|
|
||
| def _flydsl_layers(model: torch.nn.Module): | ||
| from vllm.model_executor.kernels.linear.mxfp8.rocm_native import ( | ||
| RocmDotScaledMxfp8LinearKernel, | ||
| ) | ||
|
|
||
| for module in model.modules(): | ||
| # Quark keeps the kernel on the layer's scheme, ModelOpt on the method. | ||
| kernel = getattr(getattr(module, "scheme", None), "ocp_mx_linear", None) | ||
| if kernel is None: | ||
| kernel = getattr(getattr(module, "quant_method", None), "kernel", None) | ||
| if isinstance(kernel, RocmDotScaledMxfp8LinearKernel) and kernel._use_flydsl( | ||
| module | ||
| ): | ||
| yield module | ||
|
|
||
|
|
||
| def rocm_flydsl_mxfp8_warmup(model: torch.nn.Module, max_tokens: int) -> None: | ||
| """Run each FlyDSL MXFP8 linear shape once per distinct kernel AITER can | ||
| pick for 1..max_tokens tokens, so serving compiles none of them.""" | ||
| from aiter.ops.gemm_op_a8w8 import get_mxscale_bpreshuffle_config | ||
|
|
||
| from vllm._aiter_ops import rocm_aiter_ops | ||
|
|
||
| layers = {tuple(m.weight.shape): m for m in _flydsl_layers(model)} | ||
| if not layers: | ||
| return | ||
| start, num_kernels = time.perf_counter(), 0 | ||
| device = next(iter(layers.values())).weight.device | ||
| max_k = max(k for _, k in layers) | ||
| x_buf = torch.zeros(max_tokens * max_k, dtype=torch.float8_e4m3fn, device=device) | ||
| scale_buf = torch.full( | ||
| (max_tokens * max_k // 32,), 127, dtype=torch.uint8, device=device | ||
| ).view(torch.float8_e8m0fnu) | ||
| for (n, k), layer in layers.items(): | ||
| x_q = x_buf[: max_tokens * k].view(max_tokens, k) | ||
| x_scale = scale_buf[: max_tokens * k // 32].view(max_tokens, k // 32) | ||
| kernels = set() | ||
| for m in range(1, max_tokens + 1): | ||
| row = get_mxscale_bpreshuffle_config(m, n, k, "32x32") | ||
| if row is not None: | ||
| name = row["kernelName"] | ||
| elif m & (m - 1) == 0 or m == max_tokens: | ||
| # Untuned: AITER's fallback heuristic, sampled at powers of two. | ||
| name = ("untuned", m) | ||
| else: | ||
| continue | ||
| if name in kernels: | ||
| continue | ||
| kernels.add(name) | ||
| rocm_aiter_ops.gemm_a8w8_blockscale_bpreshuffle( | ||
| x_q[:m], | ||
| layer.weight, | ||
| x_scale[:m], | ||
| layer.weight_scale.view(torch.float8_e8m0fnu), | ||
| output_dtype=torch.bfloat16, | ||
| ) | ||
| num_kernels += len(kernels) | ||
| torch.accelerator.synchronize() | ||
| logger.info( | ||
| "Warmed up %d FlyDSL MXFP8 GEMM kernels for %d shapes in %.1fs.", | ||
| num_kernels, | ||
| len(layers), | ||
| time.perf_counter() - start, | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a universal limit for all FlyDSL GEMM used in vLLM?