MCPcopy
hub / github.com/deepspeedai/DeepSpeed / get_scale_zero_point

Function get_scale_zero_point

tests/unit/ops/quantizer/test_quantize.py:50–65  ·  view source on GitHub ↗
(q_bits, is_symmetric_quant, max, min, absmax, scales=None, zero_points=None)

Source from the content-addressed store, hash-verified

48
49
50def get_scale_zero_point(q_bits, is_symmetric_quant, max, min, absmax, scales=None, zero_points=None):
51
52 q_range, q_max, q_min = get_q_props(q_bits)
53
54 if is_symmetric_quant:
55 scale = torch.empty_like(absmax)
56 for i, x in enumerate(absmax):
57 scale[i] = torch.ones_like(x) if x == 0 else q_range / (2 * x)
58 zero_point = torch.zeros(scale.shape, dtype=torch.float32, device=get_accelerator().device_name())
59 else:
60 scale = torch.empty_like(max)
61 for i, x in enumerate(max):
62 scale[i] = torch.ones_like(x) if max[i] == min[i] else q_range / (max[i] - min[i])
63 zero_point = q_min - (min * scale)
64
65 return scale, zero_point
66
67
68def int4x2to2xint4(int4X2tensor):

Callers 1

run_float_quantizeFunction · 0.85

Calls 3

get_acceleratorFunction · 0.90
get_q_propsFunction · 0.85
device_nameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…