Skip to content

Commit 3754b30

Browse files
committed
remove is_hpu_supported and refactor HPU UT
Signed-off-by: xinhe3 <xinhe3@habana.ai>
1 parent 885b892 commit 3754b30

File tree

7 files changed

+16
-25
lines changed

7 files changed

+16
-25
lines changed

.azure-pipelines/scripts/ut/run_ut_hpu.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export TQDM_MININTERVAL=60
77
pip install pytest-cov pytest-html
88
pip list
99

10-
cd /auto-round/test/test_cpu || exit 1
10+
cd /auto-round/test/test_hpu || exit 1
1111
find . -type f -exec sed -i '/sys\.path\.insert(0, "\.\.")/d' {} +
1212

1313
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
@@ -19,8 +19,8 @@ LOG_DIR=/auto-round/log_dir
1919
mkdir -p ${LOG_DIR}
2020
ut_log_name=${LOG_DIR}/ut.log
2121

22-
find . -name "test*hpu_only.py" | sed "s,\.\/,python -m pytest --cov=\"${auto_round_path}\" --cov-report term --html=report.html --self-contained-html --cov-report xml:coverage.xml --cov-append -vs --disable-warnings ,g" > run_lazy.sh
23-
find . -name "test*hpu_only.py" | sed "s,\.\/,python -m pytest --mode compile --cov=\"${auto_round_path}\" --cov-report term --html=report.html --self-contained-html --cov-report xml:coverage.xml --cov-append -vs --disable-warnings ,g" > run_compile.sh
22+
find . -name "test*.py" | sed "s,\.\/,python -m pytest --cov=\"${auto_round_path}\" --cov-report term --html=report.html --self-contained-html --cov-report xml:coverage.xml --cov-append -vs --disable-warnings ,g" > run_lazy.sh
23+
find . -name "test*.py" | sed "s,\.\/,python -m pytest --mode compile --cov=\"${auto_round_path}\" --cov-report term --html=report.html --self-contained-html --cov-report xml:coverage.xml --cov-append -vs --disable-warnings ,g" > run_compile.sh
2424

2525
cat run_lazy.sh
2626
bash run_lazy.sh 2>&1 | tee ${ut_log_name}

auto_round/data_type/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ def float8_e4m3fn_hpu_ste(x: torch.Tensor):
224224

225225
@lru_cache(None)
226226
def get_gaudi_fp8_ste_func():
227-
from auto_round.utils import is_hpu_supported
227+
from auto_round.utils import is_hpex_available
228228

229-
if is_hpu_supported():
229+
if is_hpex_available():
230230
fn = float8_e4m3fn_hpu_ste
231231
logger.warning_once("Using HPU STE for FP8")
232232
else:

auto_round/inference/auto_quantizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from transformers.utils.quantization_config import AwqConfig, GPTQConfig, QuantizationConfigMixin, QuantizationMethod
4343

4444
from auto_round.inference.convert_model import convert_hf_model, infer_target_device, post_init
45-
from auto_round.utils import is_hpu_supported
45+
from auto_round.utils import is_hpex_available
4646

4747
logger = getLogger(__name__)
4848
import sys
@@ -126,7 +126,7 @@ def from_config(cls, quantization_config: Union[QuantizationConfigMixin, Dict],
126126
f"Unknown quantization type, got {quant_method} - supported types are:"
127127
f" {list(AUTO_QUANTIZER_MAPPING.keys())}"
128128
)
129-
if "auto-round" in quant_method or is_hpu_supported(): # pragma: no cover
129+
if "auto-round" in quant_method or is_hpex_available(): # pragma: no cover
130130
target_cls = AutoRoundQuantizer
131131
else:
132132
target_cls = AUTO_QUANTIZER_MAPPING[quant_method]

auto_round/inference/convert_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
get_block_names,
4040
get_layer_names_in_block,
4141
get_module,
42-
is_hpu_supported,
42+
is_hpex_available,
4343
set_module,
4444
)
4545

@@ -165,7 +165,7 @@ def get_available_devices():
165165
if torch.cuda.is_available():
166166
devices.append("cuda")
167167

168-
if is_hpu_supported():
168+
if is_hpex_available():
169169
devices.append("hpu")
170170

171171
if hasattr(torch, "xpu") and torch.xpu.is_available():

auto_round/utils.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -798,15 +798,6 @@ def is_autoround_exllamav2_available():
798798
return res
799799

800800

801-
@lru_cache(None)
802-
def is_hpu_supported(): # pragma: no cover
803-
try:
804-
import habana_frameworks.torch.core as htcore # pylint: disable=E0401
805-
except ImportError as e:
806-
return False
807-
return True
808-
809-
810801
def get_library_version(library_name):
811802
from packaging.version import Version
812803

@@ -924,7 +915,7 @@ def _clear_memory_for_cpu_and_cuda(tensor=None):
924915

925916
@torch._dynamo.disable()
926917
def clear_memory(tensor=None):
927-
if is_hpu_supported():
918+
if is_hpex_available():
928919
# hpu does not have empty_cache
929920
return
930921
else:

test/test_cpu/test_auto_round_hpu_only.py renamed to test/test_hpu/test_auto_round.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import torch
33
from _test_helpers import is_pytest_mode_compile, is_pytest_mode_lazy
44

5-
from auto_round.utils import is_hpu_supported
5+
from auto_round.utils import is_hpex_available
66

77

88
def run_opt_125m_on_hpu():
@@ -28,13 +28,13 @@ def run_opt_125m_on_hpu():
2828
assert q_model is not None, "Expected q_model to be not None"
2929

3030

31-
@pytest.mark.skipif(not is_hpu_supported(), reason="HPU is not supported")
31+
@pytest.mark.skipif(not is_hpex_available(), reason="HPU is not supported")
3232
@pytest.mark.skipif(not is_pytest_mode_lazy(), reason="Only for lazy mode")
3333
def test_opt_125m_lazy_mode():
3434
run_opt_125m_on_hpu()
3535

3636

37-
@pytest.mark.skipif(not is_hpu_supported(), reason="HPU is not supported")
37+
@pytest.mark.skipif(not is_hpex_available(), reason="HPU is not supported")
3838
@pytest.mark.skipif(not is_pytest_mode_compile(), reason="Only for compile mode")
3939
def test_opt_125m_compile_mode():
4040
torch._dynamo.reset()

test/test_cpu/test_hpu.py renamed to test/test_hpu/test_inference.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __iter__(self):
1818
yield torch.ones([1, 10], dtype=torch.long)
1919

2020

21-
def is_hpu_supported():
21+
def is_hpex_available():
2222
try:
2323
import habana_frameworks.torch.core as htcore # pylint: disable=E0401
2424
except ImportError as e:
@@ -40,7 +40,7 @@ def tearDownClass(self):
4040
shutil.rmtree("runs", ignore_errors=True)
4141

4242
def test_autogptq_format_hpu_inference(self):
43-
if not is_hpu_supported():
43+
if not is_hpex_available():
4444
return
4545
try:
4646
import auto_gptq
@@ -73,7 +73,7 @@ def test_autogptq_format_hpu_inference(self):
7373
shutil.rmtree("./saved", ignore_errors=True)
7474

7575
def test_autoround_format_hpu_inference(self):
76-
if not is_hpu_supported():
76+
if not is_hpex_available():
7777
return
7878
bits, group_size, sym = 4, 128, False
7979
autoround = AutoRound(

0 commit comments

Comments
 (0)