MCPcopy Create free account
hub / github.com/andrewkchan/deepseek.cpp / k_quantize

Function k_quantize

quantizer.py:5–20  ·  view source on GitHub ↗

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"])

Source from the content-addressed store, hash-verified

3from typing import Literal
4
5def 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}")

Callers 2

per_expert_k_quantizeFunction · 0.90
quantizeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected