MCPcopy Create free account
hub / github.com/InternScience/SpectrumLab / evaluate_many

Method evaluate_many

spectrumlab/evaluator/base.py:99–249  ·  view source on GitHub ↗

Evaluate a single model on data_items with parallel processing. Args: data_items: List of data items to evaluate model: Model instance to evaluate max_out_len: Maximum output length for model generation batch_size: Batch size for proc

(
        self,
        data_items: List[Dict],
        model,
        max_out_len: int = 512,
        batch_size: Optional[int] = None,
        save_path: str = "./eval_results",
        n_jobs: int = -1,
    )

Source from the content-addressed store, hash-verified

97 }
98
99 def evaluate_many(
100 self,
101 data_items: List[Dict],
102 model,
103 max_out_len: int = 512,
104 batch_size: Optional[int] = None,
105 save_path: str = "./eval_results",
106 n_jobs: int = -1,
107 ) -> Dict:
108 """
109 Evaluate a single model on data_items with parallel processing.
110
111 Args:
112 data_items: List of data items to evaluate
113 model: Model instance to evaluate
114 max_out_len: Maximum output length for model generation
115 batch_size: Batch size for processing (if None, will be auto-calculated)
116 save_path: Base path to save results
117 n_jobs: Number of parallel jobs (-1 for all available cores)
118
119 Returns:
120 Dictionary containing evaluation results
121 """
122 import multiprocessing as mp
123 from concurrent.futures import ThreadPoolExecutor, as_completed
124 import math
125
126 if not data_items:
127 print("❌ No data items provided")
128 return {"error": "No data items provided"}
129
130 # Set number of jobs
131 if n_jobs == -1:
132 n_jobs = mp.cpu_count()
133
134 # Calculate batch size if not provided
135 if batch_size is None:
136 batch_size = max(1, math.ceil(len(data_items) / n_jobs))
137
138 print(f"🔄 Starting parallel evaluation on {len(data_items)} items...")
139 print(f"📝 Model: {type(model).__name__}")
140 print(f"⚡ Using {n_jobs} parallel workers with batch size {batch_size}")
141
142 # Split data into batches
143 batches = [
144 data_items[i : i + batch_size]
145 for i in range(0, len(data_items), batch_size)
146 ]
147
148 print(f"📦 Split into {len(batches)} batches")
149
150 # Build prompts for all items
151 print("📝 Building prompts...")
152 all_prompts = [self._build_prompt(item) for item in data_items]
153
154 # Split prompts into batches
155 prompt_batches = [
156 all_prompts[i : i + batch_size]

Calls 6

_build_promptMethod · 0.95
_extract_predictionMethod · 0.95
_calculate_accuracyMethod · 0.95
_save_resultsMethod · 0.95
_calculate_metricsMethod · 0.95
_print_resultsMethod · 0.95