File size: 5,834 Bytes
39db0ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbb337d
39db0ca
 
 
 
 
 
dbb337d
 
 
 
 
39db0ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbb337d
 
 
 
 
 
 
 
 
fbc0479
 
 
 
 
 
 
 
 
 
39db0ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test script to verify Trackio TRL compatibility fix
Tests that our trackio module provides the interface expected by TRL library
"""

import sys
import os
import logging

# Add src to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

def test_trackio_interface():
    """Test that trackio module provides the expected interface"""
    print("πŸ” Testing Trackio TRL Interface")
    
    try:
        # Test importing trackio
        import trackio
        print("βœ… Successfully imported trackio module")
        
        # Test that required functions exist
        required_functions = ['init', 'log', 'finish']
        for func_name in required_functions:
            if hasattr(trackio, func_name):
                print(f"βœ… Found required function: {func_name}")
            else:
                print(f"❌ Missing required function: {func_name}")
                return False
        
        # Test initialization with arguments
        experiment_id = trackio.init(
            project_name="test_project",
            experiment_name="test_experiment",
            trackio_url="https://test.hf.space",
            dataset_repo="test/trackio-experiments"
        )
        print(f"βœ… Trackio initialization with args successful: {experiment_id}")
        
        # Test initialization without arguments (TRL compatibility)
        experiment_id2 = trackio.init()
        print(f"βœ… Trackio initialization without args successful: {experiment_id2}")
        
        # Test logging
        metrics = {'loss': 0.5, 'learning_rate': 1e-4}
        trackio.log(metrics, step=1)
        print("βœ… Trackio logging successful")
        
        # Test finishing
        trackio.finish()
        print("βœ… Trackio finish successful")
        
        return True
        
    except Exception as e:
        print(f"❌ Trackio interface test failed: {e}")
        return False

def test_trl_compatibility():
    """Test that our trackio module is compatible with TRL expectations"""
    print("\nπŸ” Testing TRL Compatibility")
    
    try:
        # Simulate what TRL would do
        import trackio
        
        # TRL expects these functions to be available
        assert hasattr(trackio, 'init'), "trackio.init not found"
        assert hasattr(trackio, 'log'), "trackio.log not found"
        assert hasattr(trackio, 'finish'), "trackio.finish not found"
        
        # Test function signatures
        import inspect
        
        # Check init signature
        init_sig = inspect.signature(trackio.init)
        print(f"βœ… init signature: {init_sig}")
        
        # Test that init can be called without arguments (TRL compatibility)
        try:
            # This simulates what TRL might do
            trackio.init()
            print("βœ… init() can be called without arguments")
        except Exception as e:
            print(f"❌ init() failed when called without arguments: {e}")
            return False
        
        # Test that config attribute is available (TRL compatibility)
        try:
            config = trackio.config
            print(f"βœ… trackio.config is available: {type(config)}")
            print(f"βœ… config.project_name: {config.project_name}")
            print(f"βœ… config.experiment_name: {config.experiment_name}")
        except Exception as e:
            print(f"❌ trackio.config failed: {e}")
            return False

        # Check log signature
        log_sig = inspect.signature(trackio.log)
        print(f"βœ… log signature: {log_sig}")
        
        # Check finish signature
        finish_sig = inspect.signature(trackio.finish)
        print(f"βœ… finish signature: {finish_sig}")
        
        print("βœ… TRL compatibility test passed")
        return True
        
    except Exception as e:
        print(f"❌ TRL compatibility test failed: {e}")
        return False

def test_monitoring_integration():
    """Test that our trackio module integrates with our monitoring system"""
    print("\nπŸ” Testing Monitoring Integration")
    
    try:
        import trackio
        
        # Test that we can get the monitor
        monitor = trackio.get_monitor()
        if monitor is not None:
            print("βœ… Monitor integration working")
        else:
            print("⚠️ Monitor not available (this is normal if not initialized)")
        
        # Test availability check
        is_avail = trackio.is_available()
        print(f"βœ… Trackio availability check: {is_avail}")
        
        return True
        
    except Exception as e:
        print(f"❌ Monitoring integration test failed: {e}")
        return False

def main():
    """Run all tests"""
    print("πŸš€ Testing Trackio TRL Fix")
    print("=" * 50)
    
    tests = [
        test_trackio_interface,
        test_trl_compatibility,
        test_monitoring_integration
    ]
    
    passed = 0
    total = len(tests)
    
    for test in tests:
        try:
            if test():
                passed += 1
        except Exception as e:
            print(f"❌ Test {test.__name__} failed with exception: {e}")
    
    print("\n" + "=" * 50)
    print(f"Test Results: {passed}/{total} tests passed")
    
    if passed == total:
        print("βœ… All tests passed! Trackio TRL fix is working correctly.")
        print("\nThe trackio module now provides the interface expected by TRL library:")
        print("- init(): Initialize experiment")
        print("- log(): Log metrics")
        print("- finish(): Finish experiment")
        print("\nThis should resolve the 'module trackio has no attribute init' error.")
    else:
        print("❌ Some tests failed. Please check the implementation.")
        return 1
    
    return 0

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