|
79 | 79 | )
|
80 | 80 | from peft.utils import infer_device
|
81 | 81 |
|
| 82 | +from ..testing_utils import require_bitsandbytes, require_deterministic_for_xpu, require_non_cpu |
| 83 | + |
82 | 84 |
|
83 | 85 | PEFT_VERSION = peft.__version__
|
84 | 86 | REGRESSION_DIR = tempfile.mkdtemp(prefix="peft_regression_")
|
@@ -126,36 +128,6 @@ def strtobool(val):
|
126 | 128 | raise ValueError(f"invalid truth value {val!r}")
|
127 | 129 |
|
128 | 130 |
|
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 |
| - |
159 | 131 | def save_output(output, name, force=False):
|
160 | 132 | path = os.path.join(REGRESSION_DIR, name, PEFT_VERSION)
|
161 | 133 | filename = os.path.join(path, "output.pt")
|
@@ -236,6 +208,7 @@ def check_clean_git_status(self, force):
|
236 | 208 | else:
|
237 | 209 | raise RuntimeError("Git commit is not tagged") from exc
|
238 | 210 |
|
| 211 | + @require_deterministic_for_xpu |
239 | 212 | def assert_results_equal_or_store(self, model, name):
|
240 | 213 | """Check if the outputs are the same or save the outputs if in creation mode."""
|
241 | 214 | if not self.creation_mode: # normal regression testing mode
|
@@ -580,7 +553,7 @@ def test_ia3(self):
|
580 | 553 | self.assert_results_equal_or_store(model, "ia3_opt-350m")
|
581 | 554 |
|
582 | 555 |
|
583 |
| -@require_torch_gpu |
| 556 | +@require_non_cpu |
584 | 557 | @require_bitsandbytes
|
585 | 558 | class TestOpt8bitBnb(RegressionTester):
|
586 | 559 | def get_output(self, model):
|
@@ -637,7 +610,7 @@ def test_adalora(self):
|
637 | 610 | self.assert_results_equal_or_store(model, "adalora_opt-350m_8bit")
|
638 | 611 |
|
639 | 612 |
|
640 |
| -@require_torch_gpu |
| 613 | +@require_non_cpu |
641 | 614 | @require_bitsandbytes
|
642 | 615 | class TestOpt4bitBnb(RegressionTester):
|
643 | 616 | def get_output(self, model):
|
|
0 commit comments