[AMD] Add AITER Custom All-Reduce (#13102)
Co-authored-by: Brayden Zhong <b8zhong@uwaterloo.ca> Co-authored-by: HaiShaw <hixiao@gmail.com>
This commit is contained in:
@@ -19,7 +19,7 @@ from sglang.srt.distributed.device_communicators.custom_all_reduce_utils import
|
||||
)
|
||||
from sglang.srt.distributed.parallel_state import in_the_same_node_as
|
||||
from sglang.srt.environ import envs
|
||||
from sglang.srt.utils import is_cuda, is_hip, log_info_on_rank0
|
||||
from sglang.srt.utils import get_bool_env_var, is_cuda, is_hip, log_info_on_rank0
|
||||
|
||||
try:
|
||||
# Use custom allreduce from sgl kernel (ROCM and TRT-LLM)
|
||||
@@ -416,3 +416,23 @@ class CustomAllreduce:
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
||||
|
||||
def dispatch_custom_allreduce():
|
||||
"""Return the CustomAllreduce class to use (aiter on ROCm if enabled)."""
|
||||
if is_hip() and get_bool_env_var("SGLANG_USE_AITER_AR", default="true"):
|
||||
try:
|
||||
from aiter.dist.device_communicators.custom_all_reduce import (
|
||||
CustomAllreduce as AiterCustomAllreduce,
|
||||
)
|
||||
|
||||
logger.info("Using AiterCustomAllreduce for ROCm.")
|
||||
return AiterCustomAllreduce
|
||||
except ImportError as e:
|
||||
logger.warning(
|
||||
"Aiter custom all-reduce not available (optional dependency missing); "
|
||||
"falling back to sglang CustomAllreduce. Details: %s",
|
||||
e,
|
||||
)
|
||||
return CustomAllreduce
|
||||
return CustomAllreduce
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import logging
|
||||
import os
|
||||
from enum import Enum
|
||||
from functools import cache
|
||||
from typing import Union
|
||||
|
||||
import torch
|
||||
@@ -31,6 +32,7 @@ except Exception:
|
||||
quick_ar = False
|
||||
|
||||
|
||||
@cache
|
||||
def qr_rocm_arch_available():
|
||||
if not _is_hip:
|
||||
return False
|
||||
|
||||
@@ -327,7 +327,7 @@ class GroupCoordinator:
|
||||
|
||||
# Lazy import to avoid documentation build error
|
||||
from sglang.srt.distributed.device_communicators.custom_all_reduce import (
|
||||
CustomAllreduce,
|
||||
dispatch_custom_allreduce,
|
||||
)
|
||||
from sglang.srt.distributed.device_communicators.pymscclpp import (
|
||||
PyMscclppCommunicator,
|
||||
@@ -366,12 +366,13 @@ class GroupCoordinator:
|
||||
device=self.device,
|
||||
)
|
||||
|
||||
self.ca_comm: Optional[CustomAllreduce] = None
|
||||
self.ca_comm: Optional[Any] = None
|
||||
self.qr_comm: Optional[QuickAllReduce] = None
|
||||
if use_custom_allreduce and self.world_size > 1:
|
||||
# Initialize a custom fast all-reduce implementation.
|
||||
try:
|
||||
self.ca_comm = CustomAllreduce(
|
||||
CAClass = dispatch_custom_allreduce()
|
||||
self.ca_comm = CAClass(
|
||||
group=self.cpu_group,
|
||||
device=self.device,
|
||||
)
|
||||
|
||||
@@ -7,8 +7,11 @@ import time
|
||||
import numpy as np
|
||||
|
||||
import sglang as sgl
|
||||
from sglang.srt.utils import is_hip
|
||||
from sglang.utils import download_and_cache_file, read_jsonl
|
||||
|
||||
_is_hip = is_hip()
|
||||
|
||||
|
||||
def test_few_shot_qa():
|
||||
@sgl.function
|
||||
@@ -537,7 +540,7 @@ def test_hellaswag_select():
|
||||
accuracy_gen = np.mean(np.array(preds_gen) == np.array(labels))
|
||||
print(f"{accuracy=}, {accuracy_gen=}")
|
||||
assert np.abs(accuracy_gen - accuracy) < 0.1
|
||||
assert np.abs(latency_gen - latency) < 1
|
||||
assert np.abs(latency_gen - latency) < 1 if not _is_hip else 2
|
||||
|
||||
return accuracy, latency
|
||||
|
||||
|
||||
Reference in New Issue
Block a user