Skip to content

Trainer(accelerator="tpu") should raise exception if TPU not found #12047

@akihironitta

Description

@akihironitta

🐛 Bug

In an environment without TPU, Trainer(accelerator="tpu") should raise an exception just like Trainer(tpu_cores=8) does.

To Reproduce

>>> from pytorch_lightning import Trainer
>>> Trainer(tpu_cores=8)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/nitta/work/github.com/PyTorchLightning/pytorch-lightning/pytorch_lightning/utilities/argparse.py", line 336, in insert_env_defaults
    return fn(self, **kwargs)
  File "/Users/nitta/work/github.com/PyTorchLightning/pytorch-lightning/pytorch_lightning/trainer/trainer.py", line 472, in __init__
    gpu_ids, tpu_cores = self._parse_devices(gpus, auto_select_gpus, tpu_cores)
  File "/Users/nitta/work/github.com/PyTorchLightning/pytorch-lightning/pytorch_lightning/trainer/trainer.py", line 1741, in _parse_devices
    return device_parser._parse_devices(gpus, auto_select_gpus, tpu_cores)
  File "/Users/nitta/work/github.com/PyTorchLightning/pytorch-lightning/pytorch_lightning/utilities/device_parser.py", line 63, in _parse_devices
    tpu_cores = parse_tpu_cores(tpu_cores)
  File "/Users/nitta/work/github.com/PyTorchLightning/pytorch-lightning/pytorch_lightning/utilities/device_parser.py", line 135, in parse_tpu_cores
    raise MisconfigurationException("No TPU devices were found.")
pytorch_lightning.utilities.exceptions.MisconfigurationException: No TPU devices were found.
>>> Trainer(accelerator="tpu", devices=8)
/Users/nitta/work/github.com/PyTorchLightning/pytorch-lightning/pytorch_lightning/loops/utilities.py:90: PossibleUserWarning: `max_epochs` was not set. Setting it to 1000 epochs. To train without an epoch limit, set `max_epochs=-1`.
  rank_zero_warn(
GPU available: False, used: False
TPU available: False, using: 8 TPU cores
IPU available: False, using: 0 IPUs
<pytorch_lightning.trainer.trainer.Trainer object at 0x10569dc70>

Expected behavior

See title.

Environment

  • PyTorch Lightning Version (e.g., 1.5.0): master
  • PyTorch Version (e.g., 1.10):
  • Python version (e.g., 3.9):
  • OS (e.g., Linux):
  • CUDA/cuDNN version:
  • GPU models and configuration:
  • How you installed PyTorch (conda, pip, source):
  • If compiling from source, the output of torch.__config__.show():
  • Any other relevant information:

Additional context

  • Trainer(accelerator="gpu", devices=8) expectedly raises an exception if no gpus are found.
  • Blocking #11470

cc @kaushikb11 @rohitgr7 @justusschock @awaelchli @akihironitta

Metadata

Metadata

Assignees

No one assigned

    Labels

    accelerator: cudaCompute Unified Device Architecture GPUaccelerator: tpuTensor Processing UnitbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions