41
41
SLURMEnvironment ,
42
42
TorchElasticEnvironment ,
43
43
)
44
- from pytorch_lightning .utilities .exceptions import MisconfigurationException
45
44
from pytorch_lightning .utilities import _GPU_AVAILABLE
45
+ from pytorch_lightning .utilities .exceptions import MisconfigurationException
46
46
from tests .helpers .boring_model import BoringModel
47
47
from tests .helpers .runif import RunIf
48
48
@@ -562,9 +562,9 @@ def test_accelerator_cpu():
562
562
563
563
with pytest .raises (MisconfigurationException , match = "You passed `accelerator='gpu'`, but GPUs are not available" ):
564
564
trainer = Trainer (accelerator = "gpu" )
565
-
566
- # with pytest.raises(MisconfigurationException, match="You passed `accelerator='gpu'`, but GPUs are not available "):
567
- # trainer = Trainer(accelerator="cpu", gpus=1)
565
+
566
+ with pytest .raises (MisconfigurationException , match = "You requested GPUs: " ):
567
+ trainer = Trainer (accelerator = "cpu" , gpus = 1 )
568
568
569
569
570
570
@RunIf (min_gpus = 1 )
@@ -575,7 +575,9 @@ def test_accelerator_gpu():
575
575
assert trainer ._device_type == "gpu"
576
576
assert isinstance (trainer .accelerator , GPUAccelerator )
577
577
578
- with pytest .raises (MisconfigurationException , match = "You passed `accelerator='gpu'`, but you didn't pass `gpus` to `Trainer`" ):
578
+ with pytest .raises (
579
+ MisconfigurationException , match = "You passed `accelerator='gpu'`, but you didn't pass `gpus` to `Trainer`"
580
+ ):
579
581
trainer = Trainer (accelerator = "gpu" )
580
582
581
583
trainer = Trainer (accelerator = "auto" , gpus = 1 )
@@ -584,9 +586,10 @@ def test_accelerator_gpu():
584
586
assert isinstance (trainer .accelerator , GPUAccelerator )
585
587
586
588
589
+ @RunIf (min_gpus = 1 )
587
590
def test_accelerator_cpu_with_gpus_flag ():
588
-
591
+
589
592
trainer = Trainer (accelerator = "cpu" , gpus = 1 )
590
593
591
594
assert trainer ._device_type == "cpu"
592
- assert isinstance (trainer .accelerator , GPUAccelerator )
595
+ assert isinstance (trainer .accelerator , CPUAccelerator )
0 commit comments