()
| 53 | torch.cuda.synchronize() |
| 54 | |
| 55 | def check_gpu_memory(): |
| 56 | if device == "cuda" and torch.cuda.is_available(): |
| 57 | total_memory = torch.cuda.get_device_properties(0).total_memory / 1024**3 |
| 58 | allocated_memory = torch.cuda.memory_allocated(0) / 1024**3 |
| 59 | cached_memory = torch.cuda.memory_reserved(0) / 1024**3 |
| 60 | print(f"[INFO] GPU Memory - Total: {total_memory:.1f}GB, Allocated: {allocated_memory:.1f}GB, Cached: {cached_memory:.1f}GB") |
| 61 | return total_memory, allocated_memory, cached_memory |
| 62 | return None, None, None |
| 63 | |
| 64 | def safe_generate_with_fallback(model, generate_func, *args, **kwargs): |
| 65 | try: |
no outgoing calls
no test coverage detected