Runs evaluation on the model using vLLM. Args: dataset: The dataset to evaluate on. vllm_rollout: The vLLM rollout object for generating responses. debug: If True, prints debug information for each sample. Returns: A dictionary containing evaluation scores: 'correct', 'partiall
(dataset, vllm_rollout, debug=True)
| 173 | |
| 174 | |
| 175 | def evaluate_model(dataset, vllm_rollout, debug=True): |
| 176 | """Runs evaluation on the model using vLLM. |
| 177 | |
| 178 | Args: |
| 179 | dataset: The dataset to evaluate on. |
| 180 | vllm_rollout: The vLLM rollout object for generating responses. |
| 181 | debug: If True, prints debug information for each sample. |
| 182 | |
| 183 | Returns: |
| 184 | A dictionary containing evaluation scores: 'correct', 'partially_correct', |
| 185 | and 'correct_format' percentages. |
| 186 | """ |
| 187 | rollout_config = base_rollout.RolloutConfig( |
| 188 | max_tokens_to_generate=MAX_TOKENS_TO_GENERATE, |
| 189 | max_prompt_length=MAX_PROMPT_LENGTH, |
| 190 | temperature=EVALUATION_CONFIG["temperature"], |
| 191 | top_p=EVALUATION_CONFIG["top_p"], |
| 192 | top_k=EVALUATION_CONFIG["top_k"], |
| 193 | data_type="bfloat16", |
| 194 | ) |
| 195 | |
| 196 | total, total_correct, total_partially_correct, total_correct_format = 0, 0, 0, 0 |
| 197 | for batch in tqdm(dataset): |
| 198 | batch_response = vllm_rollout.generate(batch["prompt"], rollout_config) |
| 199 | for i, question in enumerate(batch["question"]): |
| 200 | if debug: |
| 201 | print("========================================") |
| 202 | print(f"Question: {question}") |
| 203 | print("----------------------------------------") |
| 204 | print(f"Model Generated Response: {batch_response.text[i]}") |
| 205 | print("----------------------------------------") |
| 206 | print(f"Target Response: {batch["target_answer"][i]}") |
| 207 | print("========================================") |
| 208 | |
| 209 | is_correct, is_partially_correct, has_correct_format = score_response( |
| 210 | target=batch["target_answer"][i], prediction=batch_response.text[i], debug=debug |
| 211 | ) |
| 212 | if is_correct: |
| 213 | total_correct += 1 |
| 214 | if is_partially_correct: |
| 215 | total_partially_correct += 1 |
| 216 | if has_correct_format: |
| 217 | total_correct_format += 1 |
| 218 | total += 1 |
| 219 | |
| 220 | return { |
| 221 | "correct": (total_correct / total) * 100, |
| 222 | "partially_correct": (total_partially_correct / total) * 100, |
| 223 | "correct_format": (total_correct_format / total) * 100, |
| 224 | } |
| 225 | |
| 226 | |
| 227 | def safe_string_to_float(text): |
no test coverage detected