MCPcopy Create free account
hub / github.com/apple/coremltools / get_quant_range

Function get_quant_range

coremltools/optimize/_utils.py:45–61  ·  view source on GitHub ↗

Utility to get the quantization range for a given quantization config Adapted from phoenix/quatization/_utils.py

(n_bits: int, signed: bool, mode: str)

Source from the content-addressed store, hash-verified

43
44
45def get_quant_range(n_bits: int, signed: bool, mode: str) -> Tuple[int, int]:
46 """
47 Utility to get the quantization range for a given quantization config
48 Adapted from phoenix/quatization/_utils.py
49 """
50 max_q = 2**n_bits
51 if not signed:
52 quant_min = 0
53 quant_max = max_q - 1
54 if mode == "LINEAR_SYMMETRIC":
55 quant_max -= 1
56 else:
57 quant_min = -max_q / 2
58 quant_max = max_q / 2 - 1
59 if mode == "LINEAR_SYMMETRIC":
60 quant_min += 1
61 return int(quant_min), int(quant_max)
62
63
64def quantize_weight(

Calls 1

intClass · 0.85