MCPcopy Create free account
hub / github.com/microsoft/BitNet / benchmark_model

Method benchmark_model

utils/quantize_embeddings.py:127–185  ·  view source on GitHub ↗

Benchmark model Args: output_suffix: Output file suffix (lowercase format, e.g., q6_k) Returns: dict: Dictionary with benchmark results, or None if failed

(self, output_suffix)

Source from the content-addressed store, hash-verified

125 return False
126
127 def benchmark_model(self, output_suffix):
128 """
129 Benchmark model
130
131 Args:
132 output_suffix: Output file suffix (lowercase format, e.g., q6_k)
133
134 Returns:
135 dict: Dictionary with benchmark results, or None if failed
136 """
137 model_file = self.output_dir / f"ggml-model-i2_s-embed-{output_suffix}.gguf"
138
139 if not model_file.exists():
140 print(f"❌ Model file not found for benchmarking: {model_file}")
141 return None
142
143 cmd = [
144 str(self.bench_bin),
145 "-m", str(model_file),
146 "-p", "128",
147 "-n", "0",
148 "-t", "1,2,4,8",
149 "-ngl", "0"
150 ]
151
152 print(f"\n{'='*80}")
153 print(f"🏃 Running benchmark for: {output_suffix}")
154 print(f"💻 Command: {' '.join(cmd)}")
155 print(f"{'='*80}\n")
156
157 try:
158 result = subprocess.run(
159 cmd,
160 capture_output=True,
161 text=True,
162 cwd=os.getcwd(),
163 timeout=300 # 5 minute timeout
164 )
165
166 if result.returncode == 0:
167 print("✅ Benchmark completed successfully")
168 print("\n📊 Benchmark output:")
169 print(result.stdout)
170
171 # 解析输出
172 bench_results = self.parse_benchmark_output(result.stdout, output_suffix)
173 return bench_results
174 else:
175 print(f"❌ Benchmark failed with return code {result.returncode}")
176 print(f"Error: {result.stderr}")
177 return None
178
179 except subprocess.TimeoutExpired:
180 print(f"❌ Benchmark timeout (exceeded 5 minutes)")
181 return None
182
183 except Exception as e:
184 print(f"❌ Benchmark exception: {e}")

Callers 1

run_all_quantizationsMethod · 0.95

Calls 1

Tested by

no test coverage detected