1010import torch
1111
1212from 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
1616pytestmark = 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
2820def _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-
4627def _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():
8263def 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 ,
0 commit comments