Skip to content

Commit

Permalink
ignore NVML errors for gpu stats
Browse files Browse the repository at this point in the history
  • Loading branch information
winglian committed Sep 15, 2023
1 parent 56da204 commit 97f52d6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/axolotl/utils/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pynvml
import torch
from pynvml.nvml import NVMLError


def gpu_memory_usage(device=0):
Expand All @@ -20,11 +21,13 @@ def gpu_memory_usage_smi(device=0):
device = device.index
if isinstance(device, str) and device.startswith("cuda:"):
device = int(device[5:])

pynvml.nvmlInit()
handle = pynvml.nvmlDeviceGetHandleByIndex(device)
info = pynvml.nvmlDeviceGetMemoryInfo(handle)
return info.used / 1024.0**3
try:
pynvml.nvmlInit()
handle = pynvml.nvmlDeviceGetHandleByIndex(device)
info = pynvml.nvmlDeviceGetMemoryInfo(handle)
return info.used / 1024.0**3
except NVMLError:
return 0.0


def log_gpu_memory_usage(log, msg, device):
Expand Down

0 comments on commit 97f52d6

Please sign in to comment.