-
-
Notifications
You must be signed in to change notification settings - Fork 871
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from tmm1/gpu-util
GPU memory usage logging
- Loading branch information
Showing
6 changed files
with
63 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ evaluate==0.4.0 | |
rouge-score==0.1.2 | ||
scipy | ||
scikit-learn==1.2.2 | ||
pynvml |
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,23 @@ | ||
"""Benchmarking and measurement utilities""" | ||
|
||
import pynvml | ||
import torch | ||
|
||
|
||
def gpu_memory_usage(device): | ||
if isinstance(device, torch.device): | ||
device = device.index | ||
if isinstance(device, str) and device.startswith("cuda:"): | ||
device = int(device[5:]) | ||
|
||
# NB torch.cuda.memory_usage returns zero so we use lower level api | ||
pynvml.nvmlInit() | ||
handle = pynvml.nvmlDeviceGetHandleByIndex(device) | ||
info = pynvml.nvmlDeviceGetMemoryInfo(handle) | ||
return info.used / 1024.0**3 | ||
|
||
|
||
def log_gpu_memory_usage(log, msg, device): | ||
log.info( | ||
f"GPU memory usage {msg}: {gpu_memory_usage(device):.03f} GB", stacklevel=2 | ||
) |
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