Add HF cleanup logic in ci_install_dependency.sh (#12895)

This commit is contained in:
Kangyan-Zhou
2025-11-08 22:56:25 -08:00
committed by GitHub
parent c21a3ec299
commit 4b1d163bfd
2 changed files with 50 additions and 0 deletions

View File

@@ -134,3 +134,6 @@ fi
# Show current packages
$PIP_CMD list
python3 -c "import torch; print(torch.version.cuda)"
# Prepare the CI runner (cleanup HuggingFace cache, etc.)
bash "${SCRIPT_DIR}/prepare_runner.sh"

47
scripts/ci/prepare_runner.sh Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Prepare the CI runner by cleaning up incomplete HuggingFace download files
set -euo pipefail
echo "Preparing CI runner..."
# Clean up incomplete HuggingFace download files
echo "Cleaning up incomplete HuggingFace download files..."
python3 << 'EOF'
import os
import glob
try:
from huggingface_hub import constants
hf_cache_dir = constants.HF_HUB_CACHE
except Exception as e:
print(f"Warning: Could not import huggingface_hub constants: {e}")
# Fallback to checking HF_HOME env var or default location
hf_home = os.environ.get('HF_HOME', os.path.expanduser("~/.cache/huggingface"))
hf_cache_dir = os.path.join(hf_home, "hub")
if os.path.exists(hf_cache_dir):
print(f"Checking HuggingFace cache directory: {hf_cache_dir}")
# Clean up incomplete marker files, temporary files, and lock files
patterns = ['**/*.incomplete', '**/*.tmp', '**/*.lock']
cleaned_count = 0
for pattern in patterns:
files = glob.glob(os.path.join(hf_cache_dir, pattern), recursive=True)
for file_path in files:
try:
os.remove(file_path)
print(f"Removed: {file_path}")
cleaned_count += 1
except Exception as e:
print(f"Warning: Could not remove {file_path}: {e}")
if cleaned_count > 0:
print(f"Cleaned up {cleaned_count} incomplete HuggingFace download file(s)")
else:
print("No incomplete HuggingFace download files found")
else:
print(f"HuggingFace cache directory does not exist: {hf_cache_dir}")
EOF
echo "CI runner preparation complete!"