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

Function PPQLinearQuantFunction

ppq/quantization/qfunction/linear.py:200–216  ·  view source on GitHub ↗

PPQ 核心量化函数,没啥好说的了吧,这个玩意既做 quant 也做 dequant

(
    tensor: torch.Tensor, config: TensorQuantizationConfig)

Source from the content-addressed store, hash-verified

198 return TensorwiseDynamicLinearQuantImpl.apply(tensor, config)
199
200def PPQLinearQuantFunction(
201 tensor: torch.Tensor, config: TensorQuantizationConfig) -> torch.Tensor:
202 """PPQ 核心量化函数,没啥好说的了吧,这个玩意既做 quant 也做 dequant"""
203 if not QuantizationStates.is_activated(config.state): return tensor
204 if not config.policy.has_property(QuantizationProperty.LINEAR):
205 raise ValueError('Critical Quantization Error! Non-linear config detected.')
206 if config.policy.has_property(QuantizationProperty.DYNAMIC):
207 raise ValueError('Unexpected Dynamic Flag in Quantization Policy. Use PPQDyamicQuantFunction Instead.')
208
209 if config.policy.has_property(QuantizationProperty.PER_CHANNEL):
210 return ChannelwiseLinearQuantImpl.apply(
211 tensor, config.scale, config.offset, config.channel_axis,
212 config.quant_min, config.quant_max, config.rounding)
213 elif config.policy.has_property(QuantizationProperty.PER_TENSOR):
214 return TensorwiseLinearQuantImpl.apply(
215 tensor, config.scale, config.offset,
216 config.quant_min, config.quant_max, config.rounding)
217
218def PPQLinearQuant_toInt(tensor: torch.Tensor, config: TensorQuantizationConfig) -> torch.Tensor:
219 """PPQ 核心量化函数,没啥好说的了吧,这个玩意只做 quant 不做 dequant"""

Callers 4

finetuneMethod · 0.90
__call__Method · 0.90
test_isotone.pyFile · 0.90
PPQuantFunctionFunction · 0.85

Calls 2

is_activatedMethod · 0.80
has_propertyMethod · 0.80

Tested by

no test coverage detected