Quantize a 2D float32 tensor to Q2_K or Q3_K format. Args: tensor: Input tensor of shape (M, N) where N must be a multiple of 256 Returns: Quantized tensor of type uint8 and shape (M, sizeof(block_q2_K) * N/256) containing the block_q2_K data
(tensor: torch.Tensor, method: Literal["q2_k", "q3_k"])
| 3 | from typing import Literal |
| 4 | |
| 5 | def k_quantize(tensor: torch.Tensor, method: Literal["q2_k", "q3_k"]) -> torch.Tensor: |
| 6 | """ |
| 7 | Quantize a 2D float32 tensor to Q2_K or Q3_K format. |
| 8 | |
| 9 | Args: |
| 10 | tensor: Input tensor of shape (M, N) where N must be a multiple of 256 |
| 11 | |
| 12 | Returns: |
| 13 | Quantized tensor of type uint8 and shape (M, sizeof(block_q2_K) * N/256) containing the block_q2_K data |
| 14 | """ |
| 15 | if method == "q2_k": |
| 16 | return quantizer_cpp.quantize_q2_k(tensor) |
| 17 | elif method == "q3_k": |
| 18 | return quantizer_cpp.quantize_q3_k(tensor) |
| 19 | else: |
| 20 | raise ValueError(f"Invalid method: {method}") |
no outgoing calls
no test coverage detected