File size: 6,960 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 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 |
#!/usr/bin/env python3
"""
๊ฐ๋จํ TTRLVR + AZR ํตํฉ ํ
์คํธ
๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ์ปดํฌ๋ํธ ํ
์คํธ:
1. Task Generator ํ
์คํธ
2. Data Converter ํ
์คํธ
3. Pipeline ๊ธฐ๋ณธ ์คํ ํ
์คํธ
"""
import os
import sys
import tempfile
import shutil
from pathlib import Path
# ๊ฒฝ๋ก ์ค์
sys.path.append('/home/ubuntu/RLVR/TestTime-RLVR-v2')
def test_task_generator():
"""Task Generator ๊ธฐ๋ณธ ํ
์คํธ"""
print("๐งช Testing Task Generator...")
try:
from absolute_zero_reasoner.testtime.config import TestTimeConfig
from absolute_zero_reasoner.testtime.logger import TestTimeLogger
from absolute_zero_reasoner.testtime.task_generator import TestTimeTaskGenerator
config = TestTimeConfig()
config.model_name = "Qwen/Qwen2.5-7B"
logger = TestTimeLogger()
task_generator = TestTimeTaskGenerator(config, logger)
# ํ
์คํธ IPO ํธ๋ฆฌํ
test_ipo_triples = [{
'id': 'test_triple_0',
'input': '[1, 2, 3]',
'actual_output': '[2, 4, 6]',
'program': 'def test_func(lst):\n return [x * 2 for x in lst]',
'full_input_str': 'test_func([1, 2, 3])',
'source_program_id': 'program_0',
'ipo_index': 0
}]
# Task ์์ฑ
tasks = task_generator.generate_tasks(test_ipo_triples, "TestProblem", 1)
# ๊ฒ์ฆ
assert 'induction' in tasks
assert 'deduction' in tasks
assert 'abduction' in tasks
total_tasks = sum(len(task_list) for task_list in tasks.values())
print(f"โ
Task Generator: Generated {total_tasks} tasks")
# AZR ๋ฉํ๋ฐ์ดํฐ ํ์ธ
for task_type, task_list in tasks.items():
if task_list:
task = task_list[0]
assert 'uid' in task
assert 'ipo_group_id' in task
assert 'basic_accuracy' in task
print(f"โ
Task Generator: {task_type} has AZR metadata")
return True
except Exception as e:
print(f"โ Task Generator test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_data_converter():
"""Data Converter ๊ธฐ๋ณธ ํ
์คํธ"""
print("\n๐งช Testing Data Converter...")
try:
from absolute_zero_reasoner.testtime.complete_pipeline import CompleteTestTimePipeline
from absolute_zero_reasoner.testtime.config import TestTimeConfig
from absolute_zero_reasoner.testtime.logger import TestTimeLogger
config = TestTimeConfig()
logger = TestTimeLogger()
pipeline = CompleteTestTimePipeline(config, logger)
# Mock task ๋ฐ์ดํฐ
mock_tasks = {
'induction': [{
'task_id': 'induction_0',
'task_type': 'induction',
'prompt': 'Test prompt',
'uid': 'TestProblem_round_1_induction_0',
'ipo_group_id': 'TestProblem_program_0_ipo_0',
'source_program_id': 'program_0',
'ipo_index': 0,
'ipo_triple': {
'input': '[1, 2, 3]',
'output': '[2, 4, 6]',
'program': 'def test_func(lst):\n return [x * 2 for x in lst]'
},
'ground_truth': 'def test_func(lst):\n return [x * 2 for x in lst]',
'extra_info': {'metric': 'code_f'},
'basic_accuracy': 1.0,
'original_problem_id': 'TestProblem',
'round': 1
}]
}
# ์์ ๋๋ ํ ๋ฆฌ
with tempfile.TemporaryDirectory() as temp_dir:
# ๋ฐ์ดํฐ ๋ณํ ํ
์คํธ
saved_files = pipeline._save_azr_training_data(
mock_tasks, "TestProblem", 1, temp_dir
)
# ํ์ผ ์์ฑ ํ์ธ
assert 'induction' in saved_files
assert os.path.exists(saved_files['induction'])
# Parquet ํ์ผ ์ฝ๊ธฐ ํ์ธ
import pandas as pd
df = pd.read_parquet(saved_files['induction'])
assert len(df) == 1
assert 'prompt' in df.columns
assert 'uid' in df.columns
assert 'ipo_group_id' in df.columns
print("โ
Data Converter: Parquet file created and validated")
return True
except Exception as e:
print(f"โ Data Converter test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_iterative_trainer_basic():
"""Iterative Trainer ๊ธฐ๋ณธ ์ค์ ํ
์คํธ"""
print("\n๐งช Testing Iterative Trainer Setup...")
try:
from utils.iterative_trainer import IterativeTrainer
from absolute_zero_reasoner.testtime.config import TestTimeConfig, BenchmarkConfig
from absolute_zero_reasoner.testtime.logger import TestTimeLogger
config = TestTimeConfig()
logger = TestTimeLogger()
trainer = IterativeTrainer(config, logger)
# ๊ธฐ๋ณธ ์ค์ ํ์ธ
assert trainer.current_model_path == "Qwen/Qwen2.5-7B"
assert trainer.checkpoint_dir == "/data/RLVR/checkpoints/ttrlvr_azr"
print("โ
Iterative Trainer: Basic setup successful")
return True
except Exception as e:
print(f"โ Iterative Trainer test failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""๋ฉ์ธ ํ
์คํธ ์คํ"""
print("๐ TTRLVR + AZR Simple Integration Test")
print("=" * 60)
tests = [
("Task Generator", test_task_generator),
("Data Converter", test_data_converter),
("Iterative Trainer", test_iterative_trainer_basic)
]
results = []
for test_name, test_func in tests:
try:
result = test_func()
results.append((test_name, result))
except Exception as e:
print(f"๐ฅ {test_name} crashed: {e}")
results.append((test_name, False))
# ๊ฒฐ๊ณผ ์์ฝ
print("\n" + "=" * 60)
print("๐ Test Results:")
passed = 0
total = len(results)
for test_name, result in results:
status = "โ
PASS" if result else "โ FAIL"
print(f" {status} {test_name}")
if result:
passed += 1
print(f"\nOverall: {passed}/{total} tests passed ({passed/total*100:.1f}%)")
if passed == total:
print("\n๐ All simple integration tests passed!")
return 0
else:
print(f"\nโ ๏ธ {total-passed} tests failed")
return 1
if __name__ == '__main__':
exit_code = main()
sys.exit(exit_code) |