1818
1919import pytorch_lightning as pl
2020from pytorch_lightning .accelerators .accelerator import Accelerator
21- from pytorch_lightning .plugins .precision import MixedPrecisionPlugin
21+ from pytorch_lightning .plugins .precision import TPUPrecisionPlugin
2222from pytorch_lightning .plugins .training_type .single_tpu import SingleTPUPlugin
2323from pytorch_lightning .plugins .training_type .tpu_spawn import TPUSpawnPlugin
2424from pytorch_lightning .utilities import _XLA_AVAILABLE
2525from pytorch_lightning .utilities .apply_func import apply_to_collection , move_data_to_device
26- from pytorch_lightning .utilities .exceptions import MisconfigurationException
2726
2827if _XLA_AVAILABLE :
2928 import torch_xla .core .xla_model as xm
@@ -35,18 +34,19 @@ class TPUAccelerator(Accelerator):
3534 def setup (self , trainer : "pl.Trainer" ) -> None :
3635 """
3736 Raises:
38- MisconfigurationException:
39- If AMP is used with TPU.
40- MisconfigurationException:
41- If TPUs are not using a single TPU core or TPU spawn training.
37+ ValueError:
38+ If the precision or training type plugin are unsupported.
4239 """
43- if isinstance (self .precision_plugin , MixedPrecisionPlugin ):
44- raise MisconfigurationException (
45- "amp + tpu is not supported. Only bfloats are supported on TPU. Consider using TPUHalfPrecisionPlugin"
40+ if not isinstance (self .precision_plugin , TPUPrecisionPlugin ):
41+ # this configuration should have been avoided in the accelerator connector
42+ raise ValueError (
43+ f"The `TPUAccelerator` can only be used with a `TPUPrecisionPlugin`, found: { self .precision_plugin } ."
4644 )
47-
4845 if not isinstance (self .training_type_plugin , (SingleTPUPlugin , TPUSpawnPlugin )):
49- raise MisconfigurationException ("TPUs only support a single tpu core or tpu spawn training." )
46+ raise ValueError (
47+ "The `TPUAccelerator` can only be used with a `SingleTPUPlugin` or `TPUSpawnPlugin,"
48+ f" found { self .training_type_plugin } ."
49+ )
5050 return super ().setup (trainer )
5151
5252 def run_optimizer_step (
0 commit comments