Run perplexity test on a single dataset.
(self, dataset_name, dataset_path, threads=16, ctx_size=512, model_override=None)
| 114 | self.temp_files = [] |
| 115 | |
| 116 | def run_perplexity_test(self, dataset_name, dataset_path, threads=16, ctx_size=512, model_override=None): |
| 117 | """Run perplexity test on a single dataset.""" |
| 118 | test_model = model_override if model_override else self.model_path |
| 119 | |
| 120 | print(f"\n{'='*80}") |
| 121 | print(f"📊 Testing on dataset: {dataset_name}") |
| 122 | print(f" File: {dataset_path}") |
| 123 | print(f" Model: {test_model.name}") |
| 124 | print(f"{'='*80}") |
| 125 | |
| 126 | cmd = [ |
| 127 | str(self.llama_perplexity_bin), |
| 128 | "-m", str(test_model), |
| 129 | "-f", str(dataset_path), |
| 130 | "-t", str(threads), |
| 131 | "-c", str(ctx_size), |
| 132 | "-ngl", "0" # CPU only |
| 133 | ] |
| 134 | |
| 135 | print(f"💻 Command: {' '.join(cmd)}") |
| 136 | print(f"⏱️ Starting test...\n") |
| 137 | |
| 138 | start_time = time.time() |
| 139 | |
| 140 | try: |
| 141 | result = subprocess.run( |
| 142 | cmd, |
| 143 | capture_output=True, |
| 144 | text=True, |
| 145 | timeout=3600, # 1 hour timeout |
| 146 | cwd=os.getcwd() |
| 147 | ) |
| 148 | |
| 149 | elapsed_time = time.time() - start_time |
| 150 | |
| 151 | if result.returncode == 0: |
| 152 | # Parse perplexity from output (check both stdout and stderr) |
| 153 | combined_output = result.stdout + "\n" + result.stderr |
| 154 | ppl = self.parse_perplexity(combined_output) |
| 155 | |
| 156 | if ppl is not None: |
| 157 | print(f"\n✅ Perplexity: {ppl}") |
| 158 | print(f"⏱️ Time: {elapsed_time:.2f}s ({elapsed_time/60:.2f} min)") |
| 159 | status = "success" |
| 160 | else: |
| 161 | print(f"\n⚠️ Test completed but could not parse perplexity") |
| 162 | print(f"Last 500 chars of stdout:") |
| 163 | print(result.stdout[-500:]) |
| 164 | print(f"Last 500 chars of stderr:") |
| 165 | print(result.stderr[-500:]) |
| 166 | status = "parse_error" |
| 167 | ppl = None |
| 168 | else: |
| 169 | print(f"\n❌ Test failed with return code {result.returncode}") |
| 170 | print(f"Error: {result.stderr[:500]}") |
| 171 | status = "failed" |
| 172 | ppl = None |
| 173 | elapsed_time = time.time() - start_time |
no test coverage detected