Quantize model with specific embedding type. Args: embedding_type: Token embedding type (uppercase, e.g., 'Q6_K') output_suffix: Output file suffix (lowercase, e.g., 'q6_k') Returns: Path to quantized model or None if fai
(self, embedding_type, output_suffix)
| 239 | return None |
| 240 | |
| 241 | def quantize_embedding(self, embedding_type, output_suffix): |
| 242 | """ |
| 243 | Quantize model with specific embedding type. |
| 244 | |
| 245 | Args: |
| 246 | embedding_type: Token embedding type (uppercase, e.g., 'Q6_K') |
| 247 | output_suffix: Output file suffix (lowercase, e.g., 'q6_k') |
| 248 | |
| 249 | Returns: |
| 250 | Path to quantized model or None if failed |
| 251 | """ |
| 252 | # Construct output path |
| 253 | model_dir = self.model_path.parent |
| 254 | output_path = model_dir / f"ggml-model-i2_s-embed-{output_suffix}.gguf" |
| 255 | |
| 256 | # Check if file already exists |
| 257 | file_existed = output_path.exists() |
| 258 | |
| 259 | if file_existed: |
| 260 | print(f"ℹ️ Model already exists: {output_path.name}") |
| 261 | return output_path |
| 262 | |
| 263 | cmd = [ |
| 264 | str(self.quantize_bin), |
| 265 | "--token-embedding-type", embedding_type, |
| 266 | str(self.model_path), |
| 267 | str(output_path), |
| 268 | "I2_S", |
| 269 | "1", |
| 270 | "1" |
| 271 | ] |
| 272 | |
| 273 | print(f"\n{'='*80}") |
| 274 | print(f"🔄 Quantizing with embedding type: {embedding_type}") |
| 275 | print(f"📥 Input: {self.model_path.name}") |
| 276 | print(f"📤 Output: {output_path.name}") |
| 277 | print(f"💻 Command: {' '.join(cmd)}") |
| 278 | print(f"{'='*80}\n") |
| 279 | |
| 280 | start_time = time.time() |
| 281 | |
| 282 | try: |
| 283 | result = subprocess.run( |
| 284 | cmd, |
| 285 | capture_output=True, |
| 286 | text=True, |
| 287 | cwd=os.getcwd(), |
| 288 | timeout=600 # 10 minutes timeout |
| 289 | ) |
| 290 | |
| 291 | duration = time.time() - start_time |
| 292 | |
| 293 | if result.returncode == 0: |
| 294 | file_size_mb = output_path.stat().st_size / (1024 * 1024) |
| 295 | print(f"✅ Quantization successful!") |
| 296 | print(f" Duration: {duration:.2f}s") |
| 297 | print(f" Size: {file_size_mb:.2f} MB") |
| 298 |