[NPU]Support torch_npu profiler patch API drift (#26356)
Co-authored-by: leland17 <lileliao@foxmail.com> Co-authored-by: OmX <omx@oh-my-codex.dev> Co-authored-by: ronnie_zheng <zl19940307@163.com>
This commit is contained in:
co-authored by
leland17
OmX
ronnie_zheng
parent
280280ace9
commit
4e14b50c48
@@ -0,0 +1,41 @@
|
||||
import types
|
||||
import unittest
|
||||
|
||||
from sglang.srt.utils.torch_npu_patch_utils import apply_torch_npu_patches
|
||||
from sglang.test.ci.ci_register import register_cpu_ci
|
||||
|
||||
register_cpu_ci(est_time=1, suite="base-a-test-cpu")
|
||||
|
||||
|
||||
class TestTorchNpuPatchUtils(unittest.TestCase):
|
||||
def test_apply_torch_npu_patches_uses_targeted_api_when_available(self):
|
||||
calls = []
|
||||
torch_npu = types.SimpleNamespace(
|
||||
_apply_patches=lambda patches: calls.append(("_apply_patches", patches)),
|
||||
_apply_all_patches=lambda: calls.append(("_apply_all_patches", None)),
|
||||
)
|
||||
patches = [["profiler.profile", object()]]
|
||||
|
||||
apply_torch_npu_patches(torch_npu, patches)
|
||||
|
||||
self.assertEqual(calls, [("_apply_patches", patches)])
|
||||
|
||||
def test_apply_torch_npu_patches_uses_all_patches_api_when_targeted_api_missing(
|
||||
self,
|
||||
):
|
||||
calls = []
|
||||
torch_npu = types.SimpleNamespace(
|
||||
_apply_all_patches=lambda: calls.append("_apply_all_patches")
|
||||
)
|
||||
|
||||
apply_torch_npu_patches(torch_npu, [["profiler.profile", object()]])
|
||||
|
||||
self.assertEqual(calls, ["_apply_all_patches"])
|
||||
|
||||
def test_apply_torch_npu_patches_requires_supported_api(self):
|
||||
with self.assertRaises(AttributeError):
|
||||
apply_torch_npu_patches(types.SimpleNamespace(), [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user