Repository navigation
Expand file tree
/
Copy pathtest_coherence_both.jl
More file actions
160 lines (130 loc) · 4.32 KB
/
Copy pathtest_coherence_both.jl
File metadata and controls
160 lines (130 loc) · 4.32 KB
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
#!/usr/bin/env julia
"""
Test coherence of latest CPU and GPU checkpoints
"""
using Pkg
Pkg.activate(".")
include("src/Sovwave.jl")
using .Sovwave
using .Sovwave.WaveML
using Printf
function find_latest_checkpoint(dir::String)
if !isdir(dir)
return nothing
end
files = readdir(dir, join=true)
mkv_files = filter(f -> endswith(f, ".mkv") && !contains(f, ".mp4"), files)
if isempty(mkv_files)
return nothing
end
return sort(mkv_files, by=mtime, rev=true)[1]
end
function test_checkpoint_coherence(ckpt_path::String, label::String)
println("\n" * "="^90)
println(" 🧪 TESTING $label CHECKPOINT")
println("="^90)
println("\n📦 Loading: $ckpt_path")
try
# Load model
model = load_model(ckpt_path)
println("✅ Model loaded successfully")
# Create tokenizer
tokenizer = gpt2_tokenizer(carrier_frequency=432.0, beta_s=1.618033988749895)
# Test prompts
test_prompts = [
"Two plus two",
"The sky is",
"Hello world",
"Once upon a time",
"Water flows",
"Good morning",
"Five times three",
"The sun shines"
]
println("\n🧪 COHERENCE TESTING")
println("-"^90)
coherent = 0
total = length(test_prompts)
for prompt in test_prompts
try
output = generate_text(
model,
tokenizer,
prompt;
max_new_tokens=5,
temperature=0.7
)
result = check_text_coherence(output, prompt)
status = result.is_coherent ? "✅" : "❌"
if result.is_coherent
coherent += 1
end
println(" $status \"$prompt\" → \"$output\" ($(round(result.score*100, digits=1))%)")
catch e
println(" ❌ \"$prompt\" → ERROR: $e")
end
end
rate = (coherent / total) * 100
println("\n" * "="^90)
@printf(" 📊 %s COHERENCE: %d/%d (%.1f%%)\n", label, coherent, total, rate)
println("="^90)
if rate >= 70
println(" ✅ EXCELLENT: Strong coherence")
elseif rate >= 50
println(" ⚠️ MODERATE: Some coherence present")
else
println(" ❌ POOR: Needs more training")
end
return (coherent, total, rate)
catch e
println("❌ Failed to load/test checkpoint: $e")
return (0, 0, 0.0)
end
end
function main()
println("="^90)
println(" 🔬 DUAL CHECKPOINT COHERENCE COMPARISON")
println("="^90)
# Find CPU checkpoint
cpu_ckpt = find_latest_checkpoint("checkpoints_sovwave_hf")
if cpu_ckpt === nothing
println("\n❌ No CPU checkpoint found")
cpu_results = (0, 0, 0.0)
else
cpu_results = test_checkpoint_coherence(cpu_ckpt, "CPU")
end
# Find GPU checkpoint
gpu_ckpt = find_latest_checkpoint("checkpoints_sovwave_hf_GPU")
if gpu_ckpt === nothing
println("\n❌ No GPU checkpoint found")
gpu_results = (0, 0, 0.0)
else
gpu_results = test_checkpoint_coherence(gpu_ckpt, "GPU")
end
# Comparison summary
println("\n" * "="^90)
println(" 📊 COMPARISON SUMMARY")
println("="^90)
if cpu_ckpt !== nothing
@printf(" CPU: %d/8 (%.1f%%) - %s\n", cpu_results[1], cpu_results[3], basename(cpu_ckpt))
else
println(" CPU: No checkpoint available")
end
if gpu_ckpt !== nothing
@printf(" GPU: %d/8 (%.1f%%) - %s\n", gpu_results[1], gpu_results[3], basename(gpu_ckpt))
else
println(" GPU: No checkpoint available")
end
if cpu_ckpt !== nothing && gpu_ckpt !== nothing
diff = cpu_results[3] - gpu_results[3]
if abs(diff) < 5.0
println("\n ⚖️ TIED: Both performing similarly")
elseif diff > 0
@printf("\n 🏆 CPU WINS by %.1f%%\n", diff)
else
@printf("\n 🏆 GPU WINS by %.1f%%\n", abs(diff))
end
end
println("="^90)
end
main()