Skip to content

Commit 9a01774

Browse files
committed
remove l3 tests
1 parent b4eb88c commit 9a01774

3 files changed

Lines changed: 55 additions & 91 deletions

File tree

src/attention_predictor.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl Model {
507507
.unwrap_or_default();
508508

509509
match per_epoch_scores(self, device) {
510-
Ok((score_l2, score_l3, score_qa, score_json)) => {
510+
Ok((score_l2, score_qa, score_json)) => {
511511
let entry = serde_json::json!({
512512
"Epoch": epoch,
513513
"Model_ID": self.model_id,
@@ -524,7 +524,6 @@ impl Model {
524524
"State_of_the_code": git_hash,
525525
"Time_to_train": time_str,
526526
"Self_Test_Score_L2": score_l2,
527-
"Self_Test_Score_L3": score_l3,
528527
"QA_Test_Score": score_qa,
529528
"JSON_Test_Score": score_json,
530529
"Date": date,
@@ -538,8 +537,8 @@ impl Model {
538537
let _ = writeln!(file, "{}", serde_json::to_string(&entry).unwrap());
539538
}
540539
println!(
541-
"Epoch {} scores: L2={:.3} L3={:.3} QA={:.3} JSON={:.3} LR={:.2e}",
542-
epoch, score_l2, score_l3, score_qa, score_json, last_lr
540+
"Epoch {} scores: L2={:.3} QA={:.3} JSON={:.3} LR={:.2e}",
541+
epoch, score_l2, score_qa, score_json, last_lr
543542
);
544543
}
545544
Err(e) => eprintln!("Epoch {} test failed: {}", epoch, e),

src/main.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
186186
model.simple_train(tokens.clone(), &device, lr)?;
187187

188188
match per_epoch_scores(&model, &device) {
189-
Ok((l2, l3, qa, json)) => {
189+
Ok((l2, qa, json)) => {
190190
let entry = serde_json::json!({
191191
"Model_ID": model.model_id,
192192
"LR": lr,
193193
"Self_Test_Score_L2": l2,
194-
"Self_Test_Score_L3": l3,
195194
"QA_Test_Score": qa,
196195
"JSON_Test_Score": json,
197196
});
@@ -203,10 +202,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
203202
use std::io::Write as W;
204203
let _ = writeln!(f, "{}", serde_json::to_string(&entry).unwrap());
205204
}
206-
println!(
207-
"sweep result: LR={:.2e} L2={:.3} L3={:.3} QA={:.3} JSON={:.3}",
208-
lr, l2, l3, qa, json
209-
);
205+
println!("sweep result: LR={:.2e} L2={:.3} QA={:.3} JSON={:.3}", lr, l2, qa, json);
210206
}
211207
Err(e) => eprintln!("sweep score failed for LR={:.2e}: {}", lr, e),
212208
}
@@ -236,13 +232,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
236232
model.simple_train(subset, &device, lr)?;
237233

238234
match per_epoch_scores(&model, &device) {
239-
Ok((l2, l3, qa, json)) => {
235+
Ok((l2, qa, json)) => {
240236
let entry = serde_json::json!({
241237
"Model_ID": model.model_id,
242238
"Corpus_Rate": rate,
243239
"Num_Tokens": n,
244240
"Self_Test_Score_L2": l2,
245-
"Self_Test_Score_L3": l3,
246241
"QA_Test_Score": qa,
247242
"JSON_Test_Score": json,
248243
});
@@ -255,13 +250,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
255250
let _ = writeln!(f, "{}", serde_json::to_string(&entry).unwrap());
256251
}
257252
println!(
258-
"sweep result: rate={:.0}% tokens={} L2={:.3} L3={:.3} QA={:.3} JSON={:.3}",
259-
rate * 100.0,
260-
n,
261-
l2,
262-
l3,
263-
qa,
264-
json
253+
"sweep result: rate={:.0}% tokens={} L2={:.3} QA={:.3} JSON={:.3}",
254+
rate * 100.0, n, l2, qa, json
265255
);
266256
}
267257
Err(e) => eprintln!("sweep score failed for rate={:.0}%: {}", rate * 100.0, e),

src/model_tests.rs

Lines changed: 47 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const RESULT_COLS: &[&str] = &[
2222
"State_of_the_code",
2323
"Time_to_train",
2424
"Self_Test_Score_L2",
25-
"Self_Test_Score_L3",
2625
"QA_Test_Score",
2726
"JSON_Test_Score",
2827
"Date",
@@ -44,7 +43,6 @@ const EPOCH_COLS: &[&str] = &[
4443
"State_of_the_code",
4544
"Time_to_train",
4645
"Self_Test_Score_L2",
47-
"Self_Test_Score_L3",
4846
"QA_Test_Score",
4947
"JSON_Test_Score",
5048
"Date",
@@ -97,8 +95,8 @@ pub fn print_results() -> Result<(), Box<dyn std::error::Error>> {
9795
}
9896

9997
pub fn self_test() -> Result<(), Box<dyn std::error::Error>> {
100-
let (l2, l3) = self_test_scores()?;
101-
println!("Self test scores: L2={}, L3={}", l2, l3);
98+
let l2 = self_test_scores()?;
99+
println!("Self test score: L2={}", l2);
102100
Ok(())
103101
}
104102

@@ -115,7 +113,7 @@ pub fn json_test() -> Result<(), Box<dyn std::error::Error>> {
115113
}
116114

117115
pub fn test_all() -> Result<(), Box<dyn std::error::Error>> {
118-
let (score_l2, score_l3) = self_test_scores()?;
116+
let score_l2 = self_test_scores()?;
119117
let score_qa = qa_test_score()?;
120118
let score_json = json_test_score()?;
121119

@@ -132,7 +130,6 @@ pub fn test_all() -> Result<(), Box<dyn std::error::Error>> {
132130
let entry = serde_json::json!({
133131
"Model_ID": model_id,
134132
"Self_Test_Score_L2": score_l2,
135-
"Self_Test_Score_L3": score_l3,
136133
"QA_Test_Score": score_qa,
137134
"JSON_Test_Score": score_json,
138135
"Date": date,
@@ -146,11 +143,8 @@ pub fn test_all() -> Result<(), Box<dyn std::error::Error>> {
146143
writeln!(file, "{}", serde_json::to_string(&entry).unwrap())?;
147144
}
148145

149-
println!("Self_Test_Score_L2\tSelf_Test_Score_L3\tQA_Test_Score\tJSON_Test_Score\tDate");
150-
println!(
151-
"{}\t{}\t{}\t{}\t{}",
152-
score_l2, score_l3, score_qa, score_json, date
153-
);
146+
println!("Self_Test_Score_L2\tQA_Test_Score\tJSON_Test_Score\tDate");
147+
println!("{}\t{}\t{}\t{}", score_l2, score_qa, score_json, date);
154148

155149
Ok(())
156150
}
@@ -159,11 +153,11 @@ pub fn test_all() -> Result<(), Box<dyn std::error::Error>> {
159153
pub fn per_epoch_scores<M: PredictGreedy>(
160154
model: &M,
161155
device: &candle_core::Device,
162-
) -> Result<(f32, f32, f32, f32), Box<dyn std::error::Error>> {
163-
let (l2, l3) = compute_self_test_scores(model, device)?;
156+
) -> Result<(f32, f32, f32), Box<dyn std::error::Error>> {
157+
let l2 = compute_self_test_scores(model, device)?;
164158
let qa = compute_qa_test_score(model, device)?;
165159
let json = compute_json_test_score(model, device)?;
166-
Ok((l2, l3, qa, json))
160+
Ok((l2, qa, json))
167161
}
168162

169163
/// Print the header for per_epoch_stats.log (call once before training).
@@ -194,73 +188,54 @@ fn first_n_words_contain(output: &str, expected: &str, n: usize) -> bool {
194188
fn compute_self_test_scores<M: PredictGreedy>(
195189
model: &M,
196190
device: &candle_core::Device,
197-
) -> Result<(f32, f32), Box<dyn std::error::Error>> {
198-
let level_file_paths = vec![
199-
"smoll-generated-corpus/level_2/corpus.txt",
200-
"smoll-generated-corpus/level_3/corpus.txt",
201-
];
202-
203-
let mut scores: Vec<f32> = Vec::new();
204-
205-
for level_file_path in level_file_paths.iter() {
206-
let mut file = fs::File::open(level_file_path)?;
207-
let mut content: String = String::new();
208-
file.read_to_string(&mut content)?;
209-
210-
let mut match_count = 0;
211-
let mut total = 0;
212-
213-
for line in content.split("\n").filter(|l| !l.trim().is_empty()).take(20) {
214-
let words: Vec<&str> = line.split(" ").take(6).collect();
215-
let expected_completion = line.split(" ").skip(6);
216-
let original_input = words.join(" ");
217-
let mut input = original_input.clone() + " ";
218-
219-
let mut buf = String::new();
220-
loop {
221-
let pred = model.predict_next_token_greedy(input.as_str(), device)?;
222-
input = input + pred.as_str();
223-
224-
if buf.len() > 50 || pred == "." {
225-
buf.push_str(pred.as_str());
226-
break;
227-
}
228-
229-
if pred == STOP_TOKEN {
230-
break;
231-
}
191+
) -> Result<f32, Box<dyn std::error::Error>> {
192+
let level_file_path = "smoll-generated-corpus/level_2/corpus.txt";
193+
let mut file = fs::File::open(level_file_path)?;
194+
let mut content: String = String::new();
195+
file.read_to_string(&mut content)?;
196+
197+
let mut match_count = 0;
198+
let mut total = 0;
199+
200+
for line in content.split("\n").filter(|l| !l.trim().is_empty()).take(20) {
201+
let words: Vec<&str> = line.split(" ").take(6).collect();
202+
let expected_completion = line.split(" ").skip(6);
203+
let original_input = words.join(" ");
204+
let mut input = original_input.clone() + " ";
232205

206+
let mut buf = String::new();
207+
loop {
208+
let pred = model.predict_next_token_greedy(input.as_str(), device)?;
209+
input = input + pred.as_str();
210+
211+
if buf.len() > 50 || pred == "." {
233212
buf.push_str(pred.as_str());
213+
break;
234214
}
235215

236-
let expected_completion: Vec<&str> = expected_completion.collect();
237-
let expected_completion = expected_completion.join(" ").replace("<stop>", "");
238-
239-
if first_n_words_contain(&buf, &expected_completion, 3) {
240-
match_count += 1;
241-
println!(
242-
"'{}' |> '{}' ~ '{}' - match",
243-
original_input, buf, expected_completion
244-
);
245-
} else {
246-
println!(
247-
"'{}' |> '{}' ~ '{}' - no match",
248-
original_input, buf, expected_completion
249-
);
216+
if pred == STOP_TOKEN {
217+
break;
250218
}
251219

252-
total += 1;
220+
buf.push_str(pred.as_str());
221+
}
222+
223+
let expected_completion: Vec<&str> = expected_completion.collect();
224+
let expected_completion = expected_completion.join(" ").replace("<stop>", "");
225+
226+
if first_n_words_contain(&buf, &expected_completion, 3) {
227+
match_count += 1;
228+
println!("'{}' |> '{}' ~ '{}' - match", original_input, buf, expected_completion);
229+
} else {
230+
println!("'{}' |> '{}' ~ '{}' - no match", original_input, buf, expected_completion);
253231
}
254232

255-
let success_rate = match_count as f32 / total as f32;
256-
println!(
257-
"corpus {} - matches - {}, total - {}, success rate - {}",
258-
level_file_path, match_count, total, success_rate
259-
);
260-
scores.push(success_rate);
233+
total += 1;
261234
}
262235

263-
Ok((scores[0], scores[1]))
236+
let success_rate = match_count as f32 / total as f32;
237+
println!("corpus {} - matches - {}, total - {}, success rate - {}", level_file_path, match_count, total, success_rate);
238+
Ok(success_rate)
264239
}
265240

266241
fn compute_qa_test_score<M: PredictGreedy>(
@@ -322,7 +297,7 @@ fn compute_qa_test_score<M: PredictGreedy>(
322297
Ok(success_rate)
323298
}
324299

325-
fn self_test_scores() -> Result<(f32, f32), Box<dyn std::error::Error>> {
300+
fn self_test_scores() -> Result<f32, Box<dyn std::error::Error>> {
326301
let device = get_device()?;
327302
println!("Loading test model");
328303
let model = Model::load_from_path("data/model", &device)?;

0 commit comments

Comments
 (0)