-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Updated auto select gpu #2852
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
Closed
sebastienwood
wants to merge
8
commits into
Lightning-AI:master
from
sebastienwood:updated-auto_select_gpu
Closed
Updated auto select gpu #2852
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c5065ed
init
sebastienwood ac2ea56
smol doc
sebastienwood 74ae43f
small updates
484f09b
fix useless import
2fa02bd
fixes + flake8
5693187
Update distrib_parts.py
sebastienwood 8ac853e
Merge remote-tracking branch 'pl/master' into updated-auto_select_gpu
96f3a66
training step delegation + small fixes
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -493,6 +493,7 @@ def __init__( | |
| self.accumulate_grad_batches = accumulate_grad_batches | ||
| self.configure_accumulated_gradients(accumulate_grad_batches) | ||
|
|
||
| self.auto_select_gpus = auto_select_gpus | ||
| # for gpus allow int, string and gpu list | ||
| if auto_select_gpus and isinstance(gpus, int): | ||
| self.gpus = pick_multiple_gpus(gpus) | ||
|
|
@@ -970,6 +971,10 @@ def fit( | |
| model.prepare_data() | ||
| self._is_data_prepared = True | ||
|
|
||
| # Run updated auto GPU selection with the actual model/input data | ||
| if self.auto_select_gpus: | ||
| self.update_auto_selected_gpus(model) | ||
|
|
||
| # Run auto batch size scaling | ||
| if self.auto_scale_batch_size: | ||
| if isinstance(self.auto_scale_batch_size, bool): | ||
|
|
@@ -1407,6 +1412,15 @@ def call_setup_hook(self, model): | |
| self.setup(stage_name) | ||
| model.setup(stage_name) | ||
|
|
||
| def update_auto_selected_gpus(self, model): | ||
| # Called when model/data is known. Ensure the GPU used have enough VRAM. | ||
| self.gpus = pick_multiple_gpus(len(self.gpus), model) # At most the current number of GPUs | ||
|
|
||
| self.data_parallel_device_ids = _parse_gpu_ids(self.gpus) | ||
|
Collaborator
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. Could this function be used during |
||
| self.root_gpu = determine_root_gpu_device(self.data_parallel_device_ids) | ||
| self.on_gpu = True if (self.data_parallel_device_ids and torch.cuda.is_available()) else False | ||
| self.set_nvidia_flags(self.is_slurm_managing_tasks, self.data_parallel_device_ids) | ||
|
|
||
|
|
||
| class _PatchDataLoader(object): | ||
| r""" | ||
|
|
||
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.
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.