Spaces:
Running
Running
File size: 8,864 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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
#!/usr/bin/env python3
"""
Test script for monitoring integration with HF Datasets
"""
import os
import sys
import logging
from datetime import datetime
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_monitoring_import():
"""Test that monitoring can be imported"""
try:
from monitoring import SmolLM3Monitor, create_monitor_from_config
logger.info("β
Monitoring module imported successfully")
return True
except ImportError as e:
logger.error(f"β Failed to import monitoring: {e}")
return False
def test_monitor_creation():
"""Test monitor creation with environment variables"""
try:
from monitoring import SmolLM3Monitor
# Test with environment variables
hf_token = os.environ.get('HF_TOKEN')
dataset_repo = os.environ.get('TRACKIO_DATASET_REPO', 'tonic/trackio-experiments')
logger.info(f"π§ Testing monitor creation...")
logger.info(f" HF_TOKEN: {'Set' if hf_token else 'Not set'}")
logger.info(f" Dataset repo: {dataset_repo}")
monitor = SmolLM3Monitor(
experiment_name="test_experiment",
enable_tracking=False, # Disable Trackio for testing
hf_token=hf_token,
dataset_repo=dataset_repo
)
logger.info(f"β
Monitor created successfully")
logger.info(f" Experiment name: {monitor.experiment_name}")
logger.info(f" Dataset repo: {monitor.dataset_repo}")
logger.info(f" HF client: {'Available' if monitor.hf_dataset_client else 'Not available'}")
return True
except Exception as e:
logger.error(f"β Failed to create monitor: {e}")
return False
def test_config_creation():
"""Test monitor creation from config"""
try:
from monitoring import create_monitor_from_config
# Create a simple config object
class TestConfig:
enable_tracking = True
experiment_name = "test_config_experiment"
trackio_url = None
trackio_token = None
log_artifacts = True
log_metrics = True
log_config = True
config = TestConfig()
logger.info(f"π§ Testing monitor creation from config...")
monitor = create_monitor_from_config(config)
logger.info(f"β
Monitor created from config successfully")
logger.info(f" Experiment name: {monitor.experiment_name}")
logger.info(f" Dataset repo: {monitor.dataset_repo}")
return True
except Exception as e:
logger.error(f"β Failed to create monitor from config: {e}")
return False
def test_metrics_logging():
"""Test metrics logging functionality"""
try:
from monitoring import SmolLM3Monitor
logger.info(f"π§ Testing metrics logging...")
monitor = SmolLM3Monitor(
experiment_name="test_metrics",
enable_tracking=False,
log_metrics=True
)
# Test metrics logging
test_metrics = {
'loss': 0.5,
'learning_rate': 1e-4,
'step': 100
}
monitor.log_metrics(test_metrics, step=100)
logger.info(f"β
Metrics logged successfully")
logger.info(f" Metrics history length: {len(monitor.metrics_history)}")
return True
except Exception as e:
logger.error(f"β Failed to log metrics: {e}")
return False
def test_configuration_logging():
"""Test configuration logging functionality"""
try:
from monitoring import SmolLM3Monitor
logger.info(f"π§ Testing configuration logging...")
monitor = SmolLM3Monitor(
experiment_name="test_config",
enable_tracking=False,
log_config=True
)
# Test configuration logging
test_config = {
'model_name': 'test-model',
'batch_size': 32,
'learning_rate': 1e-4,
'max_steps': 1000
}
monitor.log_configuration(test_config)
logger.info(f"β
Configuration logged successfully")
logger.info(f" Artifacts count: {len(monitor.artifacts)}")
return True
except Exception as e:
logger.error(f"β Failed to log configuration: {e}")
return False
def test_system_metrics():
"""Test system metrics logging"""
try:
from monitoring import SmolLM3Monitor
logger.info(f"π§ Testing system metrics logging...")
monitor = SmolLM3Monitor(
experiment_name="test_system",
enable_tracking=False,
log_metrics=True
)
# Test system metrics
monitor.log_system_metrics(step=1)
logger.info(f"β
System metrics logged successfully")
return True
except Exception as e:
logger.error(f"β Failed to log system metrics: {e}")
return False
def test_training_summary():
"""Test training summary logging"""
try:
from monitoring import SmolLM3Monitor
logger.info(f"π§ Testing training summary logging...")
monitor = SmolLM3Monitor(
experiment_name="test_summary",
enable_tracking=False,
log_artifacts=True
)
# Test training summary
test_summary = {
'final_loss': 0.1,
'total_steps': 1000,
'training_duration': 3600,
'model_path': '/output/model',
'status': 'completed'
}
monitor.log_training_summary(test_summary)
logger.info(f"β
Training summary logged successfully")
logger.info(f" Artifacts count: {len(monitor.artifacts)}")
return True
except Exception as e:
logger.error(f"β Failed to log training summary: {e}")
return False
def test_callback_creation():
"""Test callback creation for trainer integration"""
try:
from monitoring import SmolLM3Monitor
logger.info(f"π§ Testing callback creation...")
monitor = SmolLM3Monitor(
experiment_name="test_callback",
enable_tracking=False
)
# Test callback creation
callback = monitor.create_monitoring_callback()
logger.info(f"β
Callback created successfully")
logger.info(f" Callback type: {type(callback).__name__}")
return True
except Exception as e:
logger.error(f"β Failed to create callback: {e}")
return False
def main():
"""Run all monitoring integration tests"""
print("π§ͺ Testing Monitoring Integration with HF Datasets")
print("=" * 60)
tests = [
("Module Import", test_monitoring_import),
("Monitor Creation", test_monitor_creation),
("Config Creation", test_config_creation),
("Metrics Logging", test_metrics_logging),
("Configuration Logging", test_configuration_logging),
("System Metrics", test_system_metrics),
("Training Summary", test_training_summary),
("Callback Creation", test_callback_creation)
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"\nπ§ Running: {test_name}")
try:
if test_func():
print(f"β
{test_name}: PASSED")
passed += 1
else:
print(f"β {test_name}: FAILED")
except Exception as e:
print(f"β {test_name}: ERROR - {e}")
print(f"\nπ Test Results")
print("=" * 30)
print(f"Passed: {passed}/{total}")
print(f"Failed: {total - passed}/{total}")
if passed == total:
print("π All tests passed! Monitoring integration is working correctly.")
else:
print("β οΈ Some tests failed. Check the logs above for details.")
print(f"\nπ Environment Check:")
print(f" HF_TOKEN: {'Set' if os.environ.get('HF_TOKEN') else 'Not set'}")
print(f" TRACKIO_DATASET_REPO: {os.environ.get('TRACKIO_DATASET_REPO', 'tonic/trackio-experiments')}")
if passed == total:
print(f"\nβ
Monitoring integration is ready for use!")
print(f" Next step: Run a training experiment to verify full functionality")
else:
print(f"\nβ οΈ Please fix the failed tests before using monitoring")
if __name__ == "__main__":
main() |