MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / dequantize

Method dequantize

deepspeed/ops/fp_quantizer/quantize.py:121–143  ·  view source on GitHub ↗
(self, input_q, fp_out=None, q_bits=8, q_mantisa_bits=3, scale=None)

Source from the content-addressed store, hash-verified

119 return fp_quant_module.get_scales(self.scale, self.num_groups)
120
121 def dequantize(self, input_q, fp_out=None, q_bits=8, q_mantisa_bits=3, scale=None) -> torch.Tensor:
122 assert (self.orig_dtype is not None), \
123 "[De-quantization Error]: you need to call quantize before dequantizing!"
124 fp_out = torch.empty(self.orig_shape, dtype=self.orig_dtype,
125 device=input_q.device) if fp_out is None else fp_out
126 if q_bits == 8:
127 pass
128 elif q_bits == 12:
129 q_mantisa_bits = 7
130 elif q_bits == 6:
131 q_mantisa_bits = 2
132 elif q_bits == 4:
133 q_mantisa_bits = 1
134 else:
135 assert (0), \
136 f"Missing {q_bits}-dequantization, please add the template arguments for the kernel to support this precision!"
137
138 if scale is not None:
139 assert input_q.numel() == fp_out.numel(), \
140 '[De-quantization Error]: quantized data should have the same size as original tensor when scale is not None!'
141 input_q = torch.cat([input_q.reshape(-1, self.group_size), scale], dim=-1).contiguous()
142 fp_quant_module.dequantize(fp_out, input_q, self.group_size, q_mantisa_bits, q_bits - q_mantisa_bits - 1)
143 return fp_out
144
145 def selective_dequantize(self,
146 input_q,

Callers 3

test_fp_quant_metaFunction · 0.95
test_fp_quantFunction · 0.95

Calls 4

contiguousMethod · 0.80
numelMethod · 0.45
reshapeMethod · 0.45
dequantizeMethod · 0.45

Tested by 3

test_fp_quant_metaFunction · 0.76
test_fp_quantFunction · 0.76