init v0.23.0

Signed-off-by: Sun Ruoxi <sunruoxi@4paradigm.com>
This commit is contained in:
2026-08-27 15:11:51 +08:00
parent b582a8e7d1
commit 7f8a1b1f7a
2849 changed files with 712887 additions and 22001 deletions

View File

@@ -4,8 +4,7 @@ from unittest.mock import MagicMock, patch
from vllm.distributed.utils import StatelessProcessGroup
from tests.ut.base import TestBase
from vllm_ascend.distributed.device_communicators.pyhccl import \
PyHcclCommunicator
from vllm_ascend.distributed.device_communicators.pyhccl import PyHcclCommunicator
class MockHcclLib:
@@ -17,7 +16,6 @@ class MockUniqueId:
class TestPyHcclCommunicator(TestBase):
@patch.dict(os.environ, {"RANK": "0", "WORLD_SIZE": "1"})
def test_world_size_1_return_early(self):
comm = PyHcclCommunicator(
@@ -29,26 +27,17 @@ class TestPyHcclCommunicator(TestBase):
@patch.dict(os.environ, {"RANK": "0", "WORLD_SIZE": "2"})
def test_load_hccl_fail(self):
comm = PyHcclCommunicator(group=StatelessProcessGroup(
0, 2, None, None),
device="npu:0",
library_path="/not/exist/path/libhccl.so")
comm = PyHcclCommunicator(
group=StatelessProcessGroup(0, 2, None, None), device="npu:0", library_path="/not/exist/path/libhccl.so"
)
self.assertTrue(comm.disabled)
@patch(
"vllm_ascend.distributed.device_communicators.pyhccl_wrapper.HCCLLibrary",
MockHcclLib)
@patch(
"vllm_ascend.distributed.device_communicators.pyhccl_wrapper.hcclUniqueId",
MockUniqueId)
@patch("vllm_ascend.distributed.device_communicators.pyhccl_wrapper.HCCLLibrary", MockHcclLib)
@patch("vllm_ascend.distributed.device_communicators.pyhccl_wrapper.hcclUniqueId", MockUniqueId)
@patch("torch.npu.device")
@patch("vllm_ascend.utils.current_stream",
return_value=MagicMock(npu_stream=5678))
@patch("vllm_ascend.utils.current_stream", return_value=MagicMock(npu_stream=5678))
def test_stateless_group(self, *_):
group = StatelessProcessGroup(rank=3,
world_size=4,
store=None,
socket=None)
group = StatelessProcessGroup(rank=3, world_size=4, store=None)
comm = PyHcclCommunicator(group=group, device=3)
@@ -56,21 +45,17 @@ class TestPyHcclCommunicator(TestBase):
self.assertEqual(comm.world_size, 4)
@patch.dict(os.environ, {"RANK": "1", "WORLD_SIZE": "2"})
@patch(
"vllm_ascend.distributed.device_communicators.pyhccl_wrapper.HCCLLibrary",
MockHcclLib)
@patch(
"vllm_ascend.distributed.device_communicators.pyhccl_wrapper.hcclUniqueId",
MockUniqueId)
@patch("vllm_ascend.distributed.device_communicators.pyhccl_wrapper.HCCLLibrary", MockHcclLib)
@patch("vllm_ascend.distributed.device_communicators.pyhccl_wrapper.hcclUniqueId", MockUniqueId)
@patch("torch.distributed.is_initialized", return_value=True)
@patch("torch.distributed.get_backend", return_value="nccl")
@patch("torch.distributed.Backend.HCCL", "hccl", create=True)
@patch("torch.distributed.get_rank", return_value=1)
@patch("torch.distributed.get_world_size", return_value=2)
@patch("torch.distributed.get_process_group_ranks", return_value=[0, 1])
@patch("torch.distributed.broadcast")
@patch("torch.npu.device")
@patch("vllm_ascend.utils.current_stream",
return_value=MagicMock(npu_stream=1234))
@patch("vllm_ascend.utils.current_stream", return_value=MagicMock(npu_stream=1234))
def test_multi_gpu_pg_torch(
self,
*_,

View File

@@ -5,13 +5,21 @@ from torch.distributed import ReduceOp
from tests.ut.base import TestBase
from vllm_ascend.distributed.device_communicators.pyhccl_wrapper import (
Function, HCCLLibrary, aclrtStream_t, buffer_type, hcclComm_t,
hcclDataType_t, hcclDataTypeEnum, hcclRedOp_t, hcclRedOpTypeEnum,
hcclResult_t, hcclUniqueId)
Function,
HCCLLibrary,
aclrtStream_t,
buffer_type,
hcclComm_t,
hcclDataType_t,
hcclDataTypeEnum,
hcclRedOp_t,
hcclRedOpTypeEnum,
hcclResult_t,
hcclUniqueId,
)
class TestHcclUniqueId(TestBase):
def test_construct(self):
uid = hcclUniqueId()
uid.internal[0] = 12
@@ -20,7 +28,6 @@ class TestHcclUniqueId(TestBase):
class TestHcclDataTypeEnum(TestBase):
def test_torch_dtype_mapping(self):
expected = {
torch.int8: hcclDataTypeEnum.hcclInt8,
@@ -35,8 +42,7 @@ class TestHcclDataTypeEnum(TestBase):
for torch_dtype, expected_enum in expected.items():
with self.subTest(torch_dtype=torch_dtype):
self.assertEqual(hcclDataTypeEnum.from_torch(torch_dtype),
expected_enum)
self.assertEqual(hcclDataTypeEnum.from_torch(torch_dtype), expected_enum)
def test_unsupported_dtype_raises(self):
with self.assertRaises(ValueError):
@@ -44,7 +50,6 @@ class TestHcclDataTypeEnum(TestBase):
class TestHcclRedOpTypeEnum(TestBase):
def test_torch_reduce_op_mapping(self):
expected = {
ReduceOp.SUM: hcclRedOpTypeEnum.hcclSum,
@@ -55,8 +60,7 @@ class TestHcclRedOpTypeEnum(TestBase):
for torch_op, expected_enum in expected.items():
with self.subTest(torch_op=torch_op):
self.assertEqual(hcclRedOpTypeEnum.from_torch(torch_op),
expected_enum)
self.assertEqual(hcclRedOpTypeEnum.from_torch(torch_op), expected_enum)
def test_unsupported_op_raises(self):
unsupported_op = "NOT_EXIST"
@@ -65,7 +69,6 @@ class TestHcclRedOpTypeEnum(TestBase):
class TestFunction(TestBase):
def test_construct_with_valid_args(self):
func = Function(name="foo", restype=int, argtypes=[int, str, float])
self.assertEqual(func.name, "foo")
@@ -74,7 +77,6 @@ class TestFunction(TestBase):
class TestHCLLLibrary(TestBase):
def test_init_with_nonexistent_so(self):
fake_path = "/definitely/not/exist/libhccl.so"
with self.assertRaises(OSError):
@@ -127,7 +129,6 @@ class TestHCLLLibrary(TestBase):
@patch.object(HCCLLibrary, "HCCL_CHECK")
def test_hccl_all_reduce(self, mock_hccl_check):
lib = HCCLLibrary.__new__(HCCLLibrary)
lib._funcs = {"HcclAllReduce": MagicMock(return_value=0)}
sendbuff = buffer_type()
@@ -138,16 +139,13 @@ class TestHCLLLibrary(TestBase):
comm = hcclComm_t()
stream = aclrtStream_t()
lib.hcclAllReduce(sendbuff, recvbuff, count, datatype, op, comm,
stream)
lib.hcclAllReduce(sendbuff, recvbuff, count, datatype, op, comm, stream)
lib._funcs["HcclAllReduce"].assert_called_once_with(
sendbuff, recvbuff, count, datatype, op, comm, stream)
lib._funcs["HcclAllReduce"].assert_called_once_with(sendbuff, recvbuff, count, datatype, op, comm, stream)
mock_hccl_check.assert_called_once_with(0)
@patch.object(HCCLLibrary, "HCCL_CHECK")
def test_hccl_broad_cast(self, mock_hccl_check):
lib = HCCLLibrary.__new__(HCCLLibrary)
lib._funcs = {"HcclBroadcast": MagicMock(return_value=0)}
buff = buffer_type()
@@ -159,8 +157,7 @@ class TestHCLLLibrary(TestBase):
lib.hcclBroadcast(buff, count, datatype, root, comm, stream)
lib._funcs["HcclBroadcast"].assert_called_once_with(
buff, count, datatype, root, comm, stream)
lib._funcs["HcclBroadcast"].assert_called_once_with(buff, count, datatype, root, comm, stream)
mock_hccl_check.assert_called_once_with(0)
@patch.object(HCCLLibrary, "HCCL_CHECK")