File size: 5,015 Bytes
5e4510c |
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 |
#!/usr/bin/env python3
"""
Test script to verify the complete AlphaEvolve setup works
"""
import sys
import json
from pathlib import Path
def test_evaluator():
"""Test the evaluator with a simple program"""
print("π§ͺ Testing evaluator...")
# Simple test program
test_program = '''
def optimize_attention():
return {
'tile_size_m': 32,
'tile_size_n': 64,
'vectorization': 'none',
'unroll_factor': 2,
'loop_interchange': False,
'fusion_strategy': 'none',
'use_shared_memory': False,
'optimize_for_latency': True,
'enable_blocking': False,
'enable_recomputation': False,
'optimization_strategy': 'alphaevolve_test',
'target_speedup': 1.32,
}
'''
try:
# Import the evaluator
sys.path.insert(0, '.')
from evaluator import evaluate_program
print("β
Evaluator imported successfully")
# Test evaluation
result = evaluate_program(test_program)
if 'error' in result:
print(f"π Evaluation result: error={result['error']:.3f}")
if 'speedup' in result:
print(f"π Speedup: {result['speedup']:.3f}x")
if 'mlir_source' in result:
print(f"π MLIR source: {result['mlir_source']}")
if result['error'] < 1000:
print("β
Evaluator works!")
return True
else:
print(f"β Evaluator failed: {result}")
return False
else:
print(f"β Invalid result format: {result}")
return False
except Exception as e:
print(f"β Evaluator test failed: {e}")
return False
def test_initial_program():
"""Test the initial program generates parameters"""
print("\nπ§ͺ Testing initial program...")
try:
sys.path.insert(0, '.')
from initial_program import optimize_attention
params = optimize_attention()
print("β
Initial program imported successfully")
print(f"π Generated parameters: {list(params.keys())}")
# Check required parameters
required = ['tile_size_m', 'tile_size_n', 'unroll_factor']
for param in required:
if param in params:
print(f"β
{param}: {params[param]}")
else:
print(f"β Missing parameter: {param}")
return False
return True
except Exception as e:
print(f"β Initial program test failed: {e}")
return False
def test_mlir_file():
"""Test that the MLIR file exists and is readable"""
print("\nπ§ͺ Testing MLIR file...")
mlir_file = Path("./mlir/self_attn_with_consts_linalg_dialect.mlir")
if mlir_file.exists():
print(f"β
MLIR file exists: {mlir_file}")
try:
with open(mlir_file, 'r') as f:
content = f.read()
print(f"β
MLIR file readable: {len(content)} characters")
# Check for fixed tensor.expand_shape syntax
if 'output_shape' in content:
print("β
tensor.expand_shape syntax is fixed")
else:
print("β οΈ tensor.expand_shape may need fixing")
return True
except Exception as e:
print(f"β Cannot read MLIR file: {e}")
return False
else:
print(f"β MLIR file not found: {mlir_file}")
return False
def main():
"""Run all tests"""
print("π Testing Complete AlphaEvolve Setup\n")
tests = [
("MLIR File", test_mlir_file),
("Initial Program", test_initial_program),
("Evaluator", test_evaluator),
]
results = []
for test_name, test_func in tests:
success = test_func()
results.append((test_name, success))
# Summary
print(f"\n{'='*50}")
print("TEST SUMMARY")
print('='*50)
passed = 0
for test_name, success in results:
status = "β
PASS" if success else "β FAIL"
print(f"{status:8} {test_name}")
if success:
passed += 1
print(f"\nResults: {passed}/{len(results)} tests passed")
if passed == len(results):
print("\nπ All tests passed! Ready to run AlphaEvolve!")
print("\nπ Run evolution with:")
print(" python ../../openevolve-run.py initial_program.py evaluator.py --config config.yaml --iterations 10")
print("\nπ― Target: Achieve 32% speedup (1.32x) like AlphaEvolve paper")
else:
print(f"\nβ οΈ {len(results) - passed} test(s) failed. Fix issues before running evolution.")
return passed == len(results)
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1) |