-
Notifications
You must be signed in to change notification settings - Fork 3.5k
add accelerator.is_available()
check
#12104
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
Merged
kaushikb11
merged 22 commits into
Lightning-AI:master
from
jjenniferdai:acc-available-check
Mar 2, 2022
Merged
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3ffe5bf
first commit
jjenniferdai 4c0f4a7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9c642f9
update
jjenniferdai 55b4995
doctest?
jjenniferdai 729a8aa
codeblock instead
jjenniferdai 15d386c
update msg
jjenniferdai d36d852
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 99b4ecf
Merge branch 'master' into acc-available-check
jjenniferdai c69bcf7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2385855
update msg, hardware_name
jjenniferdai 250dc2c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d76b7e0
format
jjenniferdai cd920ac
format Update tests/trainer/properties/test_estimated_stepping_batche…
jjenniferdai 1e031f4
format Update tests/plugins/test_cluster_integration.py
jjenniferdai 4c57f8a
format Update tests/accelerators/test_ipu.py
jjenniferdai 8b632b4
format Update tests/accelerators/test_accelerator_connector.py
jjenniferdai 2193484
format Update tests/accelerators/test_accelerator_connector.py
jjenniferdai fadb69b
format Update tests/accelerators/test_accelerator_connector.py
jjenniferdai 31a54eb
req base, update name, lowercase
jjenniferdai 67301d6
update
jjenniferdai 70e9f71
Address reviews
kaushikb11 65b23b6
Fix test
kaushikb11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -455,16 +455,15 @@ def _choose_accelerator(self) -> str: | |
return "cpu" | ||
|
||
def _set_parallel_devices_and_init_accelerator(self) -> None: | ||
# TODO add device availability check | ||
ACCELERATORS = { | ||
"cpu": CPUAccelerator, | ||
"gpu": GPUAccelerator, | ||
"tpu": TPUAccelerator, | ||
"ipu": IPUAccelerator, | ||
kaushikb11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
rohitgr7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if isinstance(self._accelerator_flag, Accelerator): | ||
self.accelerator: Accelerator = self._accelerator_flag | ||
else: | ||
ACCELERATORS = { | ||
"cpu": CPUAccelerator, | ||
"gpu": GPUAccelerator, | ||
"tpu": TPUAccelerator, | ||
"ipu": IPUAccelerator, | ||
} | ||
assert self._accelerator_flag is not None | ||
self._accelerator_flag = self._accelerator_flag.lower() | ||
if self._accelerator_flag not in ACCELERATORS: | ||
|
@@ -475,6 +474,15 @@ def _set_parallel_devices_and_init_accelerator(self) -> None: | |
accelerator_class = ACCELERATORS[self._accelerator_flag] | ||
self.accelerator = accelerator_class() # type: ignore[abstract] | ||
|
||
if not self.accelerator.is_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. depending on the accelerator, we might not be able to instantiate it without it being available. The init should have the freedom to assume it is available or raise additional errors. IMO the check should have been before the instantiation. |
||
available_hardware = [acc_str for acc_str in list(ACCELERATORS) if ACCELERATORS[acc_str].is_available()] | ||
raise MisconfigurationException( | ||
f"{self.accelerator.__class__.__qualname__} can not run on this hardware" | ||
f" since {self.accelerator.hardware_name()}s are not available." | ||
" The following hardware is available and can be passed into" | ||
f" `accelerator` argument of `Trainer`: {available_hardware}." | ||
) | ||
|
||
self._set_devices_flag_if_auto_passed() | ||
|
||
self._gpus = self._devices_flag if not self._gpus else self._gpus | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.