[Build] Add build info (#1386)

Add static build_info py file to show soc and sleep mode info. It helps
to make the code clean and the error info will be more friendly for
users

This PR also added the unit test for vllm_ascend/utils.py

This PR also added the base test class for all ut in tests/ut/base.py

Signed-off-by: wangxiyuan <wangxiyuan1007@gmail.com>
This commit is contained in:
wangxiyuan
2025-06-27 09:14:43 +08:00
committed by GitHub
parent c563a08f0a
commit 5968dff4e0
11 changed files with 388 additions and 66 deletions

View File

@@ -0,0 +1,12 @@
from tests.ut.base import TestBase
class TestPatchDistributed(TestBase):
def test_GroupCoordinator_patched(self):
from vllm.distributed.parallel_state import GroupCoordinator
from vllm_ascend.patch.worker.patch_common.patch_distributed import \
GroupCoordinatorPatch
self.assertIs(GroupCoordinator, GroupCoordinatorPatch)

View File

@@ -0,0 +1,28 @@
import importlib
import os
import unittest
from unittest import mock
import torch
from vllm.v1.sample.ops import topk_topp_sampler
class TestTopKTopPSamplerOptimize(unittest.TestCase):
@mock.patch.dict(os.environ, {"VLLM_ASCEND_ENABLE_TOPK_OPTIMIZE": "1"})
@mock.patch("torch_npu.npu_top_k_top_p")
def test_npu_topk_topp_called_when_optimized(self, mock_npu_op):
import vllm_ascend.patch.worker.patch_common.patch_sampler
importlib.reload(vllm_ascend.patch.worker.patch_common.patch_sampler)
mock_npu_op.return_value = (torch.randn(1, 3))
sampler = topk_topp_sampler.TopKTopPSampler()
logits = torch.tensor([[1.0, 2.0, 3.0]])
k = torch.tensor([2])
p = torch.tensor([0.9])
generators = {0: torch.Generator()}
generators[0].manual_seed(42)
sampler.forward_native(logits, generators, k, p)
mock_npu_op.assert_called_once_with(logits, p, k)