Spaces:
Running
on
Zero
Running
on
Zero
CPU (stateless GPU mode)
Browse files- app/utils.py +4 -0
app/utils.py
CHANGED
|
@@ -70,6 +70,10 @@ def get_current_device():
|
|
| 70 |
try:
|
| 71 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 72 |
device_name = torch.cuda.get_device_name(0) if torch.cuda.is_available() else "CPU"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
except RuntimeError as e:
|
| 74 |
if "CUDA must not be initialized" in str(e):
|
| 75 |
device = torch.device("cpu")
|
|
|
|
| 70 |
try:
|
| 71 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 72 |
device_name = torch.cuda.get_device_name(0) if torch.cuda.is_available() else "CPU"
|
| 73 |
+
torch.tensor([0], dtype=torch.float32, device=device)
|
| 74 |
+
if torch.cuda.is_available():
|
| 75 |
+
torch.cuda.empty_cache()
|
| 76 |
+
logging.debug("GPU cache cleared")
|
| 77 |
except RuntimeError as e:
|
| 78 |
if "CUDA must not be initialized" in str(e):
|
| 79 |
device = torch.device("cpu")
|