Spaces:
Runtime error
Runtime error
Rick
commited on
Commit
·
deb790d
1
Parent(s):
fbe99e8
Add startup cache cleanup and disk report
Browse files
app.py
CHANGED
|
@@ -9,10 +9,23 @@ import threading
|
|
| 9 |
import base64
|
| 10 |
import time
|
| 11 |
import re
|
|
|
|
| 12 |
from datetime import datetime
|
| 13 |
from pathlib import Path
|
| 14 |
from typing import List, Optional
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# Encourage less fragmentation on GPUs with limited VRAM (e.g., RTX 5000)
|
| 17 |
os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
|
| 18 |
# Allow online downloads by default (HF Spaces first run needs this). You can set these to "1" after caches are warm.
|
|
|
|
| 9 |
import base64
|
| 10 |
import time
|
| 11 |
import re
|
| 12 |
+
import subprocess
|
| 13 |
from datetime import datetime
|
| 14 |
from pathlib import Path
|
| 15 |
from typing import List, Optional
|
| 16 |
|
| 17 |
+
|
| 18 |
+
# Temporary startup cleanup to reclaim space and report usage on HF Spaces
|
| 19 |
+
def _cleanup_and_report():
|
| 20 |
+
try:
|
| 21 |
+
import subprocess as _sp
|
| 22 |
+
_sp.run("rm -rf ~/.cache/huggingface ~/.cache/torch ~/.cache/pip ~/.cache/*", shell=True, check=False)
|
| 23 |
+
_sp.run("df -h && du -sh /home/user /home/user/* ~/.cache 2>/dev/null | sort -hr | head -30", shell=True, check=False)
|
| 24 |
+
except Exception as exc:
|
| 25 |
+
print(f"[startup-cleanup] failed: {exc}")
|
| 26 |
+
|
| 27 |
+
_cleanup_and_report()
|
| 28 |
+
|
| 29 |
# Encourage less fragmentation on GPUs with limited VRAM (e.g., RTX 5000)
|
| 30 |
os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
|
| 31 |
# Allow online downloads by default (HF Spaces first run needs this). You can set these to "1" after caches are warm.
|