7979from peft .utils .other import fsdp_auto_wrap_policy
8080
8181from .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
25562557class 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