File size: 3,151 Bytes
7e5d515
 
 
 
 
 
 
b24c04f
7e5d515
 
b24c04f
7e5d515
 
b24c04f
7e5d515
 
 
 
 
b24c04f
7e5d515
b24c04f
7e5d515
 
 
b24c04f
7e5d515
b24c04f
 
 
7e5d515
 
b24c04f
7e5d515
b24c04f
7e5d515
 
 
 
 
b24c04f
7e5d515
b24c04f
7e5d515
 
 
b24c04f
7e5d515
 
 
b24c04f
7e5d515
b24c04f
7e5d515
 
b24c04f
7e5d515
5aeda0b
b24c04f
7e5d515
b24c04f
7e5d515
 
 
 
 
 
 
b24c04f
7e5d515
b24c04f
7e5d515
 
 
 
b24c04f
7e5d515
 
 
 
 
 
 
b24c04f
7e5d515
 
 
b24c04f
7e5d515
b24c04f
7e5d515
 
 
 
 
 
 
 
b24c04f
7e5d515
b24c04f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
"""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)

    # Check if external SSD is mounted
    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")

    # Check if HF_HOME is set correctly
    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}")

    # Check if cache directories exist
    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}")

    # Check if models are present
    model_count = len(list(hub_cache.glob("models--*")))
    print(f"βœ… Found {model_count} models in cache")

    # Test importing Hugging Face libraries and check their cache detection
    try:
        from transformers import AutoTokenizer

        print("βœ… Hugging Face libraries imported successfully")

        # Test a small model to verify cache is working
        print("πŸ”„ Testing cache with a small model (this may take a moment)...")

        # This should use the external cache
        _ = AutoTokenizer.from_pretrained("openai/clip-vit-base-patch32")

        print("βœ… Successfully loaded model from cache")

        # Check if the model files are in the expected location
        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."""
    # Load .env file if available
    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()