-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1/4] Add get_device_stats to accelerator interface (#9586)
- Loading branch information
1 parent
83d83ab
commit ab06987
Showing
7 changed files
with
175 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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): | ||
"""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()) |