MCPcopy Index your code
hub / github.com/OpenPPL/ppq / PPQFloatingQuantFunction

Function PPQFloatingQuantFunction

ppq/quantization/qfunction/floating.py:95–120  ·  view source on GitHub ↗
(
    tensor: torch.Tensor, config: TensorQuantizationConfig)

Source from the content-addressed store, hash-verified

93
94
95def PPQFloatingQuantFunction(
96 tensor: torch.Tensor, config: TensorQuantizationConfig) -> torch.Tensor:
97 if not PPQ_CONFIG.USING_CUDA_KERNEL:
98 raise PermissionError('PPQ Floating Quant Function require PPQ_CONFIG.USING_CUDA_KERNEL = True')
99 if not tensor.is_cuda:
100 raise PermissionError('PPQ Floating Quant Function requires tensor device to be cuda, '
101 'CPU floating quantization is not implemented yet.')
102
103 """PPQ 核心量化函数,没啥好说的了吧,这个玩意既做 quant 也做 dequant"""
104 if not QuantizationStates.is_activated(config.state): return tensor
105 if not config.policy.has_property(QuantizationProperty.FLOATING):
106 raise ValueError('Critical Quantization Error! Unexpected policy detected. '
107 'PPQFloatingQuantFunction except a Floating Quantization Config.')
108 if config.policy.has_property(QuantizationProperty.DYNAMIC):
109 raise ValueError('Unexpected Dynamic Flag in Quantization Policy.')
110
111 if config.policy.has_property(QuantizationProperty.PER_CHANNEL):
112 return ChannelwiseFloatingQuantImpl.apply(
113 tensor, config.scale, config.offset, config.channel_axis,
114 config.exponent_bits, config.mantissa_bits,
115 config.quant_min, config.quant_max, config.rounding)
116 elif config.policy.has_property(QuantizationProperty.PER_TENSOR):
117 return TensorwiseFloatingQuantImpl.apply(
118 tensor, config.scale, config.offset,
119 config.exponent_bits, config.mantissa_bits,
120 config.quant_min, config.quant_max, config.rounding)

Callers 1

PPQuantFunctionFunction · 0.85

Calls 2

is_activatedMethod · 0.80
has_propertyMethod · 0.80

Tested by

no test coverage detected