def maybe_create_gemm_rs(
vllm_config: VllmConfig, projections: list[LinearBase]
) -> MuseSparkGemmRs | None:
"""Collectively create a workspace for the measured B300 TP4/TP8 deployments."""
pc = vllm_config.parallel_config
if (
not current_platform.is_cuda()
or not current_platform.is_device_capability(103)
or pc.tensor_parallel_size not in (4, 8)
or pc.pipeline_parallel_size != 1
or pc.use_ubatching
or vllm_config.lora_config is not None
or vllm_config.model_config.dtype != torch.bfloat16
or vllm_config.scheduler_config.max_num_batched_tokens < 512
):
return None
tp_group = get_tp_group()
eligible = torch.tensor(
int(any(MuseSparkGemmRs.supports_projection(p) for p in projections))
)
dist.all_reduce(eligible, op=dist.ReduceOp.MIN, group=tp_group.cpu_group)
if not eligible.item():
return None
if not all(in_the_same_node_as(tp_group.cpu_group, source_rank=0)):
return None
physical_id = current_platform.visible_device_id_to_physical_device_id(
torch.accelerator.current_device_index()
)
physical_ids = [None] * tp_group.world_size
dist.all_gather_object(physical_ids, physical_id, group=tp_group.cpu_group)
if not current_platform.is_fully_connected(physical_ids):
return None
from vllm.models.common.ops.gemm_rs_ar import (
GemmRsAr,
Sm100GemmRsArBF16,
)
try:
kernel = GemmRsAr(
max_M=vllm_config.scheduler_config.max_num_batched_tokens, N=8192
)
except RuntimeError as exc:
logger.warning_once(
"Muse Spark GEMM-RS workspace unavailable; using separate GEMM "
"and reduce-scatter: %s",
exc,
)
return None
# JIT-compile before CUDA graph capture, bypassing the shared singleton.
for bn, cta_group in ((128, 1), (128, 2), (256, 2)):
Sm100GemmRsArBF16.compile(kernel.rank, kernel.world_size, bn, cta_group)
logger.info_once(
"Muse Spark attention GEMM-RS enabled for TP%d BF16, aligned M >= 512.",
pc.tensor_parallel_size,
)
return MuseSparkGemmRs(kernel)