File size: 4,213 Bytes
24c2665
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
AZR Integration Test Script

AZR REINFORCE++ ν•™μŠ΅ 톡합이 μ œλŒ€λ‘œ μž‘λ™ν•˜λŠ”μ§€ ν…ŒμŠ€νŠΈ
"""

import os
import sys
import pandas as pd
import torch

# 경둜 μ„€μ •
sys.path.append('/home/ubuntu/RLVR/TestTime-RLVR-v2')
sys.path.append('/home/ubuntu/RLVR/TestTime-RLVR-v2/test')

from utils.azr_trainer_integration import AZRTrainerIntegration
from absolute_zero_reasoner.testtime.logger import TestTimeLogger


def test_data_loading():
    """Parquet 데이터 λ‘œλ”© ν…ŒμŠ€νŠΈ"""
    print("=== Testing Data Loading ===")
    
    # μ‹€μ œ 데이터 경둜
    data_path = "/home/ubuntu/RLVR/TestTime-RLVR-v2/tmp/batch_results/ttrlvr_azr_20250729_141828/humaneval/HumanEval_1/round_5/azr_training_data"
    
    # 각 파일 확인
    for task_type in ['induction', 'deduction', 'abduction']:
        file_path = os.path.join(data_path, f"{task_type}.parquet")
        if os.path.exists(file_path):
            df = pd.read_parquet(file_path)
            print(f"βœ… {task_type}: {len(df)} rows")
            
            # 첫 번째 ν–‰μ˜ reward 확인
            if len(df) > 0:
                first_reward = df.iloc[0]['basic_accuracy']
                print(f"   First row reward: {first_reward}")
        else:
            print(f"❌ {task_type}: File not found")
    
    print()


def test_azr_trainer_init():
    """AZR Trainer μ΄ˆκΈ°ν™” ν…ŒμŠ€νŠΈ"""
    print("=== Testing AZR Trainer Initialization ===")
    
    try:
        # 더미 ν† ν¬λ‚˜μ΄μ €
        from transformers import AutoTokenizer
        tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B")
        
        # 둜거
        logger = TestTimeLogger(log_dir="/tmp/test_logs")
        
        # AZR Trainer μ΄ˆκΈ°ν™”
        trainer = AZRTrainerIntegration(
            model_path="Qwen/Qwen2.5-7B",
            tokenizer=tokenizer,
            logger=logger,
            gpu_id=0,
            num_cpus=8
        )
        
        print("βœ… AZR Trainer initialized successfully")
        
        # μ„€μ • 생성 ν…ŒμŠ€νŠΈ
        config = trainer.create_azr_config(round_num=1, batch_size=24)
        print(f"βœ… Config created: {config.trainer.experiment_name}")
        
        # 정리
        trainer.cleanup()
        print("βœ… Cleanup completed")
        
    except Exception as e:
        print(f"❌ Error: {e}")
        import traceback
        traceback.print_exc()
    
    print()


def test_data_conversion():
    """데이터 λ³€ν™˜ ν…ŒμŠ€νŠΈ"""
    print("=== Testing Data Conversion ===")
    
    try:
        from transformers import AutoTokenizer
        tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B")
        logger = TestTimeLogger(log_dir="/tmp/test_logs")
        
        trainer = AZRTrainerIntegration(
            model_path="Qwen/Qwen2.5-7B",
            tokenizer=tokenizer,
            logger=logger,
            gpu_id=0,
            num_cpus=8
        )
        
        # 데이터 λ‘œλ“œ 및 λ³€ν™˜
        data_path = "/home/ubuntu/RLVR/TestTime-RLVR-v2/tmp/batch_results/ttrlvr_azr_20250729_141828/humaneval/HumanEval_1/round_5/azr_training_data"
        data_protos, stats = trainer.load_and_prepare_data(data_path)
        
        print(f"βœ… Loaded {len(data_protos)} data protos")
        print(f"   Stats: {dict(stats)}")
        
        # 배치 생성 ν…ŒμŠ€νŠΈ
        if data_protos:
            batches = trainer.prepare_batches(data_protos, batch_size=24)
            print(f"βœ… Created {len(batches)} batches")
            
            if batches:
                first_batch_size = len(batches[0])
                print(f"   First batch size: {first_batch_size}")
        
        trainer.cleanup()
        
    except Exception as e:
        print(f"❌ Error: {e}")
        import traceback
        traceback.print_exc()
    
    print()


def main():
    """메인 ν…ŒμŠ€νŠΈ ν•¨μˆ˜"""
    print("πŸ§ͺ Starting AZR Integration Tests")
    print("=" * 60)
    
    # ν™˜κ²½ μ„€μ •
    os.environ['CUDA_VISIBLE_DEVICES'] = '4'
    
    # ν…ŒμŠ€νŠΈ μ‹€ν–‰
    test_data_loading()
    test_azr_trainer_init()
    test_data_conversion()
    
    print("βœ… Tests completed!")


if __name__ == '__main__':
    main()