Spaces:
Running
Running
File size: 6,067 Bytes
d8dd7a1 |
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 |
#!/usr/bin/env python3
"""
Test Setup Script
Verifies that all components are working correctly
"""
import os
import sys
import torch
import logging
from pathlib import Path
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_imports():
"""Test that all required modules can be imported"""
logger.info("Testing imports...")
try:
import transformers
logger.info(f"β transformers {transformers.__version__}")
except ImportError as e:
logger.error(f"β transformers: {e}")
return False
try:
import datasets
logger.info(f"β datasets {datasets.__version__}")
except ImportError as e:
logger.error(f"β datasets: {e}")
return False
try:
import trl
logger.info(f"β trl {trl.__version__}")
except ImportError as e:
logger.error(f"β trl: {e}")
return False
try:
import accelerate
logger.info(f"β accelerate {accelerate.__version__}")
except ImportError as e:
logger.error(f"β accelerate: {e}")
return False
return True
def test_local_imports():
"""Test that local modules can be imported"""
logger.info("Testing local imports...")
try:
from config import get_config
logger.info("β config module")
except ImportError as e:
logger.error(f"β config module: {e}")
return False
try:
from model import SmolLM3Model
logger.info("β model module")
except ImportError as e:
logger.error(f"β model module: {e}")
return False
try:
from data import SmolLM3Dataset
logger.info("β data module")
except ImportError as e:
logger.error(f"β data module: {e}")
return False
try:
from trainer import SmolLM3Trainer
logger.info("β trainer module")
except ImportError as e:
logger.error(f"β trainer module: {e}")
return False
return True
def test_config():
"""Test configuration loading"""
logger.info("Testing configuration...")
try:
from config import get_config
config = get_config("config/train_smollm3.py")
logger.info(f"β Configuration loaded: {config.model_name}")
return True
except Exception as e:
logger.error(f"β Configuration loading failed: {e}")
return False
def test_dataset_creation():
"""Test dataset creation"""
logger.info("Testing dataset creation...")
try:
from data import create_sample_dataset
output_path = create_sample_dataset("test_dataset")
# Check if files were created
train_file = os.path.join(output_path, "train.json")
val_file = os.path.join(output_path, "validation.json")
if os.path.exists(train_file) and os.path.exists(val_file):
logger.info("β Sample dataset created successfully")
# Clean up
import shutil
shutil.rmtree(output_path)
return True
else:
logger.error("β Dataset files not created")
return False
except Exception as e:
logger.error(f"β Dataset creation failed: {e}")
return False
def test_gpu_availability():
"""Test GPU availability"""
logger.info("Testing GPU availability...")
if torch.cuda.is_available():
logger.info(f"β GPU available: {torch.cuda.get_device_name(0)}")
logger.info(f"β CUDA version: {torch.version.cuda}")
logger.info(f"β GPU memory: {torch.cuda.get_device_properties(0).total_memory / 1e9:.1f} GB")
return True
else:
logger.warning("β No GPU available, will use CPU")
return True
def test_model_loading():
"""Test model loading (without downloading)"""
logger.info("Testing model loading...")
try:
from transformers import AutoTokenizer, AutoConfig
# Test tokenizer loading
tokenizer = AutoTokenizer.from_pretrained(
"HuggingFaceTB/SmolLM3-3B",
trust_remote_code=True,
use_fast=True
)
logger.info(f"β Tokenizer loaded, vocab size: {tokenizer.vocab_size}")
# Test config loading
config = AutoConfig.from_pretrained(
"HuggingFaceTB/SmolLM3-3B",
trust_remote_code=True
)
logger.info(f"β Config loaded, model type: {config.model_type}")
return True
except Exception as e:
logger.error(f"β Model loading test failed: {e}")
return False
def main():
"""Run all tests"""
logger.info("Starting SmolLM3 setup tests...")
tests = [
("Import Tests", test_imports),
("Local Import Tests", test_local_imports),
("Configuration Tests", test_config),
("Dataset Creation Tests", test_dataset_creation),
("GPU Availability Tests", test_gpu_availability),
("Model Loading Tests", test_model_loading),
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
logger.info(f"\n{'='*50}")
logger.info(f"Running: {test_name}")
logger.info('='*50)
try:
if test_func():
passed += 1
logger.info(f"β {test_name} PASSED")
else:
logger.error(f"β {test_name} FAILED")
except Exception as e:
logger.error(f"β {test_name} FAILED with exception: {e}")
logger.info(f"\n{'='*50}")
logger.info(f"Test Results: {passed}/{total} tests passed")
logger.info('='*50)
if passed == total:
logger.info("π All tests passed! Setup is ready for SmolLM3 fine-tuning.")
return 0
else:
logger.error("β Some tests failed. Please check the errors above.")
return 1
if __name__ == '__main__':
sys.exit(main()) |