Skip to content

Commit 504b69f

Browse files
committed
Use logical NPU 0 in Ascend tests
1 parent 0c2294c commit 504b69f

3 files changed

Lines changed: 5 additions & 36 deletions

File tree

.github/scripts/ci_tests.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ def configure_ascend_npu_test_env(env: dict[str, str], test_script: str) -> bool
4040
visible_devices = env.get("GPTQMODEL_TEST_ASCEND_RT_VISIBLE_DEVICES", DEFAULT_ASCEND_RT_VISIBLE_DEVICES)
4141
env["ASCEND_RT_VISIBLE_DEVICES"] = visible_devices
4242

43-
if "GPTQMODEL_TEST_NPU_DEVICE" not in env and visible_devices and "," not in visible_devices:
44-
env["GPTQMODEL_TEST_NPU_DEVICE"] = "npu:0"
45-
4643
env["CUDA_VISIBLE_DEVICES"] = ""
4744
return True
4845

@@ -136,7 +133,6 @@ def run_tests(args: argparse.Namespace) -> int:
136133
ascend_npu_test = configure_ascend_npu_test_env(env, args.test_script)
137134
if ascend_npu_test:
138135
print(f"ASCEND_RT_VISIBLE_DEVICES={env.get('ASCEND_RT_VISIBLE_DEVICES', '')}")
139-
print(f"GPTQMODEL_TEST_NPU_DEVICE={env.get('GPTQMODEL_TEST_NPU_DEVICE', '')}")
140136

141137
if args.xpu_mode:
142138
maybe_uninstall_vllm()

tests/test_npu_linalg.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,11 @@
1010
import torch
1111

1212
from gptqmodel.quantization.npu_linalg import npu_inverse_cholesky_factor
13-
from gptqmodel.utils.torch import HAS_NPU, last_npu_device_by_pci_bus_order
13+
from gptqmodel.utils.torch import HAS_NPU
1414

1515

1616
pytestmark = pytest.mark.skipif(not HAS_NPU, reason="Ascend NPU is required")
17-
DEFAULT_ASCEND_RT_VISIBLE_DEVICES = "7"
18-
19-
20-
def _default_npu_test_device() -> str:
21-
selected = last_npu_device_by_pci_bus_order()
22-
return str(selected) if selected is not None else "npu:0"
23-
24-
25-
NPU_TEST_DEVICE = os.environ.get("GPTQMODEL_TEST_NPU_DEVICE", _default_npu_test_device())
17+
NPU_TEST_DEVICE = "npu:0"
2618

2719

2820
def _test_npu_device() -> torch.device:
@@ -32,17 +24,6 @@ def _test_npu_device() -> torch.device:
3224
return device
3325

3426

35-
def _default_subprocess_env() -> dict[str, str]:
36-
env = os.environ.copy()
37-
visible_devices = env.get("ASCEND_RT_VISIBLE_DEVICES", "").strip()
38-
if not visible_devices:
39-
visible_devices = env.get("GPTQMODEL_TEST_ASCEND_RT_VISIBLE_DEVICES", DEFAULT_ASCEND_RT_VISIBLE_DEVICES)
40-
env["ASCEND_RT_VISIBLE_DEVICES"] = visible_devices
41-
if "GPTQMODEL_TEST_NPU_DEVICE" not in env and visible_devices and "," not in visible_devices:
42-
env["GPTQMODEL_TEST_NPU_DEVICE"] = "npu:0"
43-
return env
44-
45-
4627
def _spd_matrix(size: int, seed: int) -> torch.Tensor:
4728
generator = torch.Generator(device="cpu").manual_seed(seed)
4829
values = torch.randn(size, size, generator=generator, dtype=torch.float32)
@@ -82,7 +63,6 @@ def test_npu_inverse_cholesky_factor_rejects_non_positive_definite_matrix():
8263
def test_gptq_npu_hessian_inverse_avoids_torch_npu_cpu_fallback_warnings():
8364
script = textwrap.dedent(
8465
"""
85-
import os
8666
import torch
8767
import torch.nn as nn
8868
from gptqmodel.quantization.config import QuantizeConfig
@@ -92,7 +72,7 @@ def test_gptq_npu_hessian_inverse_avoids_torch_npu_cpu_fallback_warnings():
9272
if not HAS_NPU:
9373
raise RuntimeError("Ascend NPU is not available")
9474
95-
npu_test_device = os.environ.get("GPTQMODEL_TEST_NPU_DEVICE", "npu:0")
75+
npu_test_device = "npu:0"
9676
torch.npu.set_device(npu_test_device)
9777
torch.manual_seed(0)
9878
@@ -119,11 +99,10 @@ def test_gptq_npu_hessian_inverse_avoids_torch_npu_cpu_fallback_warnings():
11999
"""
120100
)
121101

122-
env = _default_subprocess_env()
123102
proc = subprocess.run(
124103
[sys.executable, "-c", script],
125104
cwd=os.getcwd(),
126-
env=env,
105+
env=os.environ.copy(),
127106
text=True,
128107
capture_output=True,
129108
timeout=60,

tests/test_npu_support.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import copy
2-
import os
32
import sys
43
import warnings
54

@@ -29,12 +28,7 @@
2928
from gptqmodel.utils.torch import HAS_NPU, last_npu_device_by_pci_bus_order
3029

3130

32-
def _default_npu_test_device() -> str:
33-
selected = last_npu_device_by_pci_bus_order()
34-
return str(selected) if selected is not None else "npu:0"
35-
36-
37-
NPU_TEST_DEVICE = os.environ.get("GPTQMODEL_TEST_NPU_DEVICE", _default_npu_test_device())
31+
NPU_TEST_DEVICE = "npu:0"
3832
NPU_CPU_FALLBACK_MARKERS = (
3933
"not currently supported on the NPU backend",
4034
"fall back to run on the CPU",

0 commit comments

Comments
 (0)