File size: 6,981 Bytes
ebe598e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/env python3
"""
Test script for the SmolLM3 end-to-end pipeline
Verifies all components are working correctly
"""

import os
import sys
import subprocess
import importlib
from pathlib import Path

def test_imports():
    """Test that all required modules can be imported"""
    print("πŸ” Testing imports...")
    
    required_modules = [
        'torch',
        'transformers',
        'datasets',
        'accelerate',
        'trl',
        'huggingface_hub',
        'requests'
    ]
    
    failed_imports = []
    for module in required_modules:
        try:
            importlib.import_module(module)
            print(f"βœ… {module}")
        except ImportError as e:
            print(f"❌ {module}: {e}")
            failed_imports.append(module)
    
    if failed_imports:
        print(f"\n❌ Failed imports: {failed_imports}")
        return False
    
    print("βœ… All imports successful")
    return True

def test_local_modules():
    """Test local module imports"""
    print("\nπŸ” Testing local modules...")
    
    # Add src to path
    sys.path.append('src')
    
    local_modules = [
        'config',
        'model',
        'data',
        'trainer',
        'monitoring'
    ]
    
    failed_imports = []
    for module in local_modules:
        try:
            importlib.import_module(module)
            print(f"βœ… {module}")
        except ImportError as e:
            print(f"❌ {module}: {e}")
            failed_imports.append(module)
    
    if failed_imports:
        print(f"\n❌ Failed local imports: {failed_imports}")
        return False
    
    print("βœ… All local modules imported successfully")
    return True

def test_scripts():
    """Test script availability"""
    print("\nπŸ” Testing scripts...")
    
    required_scripts = [
        'scripts/trackio_tonic/deploy_trackio_space.py',
        'scripts/trackio_tonic/configure_trackio.py',
        'scripts/dataset_tonic/setup_hf_dataset.py',
        'scripts/model_tonic/push_to_huggingface.py',
        'src/train.py'
    ]
    
    missing_scripts = []
    for script in required_scripts:
        if Path(script).exists():
            print(f"βœ… {script}")
        else:
            print(f"❌ {script}")
            missing_scripts.append(script)
    
    if missing_scripts:
        print(f"\n❌ Missing scripts: {missing_scripts}")
        return False
    
    print("βœ… All scripts found")
    return True

def test_configs():
    """Test configuration files"""
    print("\nπŸ” Testing configurations...")
    
    config_dir = Path('config')
    if not config_dir.exists():
        print("❌ config directory not found")
        return False
    
    config_files = list(config_dir.glob('*.py'))
    if not config_files:
        print("❌ No configuration files found")
        return False
    
    print(f"βœ… Found {len(config_files)} configuration files:")
    for config in config_files:
        print(f"  - {config.name}")
    
    return True

def test_requirements():
    """Test requirements files"""
    print("\nπŸ” Testing requirements...")
    
    requirements_dir = Path('requirements')
    if not requirements_dir.exists():
        print("❌ requirements directory not found")
        return False
    
    req_files = list(requirements_dir.glob('*.txt'))
    if not req_files:
        print("❌ No requirements files found")
        return False
    
    print(f"βœ… Found {len(req_files)} requirements files:")
    for req in req_files:
        print(f"  - {req.name}")
    
    return True

def test_cuda():
    """Test CUDA availability"""
    print("\nπŸ” Testing CUDA...")
    
    try:
        import torch
        if torch.cuda.is_available():
            device_count = torch.cuda.device_count()
            device_name = torch.cuda.get_device_name(0)
            print(f"βœ… CUDA available: {device_count} device(s)")
            print(f"  - Device 0: {device_name}")
        else:
            print("⚠️  CUDA not available (training will be slower)")
    except Exception as e:
        print(f"❌ CUDA test failed: {e}")
        return False
    
    return True

def test_hf_token():
    """Test Hugging Face token"""
    print("\nπŸ” Testing HF token...")
    
    token = os.environ.get('HF_TOKEN')
    if not token:
        print("⚠️  HF_TOKEN not set (will be prompted during setup)")
        return True
    
    try:
        result = subprocess.run(
            ['huggingface-cli', 'whoami'],
            capture_output=True,
            text=True,
            timeout=10
        )
        
        if result.returncode == 0:
            username = result.stdout.strip()
            print(f"βœ… HF token valid: {username}")
            return True
        else:
            print(f"❌ HF token invalid: {result.stderr}")
            return False
    except Exception as e:
        print(f"❌ HF token test failed: {e}")
        return False

def test_pipeline_components():
    """Test individual pipeline components"""
    print("\nπŸ” Testing pipeline components...")
    
    # Test setup script
    if Path('setup_launch.py').exists():
        print("βœ… setup_launch.py found")
    else:
        print("❌ setup_launch.py not found")
        return False
    
    # Test launch script
    if Path('launch.sh').exists():
        print("βœ… launch.sh found")
    else:
        print("❌ launch.sh not found")
        return False
    
    # Test README
    if Path('README_END_TO_END.md').exists():
        print("βœ… README_END_TO_END.md found")
    else:
        print("❌ README_END_TO_END.md not found")
        return False
    
    return True

def main():
    """Run all tests"""
    print("πŸ§ͺ SmolLM3 End-to-End Pipeline Test")
    print("=" * 50)
    
    tests = [
        test_imports,
        test_local_modules,
        test_scripts,
        test_configs,
        test_requirements,
        test_cuda,
        test_hf_token,
        test_pipeline_components
    ]
    
    passed = 0
    total = len(tests)
    
    for test in tests:
        try:
            if test():
                passed += 1
        except Exception as e:
            print(f"❌ Test failed with exception: {e}")
    
    print(f"\nπŸ“Š Test Results: {passed}/{total} passed")
    
    if passed == total:
        print("πŸŽ‰ All tests passed! Pipeline is ready to use.")
        print("\nπŸš€ Next steps:")
        print("1. Run: python setup_launch.py")
        print("2. Run: chmod +x launch.sh")
        print("3. Run: ./launch.sh")
    else:
        print("❌ Some tests failed. Please fix the issues before running the pipeline.")
        print("\nπŸ”§ Common fixes:")
        print("1. Install missing packages: pip install -r requirements/requirements_core.txt")
        print("2. Set HF_TOKEN environment variable")
        print("3. Check CUDA installation")
    
    return passed == total

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)