Spaces:
Configuration error
Configuration error
Download gpu_profiler.py from wliu283/RealWonder: direct link, hf CLI and curl.
- Browser
- Download file 833 Bytes
-
https://huggingface.co/spaces/wliu283/RealWonder/resolve/main/gpu_profiler.py
- Command line
-
hf download hf://spaces/wliu283/RealWonder/gpu_profiler.py
-
curl -L -o gpu_profiler.py https://huggingface.co/spaces/wliu283/RealWonder/resolve/main/gpu_profiler.py
833 Bytes
| """GPU memory profiling utility.""" | |
| import torch | |
| _enabled = True | |
| def set_gpu_logging(enabled: bool): | |
| global _enabled | |
| _enabled = enabled | |
| def log_gpu(label: str): | |
| """Print GPU memory usage at a labeled checkpoint.""" | |
| if not _enabled or not torch.cuda.is_available(): | |
| return | |
| allocated = torch.cuda.memory_allocated() / (1024 ** 3) | |
| reserved = torch.cuda.memory_reserved() / (1024 ** 3) | |
| max_allocated = torch.cuda.max_memory_allocated() / (1024 ** 3) | |
| free, total = torch.cuda.mem_get_info() | |
| free_gb = free / (1024 ** 3) | |
| total_gb = total / (1024 ** 3) | |
| print( | |
| f"[GPU] {label:<45s} | " | |
| f"alloc: {allocated:6.2f} GB | " | |
| f"reserved: {reserved:6.2f} GB | " | |
| f"peak: {max_allocated:6.2f} GB | " | |
| f"free: {free_gb:6.2f} GB / {total_gb:.1f} GB" | |
| ) | |