|
|
|
"""Test script to verify external SSD cache configuration works correctly.""" |
|
|
|
import os |
|
import sys |
|
from pathlib import Path |
|
|
|
|
|
def test_cache_configuration(): |
|
"""Test that the external cache configuration is working.""" |
|
|
|
print("π§ͺ Testing External SSD Cache Configuration") |
|
print("=" * 50) |
|
|
|
|
|
external_path = Path("/Volumes/extssd") |
|
if not external_path.exists(): |
|
print("β External SSD not found at /Volumes/extssd") |
|
return False |
|
|
|
print("β
External SSD is mounted") |
|
|
|
|
|
hf_home = os.environ.get("HF_HOME") |
|
expected_hf_home = "/Volumes/extssd/huggingface" |
|
|
|
if hf_home != expected_hf_home: |
|
print( |
|
f"β οΈ HF_HOME not set correctly. Expected: {expected_hf_home}, Got: {hf_home}" |
|
) |
|
print(" Set HF_HOME with: export HF_HOME=/Volumes/extssd/huggingface") |
|
return False |
|
|
|
print(f"β
HF_HOME correctly set to: {hf_home}") |
|
|
|
|
|
hub_cache = Path(hf_home) / "hub" |
|
if not hub_cache.exists(): |
|
print(f"β Hub cache directory not found at: {hub_cache}") |
|
return False |
|
|
|
print(f"β
Hub cache directory exists at: {hub_cache}") |
|
|
|
|
|
model_count = len(list(hub_cache.glob("models--*"))) |
|
print(f"β
Found {model_count} models in cache") |
|
|
|
|
|
try: |
|
from transformers import AutoTokenizer |
|
|
|
print("β
Hugging Face libraries imported successfully") |
|
|
|
|
|
print("π Testing cache with a small model (this may take a moment)...") |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("openai/clip-vit-base-patch32") |
|
|
|
print("β
Successfully loaded model from cache") |
|
|
|
|
|
clip_path = hub_cache / "models--openai--clip-vit-base-patch32" |
|
if clip_path.exists(): |
|
print(f"β
Model files found in external cache at: {clip_path}") |
|
else: |
|
print(f"β οΈ Model files not found at expected location: {clip_path}") |
|
return False |
|
|
|
return True |
|
|
|
except Exception as e: |
|
print(f"β Error loading model: {e}") |
|
return False |
|
|
|
|
|
def main(): |
|
"""Main test function.""" |
|
|
|
env_file = Path(__file__).parent / ".env" |
|
if env_file.exists(): |
|
print("π Loading .env file...") |
|
from dotenv import load_dotenv |
|
|
|
load_dotenv() |
|
else: |
|
print("β οΈ No .env file found, using system environment variables") |
|
|
|
success = test_cache_configuration() |
|
|
|
print("\n" + "=" * 50) |
|
if success: |
|
print("π All tests passed! External SSD cache is working correctly.") |
|
print("You can now run the application with: ./run.sh") |
|
else: |
|
print("β Some tests failed. Please check the configuration.") |
|
sys.exit(1) |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |
|
|