File size: 6,318 Bytes
c8b42eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python3
"""
Validation script for UniCeption installation.

This script validates that all components of UniCeption are correctly installed
and provides helpful diagnostics.
"""

import importlib
import sys
from pathlib import Path


def check_package_installation():
    """Check if UniCeption package is properly installed."""
    try:
        import uniception

        print("βœ“ UniCeption package is installed")

        # Check if we can import core modules
        try:
            from uniception.models.encoders import UniCeptionViTEncoderBase

            print("βœ“ Core encoder modules are available")
        except ImportError as e:
            print(f"βœ— Failed to import core encoder modules: {e}")

        return True
    except ImportError as e:
        print(f"βœ— UniCeption package not found: {e}")
        return False


def check_dependencies():
    """Check optional dependencies."""
    dependencies = {
        "torch": "PyTorch",
        "torchvision": "TorchVision",
        "torchaudio": "TorchAudio",
        "xformers": "XFormers",
        "timm": "Timm (PyTorch Image Models)",
        "einops": "Einops",
        "matplotlib": "Matplotlib",
        "numpy": "NumPy",
        "PIL": "Pillow",
    }

    available = []
    missing = []

    for module, name in dependencies.items():
        try:
            mod = importlib.import_module(module)
            version = getattr(mod, "__version__", "unknown")
            available.append(f"βœ“ {name}: {version}")
        except ImportError:
            missing.append(f"βœ— {name}: not installed")

    print("\nDependency Status:")
    for dep in available:
        print(f"  {dep}")

    if missing:
        print("\nMissing Dependencies:")
        for dep in missing:
            print(f"  {dep}")

    return len(missing) == 0


def check_cuda_support():
    """Check CUDA support."""
    try:
        import torch

        if torch.cuda.is_available():
            print(f"\nβœ“ CUDA is available")
            print(f"  CUDA version: {torch.version.cuda}")
            print(f"  Available devices: {torch.cuda.device_count()}")
            for i in range(torch.cuda.device_count()):
                print(f"    Device {i}: {torch.cuda.get_device_name(i)}")
        else:
            print(f"\n⚠ CUDA is not available (CPU-only mode)")
    except ImportError:
        print(f"\n⚠ PyTorch not installed - cannot check CUDA support")


def check_croco_rope():
    """Check CroCo RoPE extension."""
    try:
        from uniception.models.libs.croco.curope import cuRoPE2D

        print("\nβœ“ CroCo RoPE extension is available")
        return True
    except ImportError:
        print("\nβœ— CroCo RoPE extension not available")
        print("  To install: cd uniception/models/libs/croco/curope && python setup.py build_ext --inplace")
        return False


def check_model_availability():
    """Check if models can be loaded."""
    try:
        # Try to check if encoder modules are available
        from uniception.models import encoders

        print(f"\nβœ“ Encoder module is available")

        # Try to run the encoder list command
        try:
            import subprocess

            result = subprocess.run(
                [sys.executable, "-m", "uniception.models.encoders.list"], capture_output=True, text=True, timeout=10
            )

            if result.returncode == 0:
                lines = result.stdout.strip().split("\n")
                encoder_count = len([line for line in lines if line.strip() and not line.startswith("Available")])
                print(f"βœ“ Available encoders: {encoder_count}")
                return True
            else:
                print(f"⚠ Encoder listing returned non-zero exit code: {result.returncode}")
                return False

        except subprocess.TimeoutExpired:
            print(f"⚠ Encoder listing timed out")
            return False
        except Exception as e:
            print(f"⚠ Could not run encoder listing: {e}")
            return False

    except Exception as e:
        print(f"\nβœ— Failed to access encoder modules: {e}")
        return False


def check_file_structure():
    """Check if the project file structure is correct."""
    base_path = Path(__file__).parent.parent
    required_dirs = [
        "uniception",
        "uniception/models",
        "uniception/models/encoders",
        "uniception/models/info_sharing",
        "uniception/models/prediction_heads",
        "scripts",
        "tests",
    ]

    missing_dirs = []
    for dir_path in required_dirs:
        full_path = base_path / dir_path
        if not full_path.exists():
            missing_dirs.append(dir_path)

    if missing_dirs:
        print(f"\nβœ— Missing directories:")
        for dir_path in missing_dirs:
            print(f"  - {dir_path}")
        return False
    else:
        print(f"\nβœ“ Project structure is correct")
        return True


def main():
    """Run all validation checks."""
    print("UniCeption Installation Validation")
    print("=" * 40)

    checks = [
        ("Package Installation", check_package_installation),
        ("Dependencies", check_dependencies),
        ("CUDA Support", check_cuda_support),
        ("CroCo RoPE Extension", check_croco_rope),
        ("Model Availability", check_model_availability),
        ("File Structure", check_file_structure),
    ]

    results = []
    for name, check_func in checks:
        print(f"\nChecking {name}...")
        try:
            result = check_func()
            results.append((name, result))
        except Exception as e:
            print(f"βœ— Error during {name} check: {e}")
            results.append((name, False))

    # Summary
    print("\n" + "=" * 40)
    print("Validation Summary:")
    passed = 0
    for name, result in results:
        status = "βœ“ PASS" if result else "βœ— FAIL"
        print(f"  {name}: {status}")
        if result:
            passed += 1

    print(f"\nOverall: {passed}/{len(results)} checks passed")

    if passed == len(results):
        print("πŸŽ‰ All checks passed! UniCeption is ready to use.")
        return 0
    else:
        print("⚠ Some checks failed. Please review the issues above.")
        return 1


if __name__ == "__main__":
    sys.exit(main())