Download gpu_manager.py from RDS777/Virtus: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/RDS777/Virtus/resolve/main/gpu_manager.py
- Command line
-
hf download hf://spaces/RDS777/Virtus/gpu_manager.py
-
curl -L -o gpu_manager.py https://huggingface.co/spaces/RDS777/Virtus/resolve/main/gpu_manager.py
1.22 kB
| """ | |
| GPU Manager — monitoring VRAM et device CUDA | |
| """ | |
| import threading | |
| from typing import Dict, Any | |
| _manager_instance = None | |
| _manager_lock = threading.Lock() | |
| class GPUManager: | |
| def __init__(self): | |
| self._device = None | |
| self._vram_total = 0 | |
| self._vram_used = 0 | |
| try: | |
| import torch | |
| if torch.cuda.is_available(): | |
| self._device = torch.cuda.get_device_name(0) | |
| self._vram_total = torch.cuda.get_device_properties(0).total_memory // (1024 ** 2) | |
| except Exception: | |
| pass | |
| def status(self) -> Dict[str, Any]: | |
| try: | |
| import torch | |
| if torch.cuda.is_available(): | |
| self._vram_used = torch.cuda.memory_allocated(0) // (1024 ** 2) | |
| except Exception: | |
| pass | |
| return { | |
| "device": self._device, | |
| "vram_total_mb": self._vram_total, | |
| "vram_used_mb": self._vram_used, | |
| } | |
| def get_gpu_manager() -> GPUManager: | |
| global _manager_instance | |
| if _manager_instance is None: | |
| with _manager_lock: | |
| if _manager_instance is None: | |
| _manager_instance = GPUManager() | |
| return _manager_instance |