Spaces:
Running
Running
Commit
·
24bc58a
1
Parent(s):
7d7d40d
Create query_gpu0_vram.py
Browse files- query_gpu0_vram.py +19 -0
query_gpu0_vram.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pynvml
|
| 2 |
+
|
| 3 |
+
def get_free_vram_gpu0():
|
| 4 |
+
pynvml.nvmlInit()
|
| 5 |
+
handle = pynvml.nvmlDeviceGetHandleByIndex(0) # Select GPU 0
|
| 6 |
+
mem_info = pynvml.nvmlDeviceGetMemoryInfo(handle)
|
| 7 |
+
free_vram_bytes = mem_info.free
|
| 8 |
+
|
| 9 |
+
# Convert bytes to human-readable format
|
| 10 |
+
def sizeof_fmt(num, suffix='B'):
|
| 11 |
+
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
|
| 12 |
+
if abs(num) < 1024.0:
|
| 13 |
+
return "%3.1f %s%s" % (num, unit, suffix)
|
| 14 |
+
num /= 1024.0
|
| 15 |
+
return "%.1f %s%s" % (num, 'Yi', suffix)
|
| 16 |
+
|
| 17 |
+
return sizeof_fmt(free_vram_bytes)
|
| 18 |
+
|
| 19 |
+
print(get_free_vram_gpu0())
|