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

Method _quantize_int8

deepspeed/inference/quantization/utils.py:73–82  ·  view source on GitHub ↗
(self, tensor: Tensor)

Source from the content-addressed store, hash-verified

71 assert False, 'Unsupported quantization bits {}'.format(self.config['num_bits'])
72
73 def _quantize_int8(self, tensor: Tensor) -> Tuple[Tensor, Tensor, Tensor]:
74 q_range = 2**self.config['num_bits'] - 1
75 min_value = tensor.amin(dim=self.config['group_dim'] + 1, keepdim=True)
76 max_value = tensor.amax(dim=self.config['group_dim'] + 1, keepdim=True)
77
78 scale = q_range / (max_value - min_value)
79
80 tensor = tensor.sub_(min_value).mul_(scale)
81 tensor = tensor_round(tensor_clamp(tensor, 0, q_range)).to(torch.uint8)
82 return tensor, scale, min_value
83
84 def _compress_uint8_to_uint4(self, tensor: Tensor) -> Tensor:
85 assert tensor.shape[-1] % 2 == 0

Callers 1

quantizeMethod · 0.95

Calls 3

tensor_roundFunction · 0.85
tensor_clampFunction · 0.85
toMethod · 0.45

Tested by

no test coverage detected