Perform single quantization Args: embedding_type: Token embedding type (uppercase format, e.g., Q6_K) output_suffix: Output file suffix (lowercase format, e.g., q6_k) Returns: bool: Whether successful
(self, embedding_type, output_suffix)
| 44 | self.newly_created_files = set() # Track newly created files |
| 45 | |
| 46 | def quantize(self, embedding_type, output_suffix): |
| 47 | """ |
| 48 | Perform single quantization |
| 49 | |
| 50 | Args: |
| 51 | embedding_type: Token embedding type (uppercase format, e.g., Q6_K) |
| 52 | output_suffix: Output file suffix (lowercase format, e.g., q6_k) |
| 53 | |
| 54 | Returns: |
| 55 | bool: Whether successful |
| 56 | """ |
| 57 | output_file = self.output_dir / f"ggml-model-i2_s-embed-{output_suffix}.gguf" |
| 58 | |
| 59 | # Check if file already exists |
| 60 | file_already_existed = output_file.exists() |
| 61 | |
| 62 | if file_already_existed: |
| 63 | print(f"ℹ️ File already exists: {output_file}") |
| 64 | print(f" Skipping quantization, will use existing file for benchmark") |
| 65 | return True |
| 66 | |
| 67 | cmd = [ |
| 68 | str(self.quantize_bin), |
| 69 | "--token-embedding-type", embedding_type, |
| 70 | str(self.input_model), |
| 71 | str(output_file), |
| 72 | "I2_S", |
| 73 | "1", |
| 74 | "1" |
| 75 | ] |
| 76 | |
| 77 | print(f"\n{'='*80}") |
| 78 | print(f"🔄 Quantizing with embedding type: {embedding_type}") |
| 79 | print(f"📥 Input: {self.input_model}") |
| 80 | print(f"📤 Output: {output_file}") |
| 81 | print(f"💻 Command: {' '.join(cmd)}") |
| 82 | print(f"{'='*80}\n") |
| 83 | |
| 84 | start_time = datetime.now() |
| 85 | |
| 86 | try: |
| 87 | result = subprocess.run( |
| 88 | cmd, |
| 89 | capture_output=True, |
| 90 | text=True, |
| 91 | cwd=os.getcwd(), |
| 92 | timeout=600 # 10 minute timeout |
| 93 | ) |
| 94 | |
| 95 | end_time = datetime.now() |
| 96 | duration = (end_time - start_time).total_seconds() |
| 97 | |
| 98 | if result.returncode == 0: |
| 99 | # Get output file size |
| 100 | file_size_mb = output_file.stat().st_size / (1024 * 1024) |
| 101 | |
| 102 | print(f"✅ Success! Duration: {duration:.2f}s, Size: {file_size_mb:.2f} MB") |
| 103 |
no outgoing calls
no test coverage detected