-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[1/4] Add get_device_stats to accelerator interface #9586
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
daniellepintz
merged 31 commits into
Lightning-AI:master
from
daniellepintz:get_device_stats
Sep 27, 2021
Merged
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
c11eb87
Add interface to accelerator to get_device_stats
daniellepintz cba4916
Update changelog
daniellepintz d4252c5
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz d0e1233
address comments
daniellepintz 269f3ff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4d8cc75
comments
daniellepintz 8e37419
Merge branch 'get_device_stats' of github.com:daniellepintz/pytorch-l…
daniellepintz 6d9cc2e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 018e5cd
fix gpu
daniellepintz 310f254
Merge branch 'get_device_stats' of github.com:daniellepintz/pytorch-l…
daniellepintz ec8084d
fix
daniellepintz 5abce11
update docstring
daniellepintz 3936242
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0fdd368
fix tests
daniellepintz 32f1047
Merge branch 'get_device_stats' of github.com:daniellepintz/pytorch-l…
daniellepintz d8314cf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5699e85
type fix
daniellepintz 8d66aba
Merge branch 'get_device_stats' of github.com:daniellepintz/pytorch-l…
daniellepintz 3ac0821
fix test
daniellepintz 1160cd0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ef5bc17
Update pytorch_lightning/accelerators/gpu.py
daniellepintz 497680c
address comments
daniellepintz d3d13ec
Merge branch 'get_device_stats' of github.com:daniellepintz/pytorch-l…
daniellepintz ae7e912
Add unit tests
daniellepintz 418e4a0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 46b9f36
comments
daniellepintz ccadca5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2658b4a
lint
daniellepintz 07bc597
Merge branch 'get_device_stats' of github.com:daniellepintz/pytorch-l…
daniellepintz e19239e
Merge branch 'master' of https://github.com/PyTorchLightning/pytorch-…
daniellepintz c4f0d02
comments
daniellepintz 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import torch | ||
|
||
from pytorch_lightning.accelerators import GPUAccelerator | ||
from pytorch_lightning.plugins.precision.precision_plugin import PrecisionPlugin | ||
from pytorch_lightning.plugins.training_type.dp import DataParallelPlugin | ||
from tests.helpers.runif import RunIf | ||
|
||
|
||
@RunIf(min_torch="1.8") | ||
@RunIf(min_gpus=1) | ||
def test_get_torch_gpu_stats(tmpdir): | ||
"""Test GPU get_device_stats with Pytorch >= 1.8.0.""" | ||
current_device = torch.device(f"cuda:{torch.cuda.current_device()}") | ||
GPUAccel = GPUAccelerator( | ||
training_type_plugin=DataParallelPlugin(parallel_devices=[current_device]), precision_plugin=PrecisionPlugin() | ||
) | ||
gpu_stats = GPUAccel.get_device_stats(current_device) | ||
fields = ["allocated_bytes.all.freed", "inactive_split.all.peak", "reserved_bytes.large_pool.peak"] | ||
|
||
for f in fields: | ||
assert any(f in h for h in gpu_stats.keys()) | ||
|
||
|
||
@RunIf(max_torch="1.7") | ||
@RunIf(min_gpus=1) | ||
def test_get_nvidia_gpu_stats(tmpdir): | ||
"""Test GPU get_device_stats with Pytorch < 1.8.0.""" | ||
current_device = torch.device(f"cuda:{torch.cuda.current_device()}") | ||
GPUAccel = GPUAccelerator( | ||
training_type_plugin=DataParallelPlugin(parallel_devices=[current_device]), precision_plugin=PrecisionPlugin() | ||
) | ||
gpu_stats = GPUAccel.get_device_stats(current_device) | ||
fields = ["utilization.gpu", "memory.used", "memory.free", "utilization.memory"] | ||
|
||
for f in fields: | ||
assert any(f in h for h in gpu_stats.keys()) |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from pytorch_lightning.accelerators import TPUAccelerator | ||
from pytorch_lightning.plugins import SingleTPUPlugin | ||
from pytorch_lightning.plugins.training_type import TPUSpawnPlugin | ||
from tests.helpers.runif import RunIf | ||
|
||
|
||
@RunIf(tpu=True) | ||
def test_device_stats_tpu(tmpdir): | ||
daniellepintz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Test TPU get_device_stats.""" | ||
plugin = SingleTPUPlugin(1) | ||
TPUAccel = TPUAccelerator(training_type_plugin=TPUSpawnPlugin(), precision_plugin=plugin) | ||
tpu_stats = TPUAccel.get_device_stats("1") | ||
fields = ["avg. free memory (MB)", "avg. peak memory (MB)"] | ||
|
||
for f in fields: | ||
assert any(f in h for h in tpu_stats.keys()) |
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.