quantize
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
x |
|
x |
Description
Converts the high-precision model into a quantization calibration model and calculates the quantization parameters after inference.
Prototype
1 | quantize(model, config) |
Parameters
Returns
None
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # Build a graph of the network for quantization. ori_model = build_model() model = copy.deepcopy(ori_model) # Perform quantization configuration. cfg = { 'batch_num': 1, 'quant_cfg': { 'weights': { 'type': 'int8', 'symmetric': True, 'strategy': 'tensor', }, }, 'algorithm': {'minmax'}, } # Call the quantization API to generate a quantization calibration model. quantize(model, cfg) |
config
Key |
- |
- |
Value |
|---|---|---|---|
batch_num |
- |
- |
Batch number for quantization. The value is of the uint32 type. |
quant_cfg |
- |
- |
Quantization configuration. |
- |
weights |
- |
Weight-only quantization configuration. |
- |
- |
type |
Weight quantization type. The value is of the string type. Currently, the following types are supported:
|
- |
- |
symmetric |
Whether the weight is symmetrically quantized. The value is of the boolean type.
|
- |
- |
strategy |
Weight quantization granularity. The value is of the string type.
For details about the quantization granularity, see Compression Concepts. |
- |
- |
group_size |
Group size in per-group quantization. This parameter can be configured only after per-group quantization is configured. It is configured only in weight quantization scenarios. The value must fall within the range [32, K – 1] and must be a multiple of 32. |
- |
inputs |
- |
Activation quantization configuration. |
- |
- |
type |
Activation quantization type. The value is of the string type. Currently, the following types are supported:
|
- |
- |
symmetric |
Whether the activation is symmetrically quantized. The value is of the boolean type.
|
- |
- |
strategy |
Activation quantization granularity. The value is of the string type.
|
algorithm |
- |
- |
Quantization algorithm. The value is of the string type. The following configurations are supported:
For details, see Compression Algorithms. |
skip_layers |
- |
- |
Layers to exclude from quantization. It is a global parameter of the string type. Any layer whose name contains the user-specified string is excluded. |