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

Method _quantize_int8

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

Source from the content-addressed store, hash-verified

76 assert False, 'Unsupported quantization bits {}'.format(self.config['num_bits'])
77
78 def _quantize_int8(self, tensor: Tensor) -> Tuple[Tensor, Tensor, Tensor]:
79 q_range = 2**self.config['num_bits'] - 1
80 min_value = tensor.amin(dim=self.config['group_dim'] + 1, keepdim=True)
81 max_value = tensor.amax(dim=self.config['group_dim'] + 1, keepdim=True)
82
83 scale = q_range / (max_value - min_value)
84
85 tensor = tensor.sub_(min_value).mul_(scale)
86 tensor = tensor_round(tensor_clamp(tensor, 0, q_range)).to(torch.uint8)
87 return tensor, scale, min_value
88
89 def _compress_uint8_to_uint4(self, tensor: Tensor) -> Tensor:
90 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