-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add assertions to TPU accelerator for device availability #11799
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,7 +16,8 @@ | |||||
import torch | ||||||
|
||||||
from pytorch_lightning.accelerators.accelerator import Accelerator | ||||||
from pytorch_lightning.utilities import _XLA_AVAILABLE | ||||||
from pytorch_lightning.utilities.exceptions import MisconfigurationException | ||||||
from pytorch_lightning.utilities.imports import _XLA_AVAILABLE | ||||||
|
||||||
if _XLA_AVAILABLE: | ||||||
import torch_xla.core.xla_model as xm | ||||||
|
@@ -25,6 +26,15 @@ | |||||
class TPUAccelerator(Accelerator): | ||||||
"""Accelerator for TPU devices.""" | ||||||
|
||||||
def __init__(self) -> None: | ||||||
""" | ||||||
Raises: | ||||||
MisconfigurationException: | ||||||
If the TPU device is not available. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" | ||||||
if not _XLA_AVAILABLE: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add another one for TPU_AVAILABLE? |
||||||
raise MisconfigurationException("The TPU Accelerator requires torch_xla and a TPU device to run.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
def get_device_stats(self, device: Union[str, torch.device]) -> Dict[str, Any]: | ||||||
"""Gets stats for the given TPU device. | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.