Spaces:
Sleeping
Sleeping
Commit
·
4be72e0
1
Parent(s):
f0033ab
Fix delete_revisions import - use fallback cache cleanup method
Browse files- delete_revisions may not be available in all huggingface_hub versions
- Add fallback to manual cache directory deletion
- Use shutil.rmtree as alternative when delete_revisions unavailable
- Add helpful manual cleanup instructions
- quantize_to_awq_colab.ipynb +33 -3
quantize_to_awq_colab.ipynb
CHANGED
|
@@ -164,12 +164,21 @@
|
|
| 164 |
" raise\n",
|
| 165 |
"\n",
|
| 166 |
"from transformers import AutoTokenizer\n",
|
| 167 |
-
"from huggingface_hub import HfApi, scan_cache_dir,
|
| 168 |
"import torch\n",
|
| 169 |
"import shutil\n",
|
| 170 |
"import gc\n",
|
| 171 |
"import os\n",
|
| 172 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
"def quantize_model_to_awq(\n",
|
| 174 |
" model_name: str,\n",
|
| 175 |
" repo_id: str,\n",
|
|
@@ -328,12 +337,33 @@
|
|
| 328 |
" revisions_to_delete.append(repo)\n",
|
| 329 |
" \n",
|
| 330 |
" if revisions_to_delete:\n",
|
| 331 |
-
"
|
| 332 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
" else:\n",
|
| 334 |
" print(f\" ℹ️ No cached revisions found for {repo_id}\")\n",
|
| 335 |
" except Exception as e:\n",
|
| 336 |
" print(f\" ⚠️ Cache cleanup warning: {e} (continuing...)\")\n",
|
|
|
|
| 337 |
" \n",
|
| 338 |
" # Check disk space after cleanup\n",
|
| 339 |
" free_space_after = check_disk_space()\n",
|
|
|
|
| 164 |
" raise\n",
|
| 165 |
"\n",
|
| 166 |
"from transformers import AutoTokenizer\n",
|
| 167 |
+
"from huggingface_hub import HfApi, scan_cache_dir, upload_folder\n",
|
| 168 |
"import torch\n",
|
| 169 |
"import shutil\n",
|
| 170 |
"import gc\n",
|
| 171 |
"import os\n",
|
| 172 |
"\n",
|
| 173 |
+
"# Try to import delete_revisions (may not be available in all versions)\n",
|
| 174 |
+
"try:\n",
|
| 175 |
+
" from huggingface_hub import delete_revisions\n",
|
| 176 |
+
" DELETE_REVISIONS_AVAILABLE = True\n",
|
| 177 |
+
"except ImportError:\n",
|
| 178 |
+
" # delete_revisions might not be available, we'll use alternative method\n",
|
| 179 |
+
" DELETE_REVISIONS_AVAILABLE = False\n",
|
| 180 |
+
" print(\"Note: delete_revisions not available, will use alternative cache cleanup method\")\n",
|
| 181 |
+
"\n",
|
| 182 |
"def quantize_model_to_awq(\n",
|
| 183 |
" model_name: str,\n",
|
| 184 |
" repo_id: str,\n",
|
|
|
|
| 337 |
" revisions_to_delete.append(repo)\n",
|
| 338 |
" \n",
|
| 339 |
" if revisions_to_delete:\n",
|
| 340 |
+
" if DELETE_REVISIONS_AVAILABLE:\n",
|
| 341 |
+
" # Use delete_revisions if available\n",
|
| 342 |
+
" delete_revisions(revisions_to_delete)\n",
|
| 343 |
+
" print(f\" ✅ Deleted {len(revisions_to_delete)} cached revision(s) for {repo_id}\")\n",
|
| 344 |
+
" else:\n",
|
| 345 |
+
" # Alternative: Delete cache directories manually\n",
|
| 346 |
+
" deleted_count = 0\n",
|
| 347 |
+
" for revision in revisions_to_delete:\n",
|
| 348 |
+
" try:\n",
|
| 349 |
+
" # Get the cache directory path\n",
|
| 350 |
+
" cache_path = revision.snapshot_path if hasattr(revision, 'snapshot_path') else None\n",
|
| 351 |
+
" if cache_path and os.path.exists(cache_path):\n",
|
| 352 |
+
" shutil.rmtree(cache_path)\n",
|
| 353 |
+
" deleted_count += 1\n",
|
| 354 |
+
" except Exception as e:\n",
|
| 355 |
+
" print(f\" ⚠️ Could not delete {revision.repo_id}: {e}\")\n",
|
| 356 |
+
" \n",
|
| 357 |
+
" if deleted_count > 0:\n",
|
| 358 |
+
" print(f\" ✅ Deleted {deleted_count} cached revision(s) for {repo_id}\")\n",
|
| 359 |
+
" else:\n",
|
| 360 |
+
" print(f\" ℹ️ Found {len(revisions_to_delete)} cached revision(s) but couldn't delete them\")\n",
|
| 361 |
+
" print(f\" Try manually: huggingface-cli scan-cache --dir ~/.cache/huggingface\")\n",
|
| 362 |
" else:\n",
|
| 363 |
" print(f\" ℹ️ No cached revisions found for {repo_id}\")\n",
|
| 364 |
" except Exception as e:\n",
|
| 365 |
" print(f\" ⚠️ Cache cleanup warning: {e} (continuing...)\")\n",
|
| 366 |
+
" print(f\" You can manually clean cache with: huggingface-cli scan-cache\")\n",
|
| 367 |
" \n",
|
| 368 |
" # Check disk space after cleanup\n",
|
| 369 |
" free_space_after = check_disk_space()\n",
|