Skip to content

Commit

Permalink
Make GPU stats more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
marxin committed Feb 22, 2024
1 parent e56e1ab commit 638e1a5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions usage-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,24 @@ def difference_in_gb(self):

try:
import GPUtil
gpu_stats = DataStatistic(lambda: 100 * GPUtil.getGPUs()[0].load)

def collect_gpu():
try:
return 100 * GPUtil.getGPUs()[0].load
except IndexError:
# sometimes GPUtil.getGPUs() returns [] if we are terminating
return 0

def collect_gpu_memory():
try:
return GPUtil.getGPUs()[0].memoryUsed / 1024
except IndexError:
# sometimes GPUtil.getGPUs() returns [] if we are terminating
return 0

gpu_stats = DataStatistic(collect_gpu)
# the memory consumption is reported in MiBs
gpu_mem_stats = DataStatistic(lambda: GPUtil.getGPUs()[0].memoryUsed / 1024)
gpu_mem_stats = DataStatistic(collect_gpu_memory)
collectors.append(gpu_stats)
collectors.append(gpu_mem_stats)
except ImportError:
Expand Down

0 comments on commit 638e1a5

Please sign in to comment.