[Kernel][DSV4.1] Fuse MXFP8 wo_b GEMM with sequence-parallel reduce-scatter (#57428)
Signed-off-by: Thien Tran <gau.nernst@yahoo.com.sg> Signed-off-by: Canlin <canlinguosdu@gmail.com> Co-authored-by: Thien Tran <gau.nernst@yahoo.com.sg> Co-authored-by: OpenAI Codex <codex@openai.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Jee Jee Li <pandaleefree@gmail.com>
This commit is contained in:
co-authored by
Thien Tran
OpenAI Codex
Claude Fable 5.1
Jee Jee Li
parent
a6c47fbbf4
commit
f92b78f6ef
@@ -160,54 +160,23 @@ def maybe_init_gemm_rs_ar(vllm_config: VllmConfig, use_sequence_parallel: bool)
|
||||
# its singleton to exactly one mode.
|
||||
all_reduce = not use_sequence_parallel
|
||||
mode = "GEMM-AR" if all_reduce else "GEMM-RS"
|
||||
enabled = envs.VLLM_KIMI_K3_GEMM_AR if all_reduce else envs.VLLM_KIMI_K3_GEMM_RS
|
||||
enabled = envs.VLLM_KIMI_K3_GEMM_AR if all_reduce else envs.VLLM_ENABLE_GEMM_RS
|
||||
if not enabled:
|
||||
return False
|
||||
|
||||
parallel_config = vllm_config.parallel_config
|
||||
tp_size = parallel_config.tensor_parallel_size
|
||||
if parallel_config.use_ubatching:
|
||||
reason = "ubatching is enabled"
|
||||
elif vllm_config.model_config.dtype != torch.bfloat16:
|
||||
reason = "the model dtype is not BF16"
|
||||
elif not current_platform.is_cuda():
|
||||
reason = "the device is not CUDA"
|
||||
elif not current_platform.is_device_capability_family(100):
|
||||
reason = "the device is not SM100-family"
|
||||
elif not 1 < tp_size <= 16:
|
||||
reason = "TP size is not in the supported range 2-16"
|
||||
elif 128 % tp_size != 0:
|
||||
reason = "TP size does not divide 128"
|
||||
else:
|
||||
reason = None
|
||||
|
||||
if reason is not None:
|
||||
logger.warning_once("%s is disabled because %s.", mode, reason)
|
||||
return False
|
||||
|
||||
from vllm.models.kimi_k3.nvidia.ops.cute_dsl.gemm_rs_ar import init_gemm_rs_ar
|
||||
# The kernel module pulls in cute_dsl, so import it only once the flag
|
||||
# asks for it.
|
||||
from vllm.model_executor.kernels.linear.cute_dsl.gemm_rs_ar import (
|
||||
maybe_init_gemm_rs_ar as maybe_init_shared_gemm_rs_ar,
|
||||
)
|
||||
|
||||
config = vllm_config.model_config.hf_text_config
|
||||
try:
|
||||
init_gemm_rs_ar(
|
||||
max_M=vllm_config.scheduler_config.max_num_batched_tokens,
|
||||
N=config.hidden_size,
|
||||
all_reduce=all_reduce,
|
||||
)
|
||||
except RuntimeError as e:
|
||||
logger.warning_once(
|
||||
"%s is disabled because initialization failed: %s. This may mean "
|
||||
"the TP ranks do not share one NVLink domain.",
|
||||
mode,
|
||||
e,
|
||||
)
|
||||
if not maybe_init_shared_gemm_rs_ar(
|
||||
vllm_config, N=config.hidden_size, all_reduce=all_reduce
|
||||
):
|
||||
return False
|
||||
if all_reduce:
|
||||
logger.info_once(
|
||||
"GEMM-AR is enabled. To disable it, set VLLM_KIMI_K3_GEMM_AR=0."
|
||||
)
|
||||
else:
|
||||
logger.info_once("GEMM-RS is enabled.")
|
||||
flag = "VLLM_KIMI_K3_GEMM_AR" if all_reduce else "VLLM_ENABLE_GEMM_RS"
|
||||
logger.info_once("To disable %s, set %s=0.", mode, flag)
|
||||
return True
|
||||
|
||||
|
||||
@@ -276,7 +245,7 @@ class KimiMLP(nn.Module):
|
||||
not use_sequence_parallel and reduce_results
|
||||
)
|
||||
if use_gemm_rs_ar and run_gemm_rs_ar:
|
||||
from vllm.models.kimi_k3.nvidia.ops.cute_dsl.gemm_rs_ar import (
|
||||
from vllm.model_executor.kernels.linear.cute_dsl.gemm_rs_ar import (
|
||||
get_gemm_rs_ar,
|
||||
)
|
||||
|
||||
@@ -309,7 +278,7 @@ class KimiMLP(nn.Module):
|
||||
x = self.act_fn(gate_up)
|
||||
|
||||
if self.gemm_rs_ar is not None and self.gemm_rs_ar.should_run(x):
|
||||
return self.gemm_rs_ar(x, self.down_proj.weight)
|
||||
return self.gemm_rs_ar.apply(x, self.down_proj)
|
||||
|
||||
x, _ = self.down_proj(x)
|
||||
if self.shard_sequence_parallel:
|
||||
|
||||
Reference in New Issue
Block a user