Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions slime/utils/memory_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import gc
import logging

import psutil
import torch
import torch.distributed as dist

Expand All @@ -18,13 +19,18 @@ def clear_memory(clear_host_memory: bool = False):
def available_memory():
device = torch.cuda.current_device()
free, total = torch.cuda.mem_get_info(device)
vm = psutil.virtual_memory()
return {
"gpu": str(device),
"total_GB": _byte_to_gb(total),
"free_GB": _byte_to_gb(free),
"used_GB": _byte_to_gb(total - free),
"allocated_GB": _byte_to_gb(torch.cuda.memory_allocated(device)),
"reserved_GB": _byte_to_gb(torch.cuda.memory_reserved(device)),
"host_total_GB": _byte_to_gb(vm.total),
"host_available_GB": _byte_to_gb(vm.available),
"host_used_GB": _byte_to_gb(vm.used),
"host_free_GB": _byte_to_gb(vm.free),
}


Expand Down