Skip to content

[Test] Add unittests for vllm_ascend #1662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 96 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
f0a0939
add uts for multistream
SunnyLee151064 Jul 8, 2025
75faf72
add uts for multistream
SunnyLee151064 Jul 8, 2025
4cd62fd
add uts for multistream
SunnyLee151064 Jul 8, 2025
7603645
add uts for multistream
SunnyLee151064 Jul 8, 2025
4149c58
add uts for multistream
SunnyLee151064 Jul 8, 2025
1ffefd3
add uts for multistream
SunnyLee151064 Jul 8, 2025
54f40a4
Update test_ms_split.py
SunnyLee151064 Jul 9, 2025
a0fea3b
Update test_metadata.py
SunnyLee151064 Jul 9, 2025
a44834f
Update test_ms_split.py
SunnyLee151064 Jul 9, 2025
a4f4520
Update test_metadata.py
SunnyLee151064 Jul 9, 2025
4e86153
Update test_metadata.py
SunnyLee151064 Jul 9, 2025
b96a747
Update test_ms_split.py
SunnyLee151064 Jul 9, 2025
4468bb0
Update test_metadata.py
SunnyLee151064 Jul 9, 2025
d665990
Update test_metadata.py
SunnyLee151064 Jul 9, 2025
9cc55d2
Update test_ms_split.py
SunnyLee151064 Jul 9, 2025
d7e1a85
Update test_metadata.py
SunnyLee151064 Jul 9, 2025
cf621fc
Update test_metadata.py
SunnyLee151064 Jul 9, 2025
93dd06d
Update test_metadata.py
SunnyLee151064 Jul 9, 2025
dd85543
Update test_ms_split.py
SunnyLee151064 Jul 9, 2025
6a9bfd4
Update test_metadata.py
SunnyLee151064 Jul 9, 2025
db28864
Update test_metadata.py
SunnyLee151064 Jul 9, 2025
655c763
Update test_ms_split.py
SunnyLee151064 Jul 9, 2025
c772aa4
Update test_metadata.py
SunnyLee151064 Jul 10, 2025
9ddabf5
stash
SunnyLee151064 Jul 10, 2025
0fde5ef
test_mla
SunnyLee151064 Jul 11, 2025
2547c03
stash
Jul 14, 2025
7683245
format
Jul 15, 2025
670ac87
Update conftest.py
SunnyLee151064 Jul 15, 2025
6b1a01d
Update test_eagle_correctness.py
SunnyLee151064 Jul 15, 2025
f65f6a9
Update test_simple.py
SunnyLee151064 Jul 15, 2025
66a6abc
Update test_rotary_embedding.py
SunnyLee151064 Jul 15, 2025
3e71288
Update test_attention_v1.py
SunnyLee151064 Jul 15, 2025
8dd3196
Update test_attention_v1.py
SunnyLee151064 Jul 15, 2025
71d8bf1
Update base.py
SunnyLee151064 Jul 15, 2025
1157041
Update test_simple_buffer.py
SunnyLee151064 Jul 15, 2025
df2c81d
Update test_simple_pipe.py
SunnyLee151064 Jul 15, 2025
ae3e0e4
Update test_parallel_state.py
SunnyLee151064 Jul 15, 2025
f8e9254
Update test_simple_connector.py
SunnyLee151064 Jul 15, 2025
562980c
Update test_expert_load_balancer.py
SunnyLee151064 Jul 15, 2025
f9216c9
Update test_rotary_embedding.py
SunnyLee151064 Jul 15, 2025
e1c2dcf
Update test_patch_distributed.py
SunnyLee151064 Jul 15, 2025
d4bb12c
Update test_patch_sampler.py
SunnyLee151064 Jul 15, 2025
ecc69f4
Update test_quant_config.py
SunnyLee151064 Jul 15, 2025
922f477
Update test_quant_config.py
SunnyLee151064 Jul 15, 2025
467e763
Update test_quantizer.py
SunnyLee151064 Jul 15, 2025
6a13678
Update test_w8a8.py
SunnyLee151064 Jul 15, 2025
92d4ddd
Update test_ascend_config.py
SunnyLee151064 Jul 15, 2025
462d97f
Update test_platform.py
SunnyLee151064 Jul 15, 2025
37fd017
Update test_utils.py
SunnyLee151064 Jul 15, 2025
6525e8c
Update test_input_batch.py
SunnyLee151064 Jul 15, 2025
243e85f
Update test_pooling_model_runner.py
SunnyLee151064 Jul 15, 2025
e50d7df
Update utils.py
SunnyLee151064 Jul 15, 2025
de7f495
Update mla_v1.py
SunnyLee151064 Jul 15, 2025
4887b90
Update mla_v1.py
SunnyLee151064 Jul 15, 2025
93fc274
Update piecewise_backend.py
SunnyLee151064 Jul 15, 2025
4dd9958
Update scheduler.py
SunnyLee151064 Jul 15, 2025
8291ae4
Update scheduler.py
SunnyLee151064 Jul 15, 2025
44f02ee
Update scheduler.py
SunnyLee151064 Jul 15, 2025
7a06187
Update scheduler.py
SunnyLee151064 Jul 15, 2025
3fc1350
Update __init__.py
SunnyLee151064 Jul 15, 2025
ae2e45e
Update pyhccl.py
SunnyLee151064 Jul 15, 2025
0e869d1
修改靠近
Jul 15, 2025
20ad86e
修改对其
Jul 15, 2025
9a669d5
修改对齐
Jul 15, 2025
96d4eb1
修改对齐
Jul 15, 2025
fa0b0e6
Delete tests/ut/__init__.py
SunnyLee151064 Jul 21, 2025
bb2e458
Update test_piecewise_backend.py
SunnyLee151064 Jul 21, 2025
bbce235
Update test_scheduler.py
SunnyLee151064 Jul 21, 2025
6a41744
Update test_pyhccl.py
SunnyLee151064 Jul 21, 2025
386e149
Update test_pyhccl_wrapper.py
SunnyLee151064 Jul 21, 2025
c08dbc4
Update test_base.py
SunnyLee151064 Jul 21, 2025
74f3a16
Update test_metadata.py
SunnyLee151064 Jul 21, 2025
042543d
Update test_ms_split.py
SunnyLee151064 Jul 21, 2025
83df950
Update test_cache.py
SunnyLee151064 Jul 21, 2025
265daa1
Update test_mla_v1.py
SunnyLee151064 Jul 21, 2025
ce2a35d
Update test_piecewise_backend.py
SunnyLee151064 Jul 21, 2025
c8897c0
Update test_piecewise_backend.py
SunnyLee151064 Jul 21, 2025
33f6538
Update test_pyhccl.py
SunnyLee151064 Jul 21, 2025
9a61ee3
Update test_pyhccl_wrapper.py
SunnyLee151064 Jul 21, 2025
94f98f8
Update test_mla_v1.py
SunnyLee151064 Jul 21, 2025
706eb86
Update test_mla_v1.py
SunnyLee151064 Jul 21, 2025
de24aa1
Update test_scheduler.py
SunnyLee151064 Jul 21, 2025
bbb9cc7
Update test_mla_v1.py
SunnyLee151064 Jul 21, 2025
ac007a9
Update test_scheduler.py
SunnyLee151064 Jul 21, 2025
9c797d7
Update test_scheduler.py
SunnyLee151064 Jul 21, 2025
a917785
Update test_scheduler.py
SunnyLee151064 Jul 21, 2025
afb36ec
Update test_mla_v1.py
SunnyLee151064 Jul 21, 2025
160cf76
Delete tests/ut/compilation/test_piecewise_backend.py
SunnyLee151064 Jul 21, 2025
8bf5cf9
Update test_scheduler.py
SunnyLee151064 Jul 21, 2025
4a7d9a3
Update test_scheduler.py
SunnyLee151064 Jul 21, 2025
7117297
Update test_cache.py
SunnyLee151064 Jul 21, 2025
38f4ffc
Update test_cache.py
SunnyLee151064 Jul 21, 2025
8cf8adf
Update test_mla_v1.py
SunnyLee151064 Jul 21, 2025
5242305
Update test_cache.py
SunnyLee151064 Jul 21, 2025
02e06a4
Update test_mla_v1.py
SunnyLee151064 Jul 21, 2025
59398c6
Update test_mla_v1.py
SunnyLee151064 Jul 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed tests/__init__.py
Empty file.
666 changes: 666 additions & 0 deletions tests/ut/attention/test_mla_v1.py

Large diffs are not rendered by default.

722 changes: 722 additions & 0 deletions tests/ut/core/test_scheduler.py

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions tests/ut/distributed/device_communicators/test_pyhccl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import os
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


class MockHcclLib:

def __init__(self, path):
pass

def hcclGetUniqueId(self):
uid = MagicMock()
uid.internal = list(range(128)) # 128 字节随意填充
return uid

def hcclCommInitRank(self, rank):
return f"fake_comm_{rank}"

def hcclAllReduce(self, *args, **kw):
pass


class MockUniqueId:

def __init__(self):
self.internal = [0] * 128


class TestPyHcclCommunicator(TestBase):

@patch.dict(os.environ, {"RANK": "0", "WORLD_SIZE": "1"})
def test_world_size_1_return_early(self):
comm = PyHcclCommunicator(
group=StatelessProcessGroup(0, 1, None, None),
device="npu:0",
)
self.assertTrue(comm.disabled)
self.assertFalse(comm.available)

@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")
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("torch.npu.device")
@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)

comm = PyHcclCommunicator(group=group, device=3)

self.assertEqual(comm.rank, 3)
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("torch.distributed.is_initialized", return_value=True)
@patch("torch.distributed.get_backend", return_value="nccl")
@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))
def test_multi_gpu_pg_torch(
self,
*_,
):
fake_pg = MagicMock()
comm = PyHcclCommunicator(group=fake_pg, device="npu:1")

self.assertEqual(comm.rank, 1)
self.assertEqual(comm.world_size, 2)
self.assertFalse(comm.available)
self.assertTrue(comm.disabled)
173 changes: 173 additions & 0 deletions tests/ut/distributed/device_communicators/test_pyhccl_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
from unittest.mock import MagicMock, patch

import torch
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)


class TestHcclUniqueId(TestBase):

def test_construct(self):
uid = hcclUniqueId()
uid.internal[0] = 12
self.assertEqual(len(uid.internal), 4108)
self.assertEqual(uid.internal[0], 12)


class TestHcclDataTypeEnum(TestBase):

def test_torch_dtype_mapping(self):
expected = {
torch.int8: hcclDataTypeEnum.hcclInt8,
torch.uint8: hcclDataTypeEnum.hcclUint8,
torch.int32: hcclDataTypeEnum.hcclInt32,
torch.int64: hcclDataTypeEnum.hcclInt64,
torch.float16: hcclDataTypeEnum.hcclFloat16,
torch.float32: hcclDataTypeEnum.hcclFloat32,
torch.float64: hcclDataTypeEnum.hcclFloat64,
torch.bfloat16: hcclDataTypeEnum.hcclBfloat16,
}

for torch_dtype, expected_enum in expected.items():
with self.subTest(torch_dtype=torch_dtype):
self.assertEqual(hcclDataTypeEnum.from_torch(torch_dtype),
expected_enum)

def test_unsupported_dtype_raises(self):
with self.assertRaises(ValueError):
hcclDataTypeEnum.from_torch(torch.complex64)


class TestHcclRedOpTypeEnum(TestBase):

def test_torch_reduce_op_mapping(self):
expected = {
ReduceOp.SUM: hcclRedOpTypeEnum.hcclSum,
ReduceOp.PRODUCT: hcclRedOpTypeEnum.hcclProd,
ReduceOp.MAX: hcclRedOpTypeEnum.hcclMax,
ReduceOp.MIN: hcclRedOpTypeEnum.hcclMin,
}

for torch_op, expected_enum in expected.items():
with self.subTest(torch_op=torch_op):
self.assertEqual(hcclRedOpTypeEnum.from_torch(torch_op),
expected_enum)

def test_unsupported_op_raises(self):
unsupported_op = "NOT_EXIST"
with self.assertRaises(ValueError):
hcclRedOpTypeEnum.from_torch(unsupported_op)


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")
self.assertIs(func.restype, int)
self.assertEqual(func.argtypes, [int, str, float])


class TestHCLLLibrary(TestBase):

def test_init_with_nonexistent_so(self):
fake_path = "/definitely/not/exist/libhccl.so"
with self.assertRaises(OSError):
HCCLLibrary(fake_path)

def test_hccl_get_error_string(self):
lib = MagicMock(sepc=HCCLLibrary)
mock_fn = MagicMock()
mock_fn.return_value = "HCCL internal error"
lib.hcclGetErrorString = mock_fn

result = hcclResult_t(1)
msg = lib.hcclGetErrorString(result)
self.assertEqual(msg, "HCCL internal error")
mock_fn.assert_called_once()

def test_hccl_check(self):
lib = HCCLLibrary.__new__(HCCLLibrary)
mock_fn = MagicMock()
mock_fn.return_value = "fake error"
lib.hcclGetErrorString = mock_fn
result = hcclResult_t(123)
with self.assertRaises(RuntimeError) as cm:
lib.HCCL_CHECK(result)

self.assertEqual(str(cm.exception), "HCCL error: fake error")

@patch.object(HCCLLibrary, "HCCL_CHECK")
def test_hccl_get_uniqueId(self, mock_HCCL_CHECK):
lib = HCCLLibrary.__new__(HCCLLibrary)
lib._funcs = {"HcclGetRootInfo": MagicMock(return_value=0)}
unique_id = lib.hcclGetUniqueId()
self.assertIsInstance(unique_id, hcclUniqueId)
lib._funcs["HcclGetRootInfo"].assert_called_once()
mock_HCCL_CHECK.assert_called_once_with(0)

@patch.object(HCCLLibrary, "HCCL_CHECK")
def test_hccl_comm_initRank(self, mock_hccl_check):
lib = HCCLLibrary.__new__(HCCLLibrary)
lib._funcs = {"HcclCommInitRootInfo": MagicMock(return_value=0)}

world_size = 4
unique_id = hcclUniqueId()
rank = 1

comm = lib.hcclCommInitRank(world_size, unique_id, rank)
self.assertIsInstance(comm, hcclComm_t)
lib._funcs["HcclCommInitRootInfo"].assert_called_once()
mock_hccl_check.assert_called_once_with(0)

@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()
recvbuff = buffer_type()
count = 10
datatype = hcclDataType_t(1)
op = hcclRedOp_t(0)
comm = hcclComm_t()
stream = aclrtStream_t()

lib.hcclAllReduce(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()
count = 10
datatype = 1
root = 0
comm = hcclComm_t()
stream = aclrtStream_t()

lib.hcclBroadcast(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")
def test_hcclCommDestroy_success(self, mock_hccl_check):
lib = HCCLLibrary.__new__(HCCLLibrary)
lib._funcs = {"HcclCommDestroy": MagicMock(return_value=0)}
comm = hcclComm_t()
lib.hcclCommDestroy(comm)
lib._funcs["HcclCommDestroy"].assert_called_once_with(comm)
mock_hccl_check.assert_called_once_with(0)
32 changes: 32 additions & 0 deletions tests/ut/multistream/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from tests.ut.base import TestBase
from vllm_ascend.multistream.base import (MSAttentionMetadataSplitConfig,
MSEventKey)


class Testbase(TestBase):

def test_ms_event_key(self):
self.assertEqual(MSEventKey.ATTN_COM_FINISH.value, 0)
self.assertEqual(MSEventKey.ATTN_AR_FINISH.value, 1)
self.assertEqual(MSEventKey.FFN_COM_FINISH.value, 2)
self.assertEqual(MSEventKey.FFN_AR_FINISH.value, 3)
self.assertEqual(MSEventKey.MOE_BEFORE_COMM.value, 4)
self.assertEqual(MSEventKey.MOE_AFTER_COMM.value, 5)
self.assertEqual(MSEventKey.MOE_SE_COMM_FINISH.value, 6)
self.assertEqual(MSEventKey.MOE_SE_COMP_FINISH.value, 7)
self.assertEqual(MSEventKey.MOE_GATE_FINISH.value, 8)

def test_ms_attention_metadata_split_config_default(self):
config = MSAttentionMetadataSplitConfig()
self.assertEqual(config.num_micro_batches, 2)
self.assertEqual(config.min_total_tokens_to_split, 256)
self.assertEqual(config.min_prefill_tokens_to_split, 64)

def test_ms_attention_metadata_split_config_custom(self):
config = MSAttentionMetadataSplitConfig(
num_micro_batches=4,
min_total_tokens_to_split=512,
min_prefill_tokens_to_split=128)
self.assertEqual(config.num_micro_batches, 4)
self.assertEqual(config.min_total_tokens_to_split, 512)
self.assertEqual(config.min_prefill_tokens_to_split, 128)
Loading
Loading