Skip to content

Commit 8d935a6

Browse files
authored
CI Enable 5 test cases on XPU (#2442)
Signed-off-by: Yao, Matrix <[email protected]>
1 parent 15106f5 commit 8d935a6

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

scripts/launch_notebook_mp.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from accelerate import notebook_launcher
2323

2424
import peft
25+
from peft.utils import infer_device
2526

2627

2728
def init():
@@ -33,7 +34,8 @@ def __init__(self):
3334
def forward(self, x):
3435
return self.linear(x)
3536

36-
model = MyModule().to("cuda")
37+
device = infer_device()
38+
model = MyModule().to(device)
3739
peft.get_peft_model(model, peft.LoraConfig(target_modules=["linear"]))
3840

3941

tests/test_common_gpu.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
require_bitsandbytes,
6363
require_multi_accelerator,
6464
require_non_cpu,
65-
require_torch_gpu,
6665
)
6766

6867

@@ -1252,7 +1251,7 @@ def test_4bit_dora_merging(self):
12521251
assert torch.allclose(out_dora, out_unmerged, atol=atol, rtol=rtol)
12531252
assert torch.allclose(out_dora, out_unloaded, atol=atol, rtol=rtol)
12541253

1255-
@require_torch_gpu
1254+
@require_non_cpu
12561255
@pytest.mark.single_gpu_tests
12571256
@require_bitsandbytes
12581257
def test_8bit_dora_merging(self):

tests/test_gpu_examples.py

+18-17
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
from peft.utils.other import fsdp_auto_wrap_policy
8080

8181
from .testing_utils import (
82+
device_count,
8283
require_aqlm,
8384
require_auto_awq,
8485
require_auto_gptq,
@@ -302,7 +303,7 @@ def test_causal_lm_training_multi_gpu_4bit(self):
302303
quantization_config=BitsAndBytesConfig(load_in_4bit=True),
303304
)
304305

305-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
306+
assert set(model.hf_device_map.values()) == set(range(device_count))
306307

307308
model = prepare_model_for_kbit_training(model)
308309

@@ -424,7 +425,7 @@ def on_optimizer_step(self, args, state, control, **kwargs):
424425
assert trainer.state.log_history[-1]["train_loss"] is not None
425426

426427
@pytest.mark.single_gpu_tests
427-
@require_torch_gpu
428+
@require_non_cpu
428429
def test_8bit_adalora_causalLM(self):
429430
r"""
430431
Tests the 8bit training with adalora
@@ -497,7 +498,7 @@ def on_optimizer_step(self, args, state, control, **kwargs):
497498
assert trainer.state.log_history[-1]["train_loss"] is not None
498499

499500
@pytest.mark.multi_gpu_tests
500-
@require_torch_multi_gpu
501+
@require_multi_accelerator
501502
def test_causal_lm_training_multi_gpu(self):
502503
r"""
503504
Test the CausalLM training on a multi-GPU device. This test is a converted version of
@@ -511,8 +512,8 @@ def test_causal_lm_training_multi_gpu(self):
511512
quantization_config=BitsAndBytesConfig(load_in_8bit=True),
512513
device_map="auto",
513514
)
514-
515-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
515+
print(f"device map: {model.hf_device_map}")
516+
assert set(model.hf_device_map.values()) == set(range(device_count))
516517

517518
tokenizer = AutoTokenizer.from_pretrained(self.causal_lm_model_id)
518519
model = prepare_model_for_kbit_training(model)
@@ -621,7 +622,7 @@ def test_seq2seq_lm_training_single_gpu(self):
621622
assert trainer.state.log_history[-1]["train_loss"] is not None
622623

623624
@pytest.mark.multi_gpu_tests
624-
@require_torch_multi_gpu
625+
@require_multi_accelerator
625626
def test_seq2seq_lm_training_multi_gpu(self):
626627
r"""
627628
Test the Seq2SeqLM training on a multi-GPU device. This test is a converted version of
@@ -636,7 +637,7 @@ def test_seq2seq_lm_training_multi_gpu(self):
636637
device_map="balanced",
637638
)
638639

639-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
640+
assert set(model.hf_device_map.values()) == set(range(device_count))
640641

641642
tokenizer = AutoTokenizer.from_pretrained(self.seq2seq_model_id)
642643
model = prepare_model_for_kbit_training(model)
@@ -920,7 +921,7 @@ def test_causal_lm_training_multi_gpu_4bit_dora(self):
920921
quantization_config=BitsAndBytesConfig(load_in_4bit=True),
921922
)
922923

923-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
924+
assert set(model.hf_device_map.values()) == set(range(device_count))
924925

925926
model = prepare_model_for_kbit_training(model)
926927

@@ -1037,7 +1038,7 @@ def test_causal_lm_training_multi_gpu_8bit_dora(self):
10371038
quantization_config=BitsAndBytesConfig(load_in_8bit=True),
10381039
)
10391040

1040-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
1041+
assert set(model.hf_device_map.values()) == set(range(device_count))
10411042

10421043
model = prepare_model_for_kbit_training(model)
10431044

@@ -1284,7 +1285,7 @@ def test_causal_lm_training_multi_gpu_vera(self):
12841285
quantization_config=BitsAndBytesConfig(load_in_8bit=True),
12851286
)
12861287

1287-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
1288+
assert set(model.hf_device_map.values()) == set(range(device_count))
12881289

12891290
model = prepare_model_for_kbit_training(model)
12901291

@@ -1343,7 +1344,7 @@ def test_causal_lm_training_multi_gpu_4bit_vera(self):
13431344
quantization_config=BitsAndBytesConfig(load_in_4bit=True),
13441345
)
13451346

1346-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
1347+
assert set(model.hf_device_map.values()) == set(range(device_count))
13471348

13481349
model = prepare_model_for_kbit_training(model)
13491350

@@ -1656,7 +1657,7 @@ def test_causal_lm_training_multi_gpu(self):
16561657
quantization_config=self.quantization_config,
16571658
)
16581659

1659-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
1660+
assert set(model.hf_device_map.values()) == set(range(device_count))
16601661

16611662
model = prepare_model_for_kbit_training(model)
16621663

@@ -2552,7 +2553,7 @@ def test_config_no_loftq_config(self):
25522553

25532554

25542555
@require_bitsandbytes
2555-
@require_torch_gpu
2556+
@require_non_cpu
25562557
class MultiprocessTester(unittest.TestCase):
25572558
def test_notebook_launcher(self):
25582559
script_path = os.path.join("scripts", "launch_notebook_mp.py")
@@ -3187,7 +3188,7 @@ def test_causal_lm_training_multi_gpu(self):
31873188
device_map="auto",
31883189
)
31893190

3190-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
3191+
assert set(model.hf_device_map.values()) == set(range(device_count))
31913192

31923193
model = prepare_model_for_kbit_training(model)
31933194

@@ -3335,7 +3336,7 @@ def test_causal_lm_training_multi_gpu_eetq(self):
33353336
quantization_config=quantization_config,
33363337
)
33373338

3338-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
3339+
assert set(model.hf_device_map.values()) == set(range(device_count))
33393340

33403341
model = prepare_model_for_kbit_training(model)
33413342

@@ -3586,7 +3587,7 @@ def test_causal_lm_training_multi_gpu_torchao(self, quant_type):
35863587
torch_dtype=torch.bfloat16,
35873588
)
35883589

3589-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
3590+
assert set(model.hf_device_map.values()) == set(range(device_count))
35903591

35913592
model = prepare_model_for_kbit_training(model)
35923593
model.model_parallel = True
@@ -3646,7 +3647,7 @@ def test_causal_lm_training_multi_gpu_torchao_int4_raises(self):
36463647
torch_dtype=torch.bfloat16,
36473648
)
36483649

3649-
assert set(model.hf_device_map.values()) == set(range(torch.cuda.device_count()))
3650+
assert set(model.hf_device_map.values()) == set(range(device_count))
36503651

36513652
model = prepare_model_for_kbit_training(model)
36523653
model.model_parallel = True

0 commit comments

Comments
 (0)