[AMD] Support --enable-aiter-allreduce-fusion on AMD GPUs (#13747)

Co-authored-by: yctseng0211 <yctseng@amd.com>
This commit is contained in:
Hubert Lu
2026-02-24 23:11:55 -08:00
committed by GitHub
co-authored by yctseng0211
parent 73fe389dd1
commit 17b0affbdf
9 changed files with 837 additions and 18 deletions
+43 -8
View File
@@ -101,6 +101,20 @@ def apply_flashinfer_allreduce_fusion(batch_size: int):
)
def apply_aiter_all_reduce_fusion(input_tensor: torch.Tensor):
n = input_tensor.shape[-1]
total_bytes = input_tensor.numel() * input_tensor.element_size()
return (
_use_aiter
and total_bytes > 0
and n <= 16384
and total_bytes < 8 * 1024 * 8192
and get_tensor_model_parallel_world_size() != 6
and not is_dp_attention_enabled()
and get_global_server_args().enable_aiter_allreduce_fusion
)
class ScatterMode(Enum):
"""
Suppose we have TP=4, DP=2, enable-dp-attention, and the system handles seq a,b,c,d
@@ -430,11 +444,20 @@ class LayerCommunicator:
and hasattr(hidden_states, "_sglang_needs_allreduce_fusion")
and hidden_states._sglang_needs_allreduce_fusion
):
hidden_states, residual = (
self.input_layernorm.forward_with_allreduce_fusion(
if (
apply_aiter_all_reduce_fusion(hidden_states)
or apply_flashinfer_allreduce_fusion(hidden_states.shape[0])
) and hasattr(self.input_layernorm, "forward_with_allreduce_fusion"):
hidden_states, residual = (
self.input_layernorm.forward_with_allreduce_fusion(
hidden_states, residual
)
)
else:
hidden_states = tensor_model_parallel_all_reduce(hidden_states)
hidden_states, residual = self.input_layernorm(
hidden_states, residual
)
)
else:
if residual is None:
residual = hidden_states
@@ -601,7 +624,15 @@ class LayerCommunicator:
)
return (
apply_flashinfer_allreduce_fusion(batch_size)
(
apply_flashinfer_allreduce_fusion(batch_size)
or (
_use_aiter
and batch_size > 0
and get_tensor_model_parallel_world_size() != 6
and get_global_server_args().enable_aiter_allreduce_fusion
)
)
and (not self.is_last_layer)
and (self._context.tp_size > 1)
)
@@ -807,13 +838,17 @@ class CommunicateWithAllReduceAndLayerNormFn:
if hidden_states.shape[0] != 0:
hidden_states = layernorm(hidden_states)
else:
if apply_flashinfer_allreduce_fusion(hidden_states.shape[0]) and hasattr(
layernorm, "forward_with_allreduce_fusion"
):
handled = False
if (
apply_aiter_all_reduce_fusion(hidden_states)
or apply_flashinfer_allreduce_fusion(hidden_states.shape[0])
) and hasattr(layernorm, "forward_with_allreduce_fusion"):
hidden_states, residual = layernorm.forward_with_allreduce_fusion(
hidden_states, residual
)
else:
handled = True
if not handled:
hidden_states = tensor_model_parallel_all_reduce(hidden_states)
if _is_npu and context.cache is not None:
_ = prepare_weight_cache(hidden_states, context.cache)
+30 -9
View File
@@ -307,7 +307,11 @@ class RMSNorm(MultiPlatformOp):
Forward method with allreduce fusion, prioritizing flashinfer fused operations
"""
if residual is not None:
from sglang.srt.distributed import get_tensor_model_parallel_world_size
from sglang.srt.distributed import (
get_tensor_model_parallel_world_size,
tensor_model_parallel_all_reduce,
tensor_model_parallel_fused_allreduce_rmsnorm,
)
from sglang.srt.layers.flashinfer_comm_fusion import (
flashinfer_allreduce_residual_rmsnorm,
)
@@ -315,14 +319,31 @@ class RMSNorm(MultiPlatformOp):
if get_tensor_model_parallel_world_size() > 1:
if post_residual_addition is not None:
residual = residual + post_residual_addition
fused_result = flashinfer_allreduce_residual_rmsnorm(
input_tensor=x,
residual=residual,
weight=self.weight,
eps=self.variance_epsilon,
)
if fused_result[0] is not None:
return fused_result
# Prefer AITER fused AR+RMSNorm when enabled on AMD.
if _use_aiter:
fused_result = tensor_model_parallel_fused_allreduce_rmsnorm(
x, residual, self.weight, self.variance_epsilon
)
if fused_result is not None:
return fused_result
else:
fused_result = flashinfer_allreduce_residual_rmsnorm(
input_tensor=x,
residual=residual,
weight=self.weight,
eps=self.variance_epsilon,
)
if fused_result[0] is not None:
return fused_result
# For AITER route, preserve correctness when fused path is unavailable.
if (
_use_aiter
and get_global_server_args().enable_aiter_allreduce_fusion
):
x = tensor_model_parallel_all_reduce(x)
return self.forward(x, residual, None)
return self.forward(x, residual, post_residual_addition)