MCPcopy Index your code
hub / github.com/microsoft/BitNet / run_all_tests

Method run_all_tests

utils/test_perplexity.py:326–439  ·  view source on GitHub ↗

Run perplexity tests on all datasets.

(self, threads=16, ctx_size=512)

Source from the content-addressed store, hash-verified

324 print(f"ℹ️ Keeping existing file: {model_path.name}")
325
326 def run_all_tests(self, threads=16, ctx_size=512):
327 """Run perplexity tests on all datasets."""
328 datasets = self.find_datasets()
329
330 if not datasets:
331 print(f"\n❌ No datasets found in {self.data_dir}")
332 print(f" Make sure each dataset directory has a test.txt file")
333 return
334
335 # Quick mode: test all datasets but only first 4096 chars with smaller context
336 if self.quick_mode:
337 ctx_size = min(ctx_size, 128) # Use smaller context in quick mode
338 print(f"\n⚡ QUICK TEST MODE ENABLED")
339 print(f" - Testing all datasets with first 4096 characters only")
340 print(f" - Using reduced context size: {ctx_size}")
341
342 # Determine models to test
343 if self.test_embeddings:
344 print(f"\n{'='*80}")
345 print(f"🧪 EMBEDDING QUANTIZATION TEST MODE")
346 print(f"{'='*80}")
347 print(f"📦 Base model: {self.model_path.name}")
348 print(f"🔢 Embedding types to test: {len(self.embedding_types)}")
349 print(f"📊 Datasets: {len(datasets)}")
350 print(f"🧵 Threads: {threads}")
351 print(f"📏 Context size: {ctx_size}")
352 print(f"{'='*80}")
353
354 total_start = time.time()
355
356 # Test each embedding type
357 for i, (embedding_type, output_suffix) in enumerate(self.embedding_types, 1):
358 print(f"\n\n{'#'*80}")
359 print(f"[{i}/{len(self.embedding_types)}] Testing embedding type: {output_suffix} ({embedding_type})")
360 print(f"{'#'*80}")
361
362 # Quantize model
363 quantized_model = self.quantize_embedding(embedding_type, output_suffix)
364
365 if quantized_model is None:
366 print(f"⚠️ Skipping tests for {output_suffix} due to quantization failure")
367 continue
368
369 # Test on all datasets
370 for j, dataset in enumerate(datasets, 1):
371 print(f"\n[{j}/{len(datasets)}] Testing {dataset['name']} with {output_suffix}...")
372
373 # Use quick dataset if in quick mode
374 test_path = dataset['path']
375 if self.quick_mode:
376 test_path = self.create_quick_dataset(dataset['path'])
377
378 result = self.run_perplexity_test(
379 f"{dataset['name']}_embed-{output_suffix}",
380 test_path,
381 threads,
382 ctx_size,
383 model_override=quantized_model

Callers 1

mainFunction · 0.95

Calls 8

find_datasetsMethod · 0.95
quantize_embeddingMethod · 0.95
create_quick_datasetMethod · 0.95
run_perplexity_testMethod · 0.95
cleanup_modelMethod · 0.95
cleanup_temp_filesMethod · 0.95
save_resultsMethod · 0.95
print_summaryMethod · 0.95

Tested by

no test coverage detected