Run all quantizations Args: types_to_quantize: List of quantization types, tuples of (embedding_type, output_suffix)
(self, types_to_quantize)
| 273 | print(f"ℹ️ Keeping existing file: {model_file}") |
| 274 | |
| 275 | def run_all_quantizations(self, types_to_quantize): |
| 276 | """ |
| 277 | Run all quantizations |
| 278 | |
| 279 | Args: |
| 280 | types_to_quantize: List of quantization types, tuples of (embedding_type, output_suffix) |
| 281 | """ |
| 282 | print(f"\n{'='*80}") |
| 283 | print(f"🚀 Starting Embedding Quantization and Benchmarking") |
| 284 | print(f"{'='*80}") |
| 285 | print(f"📥 Input model: {self.input_model}") |
| 286 | print(f"📤 Output directory: {self.output_dir}") |
| 287 | print(f"📊 Stats directory: {self.stats_dir}") |
| 288 | print(f"🔢 Total quantizations: {len(types_to_quantize)}") |
| 289 | print(f"{'='*80}\n") |
| 290 | |
| 291 | total_start = datetime.now() |
| 292 | |
| 293 | for i, (embedding_type, output_suffix) in enumerate(types_to_quantize, 1): |
| 294 | print(f"\n{'#'*80}") |
| 295 | print(f"[{i}/{len(types_to_quantize)}] Processing {output_suffix} ({embedding_type})") |
| 296 | print(f"{'#'*80}\n") |
| 297 | |
| 298 | # Quantize model |
| 299 | success = self.quantize(embedding_type, output_suffix) |
| 300 | |
| 301 | if not success: |
| 302 | print(f"⚠️ Skipping benchmark for {output_suffix} due to quantization failure") |
| 303 | continue |
| 304 | |
| 305 | # Run benchmark |
| 306 | bench_results = self.benchmark_model(output_suffix) |
| 307 | |
| 308 | if bench_results: |
| 309 | self.results.append(bench_results) |
| 310 | else: |
| 311 | print(f"⚠️ Benchmark failed for {output_suffix}") |
| 312 | |
| 313 | # Cleanup model files (only delete newly created files) |
| 314 | self.cleanup_model(output_suffix) |
| 315 | |
| 316 | print(f"\n{'#'*80}") |
| 317 | print(f"✅ Completed {output_suffix}") |
| 318 | print(f"{'#'*80}\n") |
| 319 | |
| 320 | total_end = datetime.now() |
| 321 | total_duration = (total_end - total_start).total_seconds() |
| 322 | |
| 323 | # 保存结果到CSV |
| 324 | self.save_results_to_csv() |
| 325 | |
| 326 | # 打印总结 |
| 327 | self.print_summary(total_duration) |
| 328 | |
| 329 | def save_results_to_csv(self): |
| 330 | """将benchmark结果保存到CSV文件""" |
no test coverage detected