evaluate: use rayon par_sort_by for parallel LLM comparisons
Merge sort parallelizes naturally — multiple LLM comparison calls happen concurrently. Safe because merge sort terminates correctly even with non-deterministic comparators (unlike quicksort). Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
e12dea503b
commit
433d36aea8
1 changed files with 10 additions and 8 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
use crate::store;
|
use crate::store;
|
||||||
use crate::store::StoreView;
|
use crate::store::StoreView;
|
||||||
use crate::agents::llm;
|
use crate::agents::llm;
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
pub fn cmd_consolidate_batch(count: usize, auto: bool, agent: Option<String>) -> Result<(), String> {
|
pub fn cmd_consolidate_batch(count: usize, auto: bool, agent: Option<String>) -> Result<(), String> {
|
||||||
let store = store::Store::load()?;
|
let store = store::Store::load()?;
|
||||||
|
|
@ -178,17 +179,18 @@ pub fn cmd_evaluate_agents(samples_per_type: usize, model: &str) -> Result<(), S
|
||||||
all_samples.len() * (all_samples.len() as f64).log2() as usize,
|
all_samples.len() * (all_samples.len() as f64).log2() as usize,
|
||||||
model);
|
model);
|
||||||
|
|
||||||
// Sort with LLM comparator — yes, really. Rust's sort_by with an
|
// Sort with LLM comparator — yes, really. Rayon's parallel merge sort
|
||||||
// LLM as the comparison function. Each comparison is an API call.
|
// with an LLM as the comparison function. Multiple API calls in parallel.
|
||||||
let mut comparisons = 0usize;
|
let comparisons = AtomicUsize::new(0);
|
||||||
all_samples.sort_by(|a, b| {
|
use rayon::slice::ParallelSliceMut;
|
||||||
comparisons += 1;
|
all_samples.par_sort_by(|a, b| {
|
||||||
if comparisons % 10 == 0 {
|
let n = comparisons.fetch_add(1, Ordering::Relaxed);
|
||||||
eprint!(" {} comparisons...\r", comparisons);
|
if n % 10 == 0 {
|
||||||
|
eprint!(" {} comparisons...\r", n);
|
||||||
}
|
}
|
||||||
llm_compare(a, b, model).unwrap_or(std::cmp::Ordering::Equal)
|
llm_compare(a, b, model).unwrap_or(std::cmp::Ordering::Equal)
|
||||||
});
|
});
|
||||||
eprintln!(" {} total comparisons", comparisons);
|
eprintln!(" {} total comparisons", comparisons.load(Ordering::Relaxed));
|
||||||
|
|
||||||
let sorted = all_samples;
|
let sorted = all_samples;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue