Commit ·
e1ae3fc
1
Parent(s): 907836d
add scripts to delete old versions
Browse files- delete-past-version.sh +138 -4
- generate-vad-asr.py +11 -0
delete-past-version.sh
CHANGED
|
@@ -62,7 +62,71 @@ done
|
|
| 62 |
|
| 63 |
if [[ ${#paths_to_remove[@]} -eq 0 ]]; then
|
| 64 |
echo ""
|
| 65 |
-
echo "Nothing to remove
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
exit 0
|
| 67 |
fi
|
| 68 |
|
|
@@ -140,6 +204,14 @@ else
|
|
| 140 |
exit 1
|
| 141 |
fi
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
# ============================================================
|
| 144 |
# Stage, commit, and force-push
|
| 145 |
# ============================================================
|
|
@@ -151,12 +223,74 @@ echo "Committing..."
|
|
| 151 |
git commit -m "Remove old versions (< $remove_version_up_to) to free Hugging Face storage"
|
| 152 |
|
| 153 |
echo ""
|
| 154 |
-
echo "Force-pushing to origin..."
|
| 155 |
git push origin --force --all
|
| 156 |
git push origin --force --tags
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
echo ""
|
| 159 |
echo "================================================================"
|
| 160 |
-
echo "
|
| 161 |
-
echo "and
|
|
|
|
| 162 |
echo "================================================================"
|
|
|
|
| 62 |
|
| 63 |
if [[ ${#paths_to_remove[@]} -eq 0 ]]; then
|
| 64 |
echo ""
|
| 65 |
+
echo "Nothing to remove from the working tree."
|
| 66 |
+
echo "Checking for orphaned LFS files on Hugging Face server..."
|
| 67 |
+
echo ""
|
| 68 |
+
|
| 69 |
+
REMOTE_URL=$(git remote get-url origin 2>/dev/null || true)
|
| 70 |
+
if [[ -z "$REMOTE_URL" ]]; then
|
| 71 |
+
echo "No remote found. Nothing to do."
|
| 72 |
+
exit 0
|
| 73 |
+
fi
|
| 74 |
+
|
| 75 |
+
REPO_ID=$(echo "$REMOTE_URL" | sed -E 's|.*[:/](.+/[^/.]+)(\.git)?$|\1|')
|
| 76 |
+
|
| 77 |
+
python3 << PYEOF
|
| 78 |
+
import re
|
| 79 |
+
import sys
|
| 80 |
+
import os
|
| 81 |
+
from huggingface_hub import HfApi
|
| 82 |
+
|
| 83 |
+
api = HfApi()
|
| 84 |
+
|
| 85 |
+
# Check authentication: try HF_TOKEN env var, then saved token
|
| 86 |
+
token = os.environ.get("HF_TOKEN") or api.token
|
| 87 |
+
if not token:
|
| 88 |
+
print("ERROR: Not authenticated with Hugging Face.")
|
| 89 |
+
print("Please do ONE of the following:")
|
| 90 |
+
print(" 1. Run: hf auth login")
|
| 91 |
+
print(" 2. Set env var: export HF_TOKEN=your_token_here")
|
| 92 |
+
print(" (get a token at https://huggingface.co/settings/tokens)")
|
| 93 |
+
sys.exit(1)
|
| 94 |
+
|
| 95 |
+
repo_id = "$REPO_ID"
|
| 96 |
+
remove_up_to = "$remove_version_up_to"
|
| 97 |
+
|
| 98 |
+
def parse_version(v):
|
| 99 |
+
parts = v.split(".")
|
| 100 |
+
return int(parts[0]) * 100000 + int(parts[1]) * 10000 + int(parts[2]) * 10
|
| 101 |
+
|
| 102 |
+
cutoff = parse_version(remove_up_to)
|
| 103 |
+
|
| 104 |
+
print(f"Listing LFS files in {repo_id}...")
|
| 105 |
+
all_lfs = list(api.list_lfs_files(repo_id, token=token))
|
| 106 |
+
print(f"Found {len(all_lfs)} LFS files total")
|
| 107 |
+
|
| 108 |
+
old_files = []
|
| 109 |
+
for f in all_lfs:
|
| 110 |
+
m = re.search(r"(\d+\.\d+\.\d+)", f.filename)
|
| 111 |
+
if m and parse_version(m.group(1)) < cutoff:
|
| 112 |
+
old_files.append(f)
|
| 113 |
+
|
| 114 |
+
if not old_files:
|
| 115 |
+
print("No orphaned LFS files found. Storage is already clean.")
|
| 116 |
+
sys.exit(0)
|
| 117 |
+
|
| 118 |
+
total_size = sum(f.size for f in old_files)
|
| 119 |
+
print(f"Found {len(old_files)} orphaned LFS files ({total_size / 1024**3:.1f} GB)")
|
| 120 |
+
print("Deleting them from the Hub (this may take a while)...")
|
| 121 |
+
api.permanently_delete_lfs_files(repo_id, old_files, token=token)
|
| 122 |
+
print(f"Done! Freed {total_size / 1024**3:.1f} GB of storage.")
|
| 123 |
+
PYEOF
|
| 124 |
+
|
| 125 |
+
echo ""
|
| 126 |
+
echo "================================================================"
|
| 127 |
+
echo "Done! Orphaned LFS files have been permanently deleted from"
|
| 128 |
+
echo "the Hugging Face server."
|
| 129 |
+
echo "================================================================"
|
| 130 |
exit 0
|
| 131 |
fi
|
| 132 |
|
|
|
|
| 204 |
exit 1
|
| 205 |
fi
|
| 206 |
|
| 207 |
+
# ============================================================
|
| 208 |
+
# Prune orphaned LFS objects locally
|
| 209 |
+
# (objects that are no longer referenced by any commit)
|
| 210 |
+
# ============================================================
|
| 211 |
+
echo ""
|
| 212 |
+
echo "Pruning orphaned LFS objects locally..."
|
| 213 |
+
git lfs prune
|
| 214 |
+
|
| 215 |
# ============================================================
|
| 216 |
# Stage, commit, and force-push
|
| 217 |
# ============================================================
|
|
|
|
| 223 |
git commit -m "Remove old versions (< $remove_version_up_to) to free Hugging Face storage"
|
| 224 |
|
| 225 |
echo ""
|
| 226 |
+
echo "Force-pushing git history to origin..."
|
| 227 |
git push origin --force --all
|
| 228 |
git push origin --force --tags
|
| 229 |
|
| 230 |
+
echo ""
|
| 231 |
+
echo "Pushing LFS state to origin..."
|
| 232 |
+
git lfs push --all origin
|
| 233 |
+
|
| 234 |
+
# ============================================================
|
| 235 |
+
# Permanently delete orphaned LFS files from Hugging Face
|
| 236 |
+
# (This is the key step that actually frees server-side storage)
|
| 237 |
+
# ============================================================
|
| 238 |
+
echo ""
|
| 239 |
+
echo "Deleting orphaned LFS files from Hugging Face server..."
|
| 240 |
+
|
| 241 |
+
# Extract repo ID from remote URL (e.g., git@hf.co2:user/repo -> user/repo)
|
| 242 |
+
REPO_ID=$(echo "$REMOTE_URL" | sed -E 's|.*[:/](.+/[^/.]+)(\.git)?$|\1|')
|
| 243 |
+
|
| 244 |
+
python3 << PYEOF
|
| 245 |
+
import re
|
| 246 |
+
import sys
|
| 247 |
+
import os
|
| 248 |
+
from huggingface_hub import HfApi
|
| 249 |
+
|
| 250 |
+
api = HfApi()
|
| 251 |
+
|
| 252 |
+
token = os.environ.get("HF_TOKEN") or api.token
|
| 253 |
+
if not token:
|
| 254 |
+
print("ERROR: Not authenticated with Hugging Face.")
|
| 255 |
+
print("Please do ONE of the following:")
|
| 256 |
+
print(" 1. Run: hf auth login")
|
| 257 |
+
print(" 2. Set env var: export HF_TOKEN=your_token_here")
|
| 258 |
+
print(" (get a token at https://huggingface.co/settings/tokens)")
|
| 259 |
+
sys.exit(1)
|
| 260 |
+
|
| 261 |
+
repo_id = "$REPO_ID"
|
| 262 |
+
remove_up_to = "$remove_version_up_to"
|
| 263 |
+
|
| 264 |
+
def parse_version(v):
|
| 265 |
+
parts = v.split(".")
|
| 266 |
+
return int(parts[0]) * 100000 + int(parts[1]) * 10000 + int(parts[2]) * 10
|
| 267 |
+
|
| 268 |
+
cutoff = parse_version(remove_up_to)
|
| 269 |
+
|
| 270 |
+
print(f"Listing LFS files in {repo_id}...")
|
| 271 |
+
all_lfs = list(api.list_lfs_files(repo_id, token=token))
|
| 272 |
+
print(f"Found {len(all_lfs)} LFS files total")
|
| 273 |
+
|
| 274 |
+
old_files = []
|
| 275 |
+
for f in all_lfs:
|
| 276 |
+
m = re.search(r"(\d+\.\d+\.\d+)", f.filename)
|
| 277 |
+
if m and parse_version(m.group(1)) < cutoff:
|
| 278 |
+
old_files.append(f)
|
| 279 |
+
|
| 280 |
+
if not old_files:
|
| 281 |
+
print("No orphaned LFS files found on the server. Storage is already clean.")
|
| 282 |
+
sys.exit(0)
|
| 283 |
+
|
| 284 |
+
total_size = sum(f.size for f in old_files)
|
| 285 |
+
print(f"Found {len(old_files)} orphaned LFS files ({total_size / 1024**3:.1f} GB)")
|
| 286 |
+
print("Deleting them from the Hub (this may take a while)...")
|
| 287 |
+
api.permanently_delete_lfs_files(repo_id, old_files, token=token)
|
| 288 |
+
print(f"Done! Freed {total_size / 1024**3:.1f} GB of storage.")
|
| 289 |
+
PYEOF
|
| 290 |
+
|
| 291 |
echo ""
|
| 292 |
echo "================================================================"
|
| 293 |
+
echo "All done! Old versions (< $remove_version_up_to) have been removed,"
|
| 294 |
+
echo "and orphaned LFS files have been permanently deleted from"
|
| 295 |
+
echo "the Hugging Face server."
|
| 296 |
echo "================================================================"
|
generate-vad-asr.py
CHANGED
|
@@ -467,6 +467,17 @@ def to_file(
|
|
| 467 |
print("<br/>", file=f)
|
| 468 |
print("<br/>", file=f)
|
| 469 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
# Table: one row per unique model
|
| 471 |
seen = set()
|
| 472 |
model_rows = []
|
|
|
|
| 467 |
print("<br/>", file=f)
|
| 468 |
print("<br/>", file=f)
|
| 469 |
|
| 470 |
+
print(
|
| 471 |
+
"<strong>Note about storage</strong> "
|
| 472 |
+
"Hugging Face provides limited storage for open-source projects. "
|
| 473 |
+
"To stay within the limit, we <strong>delete old versions frequently</strong> "
|
| 474 |
+
"and only keep the most recent ones. "
|
| 475 |
+
"If you need a specific older version, please build it from source.",
|
| 476 |
+
file=f,
|
| 477 |
+
)
|
| 478 |
+
print("<br/>", file=f)
|
| 479 |
+
print("<br/>", file=f)
|
| 480 |
+
|
| 481 |
# Table: one row per unique model
|
| 482 |
seen = set()
|
| 483 |
model_rows = []
|