Skip to content

Commit d67d034

Browse files
authored
TST XPU regression tests with deterministic (#2600)
--------- Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
1 parent 59ef3b9 commit d67d034

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

tests/regression/__init__.py

Whitespace-only changes.

tests/regression/test_regression.py

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
)
8080
from peft.utils import infer_device
8181

82+
from ..testing_utils import require_bitsandbytes, require_deterministic_for_xpu, require_non_cpu
83+
8284

8385
PEFT_VERSION = peft.__version__
8486
REGRESSION_DIR = tempfile.mkdtemp(prefix="peft_regression_")
@@ -126,36 +128,6 @@ def strtobool(val):
126128
raise ValueError(f"invalid truth value {val!r}")
127129

128130

129-
# same as in ..testing_utils.py but cannot be imported
130-
def require_torch_gpu(test_case):
131-
"""
132-
Decorator marking a test that requires a GPU. Will be skipped when no GPU is available.
133-
134-
Copies from tsting_utils.py.
135-
136-
"""
137-
if not torch.cuda.is_available():
138-
return unittest.skip("test requires GPU")(test_case)
139-
else:
140-
return test_case
141-
142-
143-
# same as in ..testing_utils.py but cannot be imported
144-
def require_bitsandbytes(test_case):
145-
"""
146-
Decorator marking a test that requires the bitsandbytes library. Will be skipped when the library is not installed.
147-
148-
Copies from tsting_utils.py.
149-
150-
"""
151-
try:
152-
import bitsandbytes # noqa: F401
153-
except ImportError:
154-
return unittest.skip("test requires bitsandbytes")(test_case)
155-
else:
156-
return test_case
157-
158-
159131
def save_output(output, name, force=False):
160132
path = os.path.join(REGRESSION_DIR, name, PEFT_VERSION)
161133
filename = os.path.join(path, "output.pt")
@@ -236,6 +208,7 @@ def check_clean_git_status(self, force):
236208
else:
237209
raise RuntimeError("Git commit is not tagged") from exc
238210

211+
@require_deterministic_for_xpu
239212
def assert_results_equal_or_store(self, model, name):
240213
"""Check if the outputs are the same or save the outputs if in creation mode."""
241214
if not self.creation_mode: # normal regression testing mode
@@ -580,7 +553,7 @@ def test_ia3(self):
580553
self.assert_results_equal_or_store(model, "ia3_opt-350m")
581554

582555

583-
@require_torch_gpu
556+
@require_non_cpu
584557
@require_bitsandbytes
585558
class TestOpt8bitBnb(RegressionTester):
586559
def get_output(self, model):
@@ -637,7 +610,7 @@ def test_adalora(self):
637610
self.assert_results_equal_or_store(model, "adalora_opt-350m_8bit")
638611

639612

640-
@require_torch_gpu
613+
@require_non_cpu
641614
@require_bitsandbytes
642615
class TestOpt4bitBnb(RegressionTester):
643616
def get_output(self, model):

0 commit comments

Comments
 (0)