neural_compressor.config

Configs for Neural Compressor.

Module Contents

Classes

Options

Option Class for configs.

BenchmarkConfig

Config Class for Benchmark.

AccuracyCriterion

Class of Accuracy Criterion.

TuningCriterion

Class for Tuning Criterion.

PostTrainingQuantConfig

Config Class for Post Training Quantization.

QuantizationAwareTrainingConfig

Config Class for Quantization Aware Training.

WeightPruningConfig

Similiar to torch optimizer's interface.

KnowledgeDistillationLossConfig

Config Class for Knowledge Distillation Loss.

IntermediateLayersKnowledgeDistillationLossConfig

Config Class for Intermediate Layers Knowledge Distillation Loss.

SelfKnowledgeDistillationLossConfig

Config Class for Self Knowledge Distillation Loss.

DistillationConfig

Config of distillation.

MixedPrecisionConfig

Config Class for MixedPrecision.

ExportConfig

Config Class for Export.

ONNXQlinear2QDQConfig

Config Class for ONNXQlinear2QDQ.

Torch2ONNXConfig

Config Class for Torch2ONNX.

TF2ONNXConfig

Config Class for TF2ONNX.

Functions

check_value(name, src, supported_type[, supported_value])

Check if the given object is the given supported type and in the given supported value.

neural_compressor.config.check_value(name, src, supported_type, supported_value=[])

Check if the given object is the given supported type and in the given supported value.

class neural_compressor.config.Options(random_seed=1978, workspace=default_workspace, resume_from=None, tensorboard=False)

Option Class for configs.

property random_seed

Get random seed.

property workspace

Get workspace.

property resume_from

Get resume_from.

property tensorboard

Get tensorboard.

class neural_compressor.config.BenchmarkConfig(inputs=[], outputs=[], backend='default', warmup=5, iteration=-1, cores_per_instance=None, num_of_instance=None, inter_num_of_threads=None, intra_num_of_threads=None)

Config Class for Benchmark.

property backend

Get backend.

property outputs

Get outputs.

property inputs

Get inputs.

property warmup

Get warmup.

property iteration

Get iteration.

property cores_per_instance

Get cores_per_instance.

property num_of_instance

Get num_of_instance.

property inter_num_of_threads

Get inter_num_of_threads.

property intra_num_of_threads

Get intra_num_of_threads.

class neural_compressor.config.AccuracyCriterion(higher_is_better=True, criterion='relative', tolerable_loss=0.01)

Class of Accuracy Criterion.

property higher_is_better

Get higher_is_better.

property relative

Get tolerable_loss when criterion is relative.

property absolute

Get tolerable_loss when criterion is absolute.

property criterion

Get criterion.

property tolerable_loss

Get tolerable_loss.

class neural_compressor.config.TuningCriterion(strategy='basic', strategy_kwargs=None, timeout=0, max_trials=100, objective='performance')

Class for Tuning Criterion.

property max_trials

Get max_trials.

property timeout

Get timeout.

property objective

Get objective.

property strategy

Get strategy.

property strategy_kwargs

Get strategy_kwargs.

class neural_compressor.config.PostTrainingQuantConfig(device='cpu', backend='default', quant_format='default', inputs=[], outputs=[], approach='static', calibration_sampling_size=[100], op_type_list=None, op_name_list=None, reduce_range=None, excluded_precisions=[], quant_level=1, tuning_criterion=tuning_criterion, accuracy_criterion=accuracy_criterion)

Bases: _BaseQuantizationConfig

Config Class for Post Training Quantization.

property approach

Get approach.

property tuning_criterion

Get tuning_criterion.

class neural_compressor.config.QuantizationAwareTrainingConfig(device='cpu', backend='default', inputs=[], outputs=[], op_type_list=None, op_name_list=None, reduce_range=None, excluded_precisions=[], quant_level=1)

Bases: _BaseQuantizationConfig

Config Class for Quantization Aware Training.

property approach

Get approach.

class neural_compressor.config.WeightPruningConfig(pruning_configs=[{}], target_sparsity=0.9, pruning_type='snip_momentum', pattern='4x1', op_names=[], excluded_op_names=[], start_step=0, end_step=0, pruning_scope='global', pruning_frequency=1, min_sparsity_ratio_per_op=0.0, max_sparsity_ratio_per_op=0.98, sparsity_decay_type='exp', pruning_op_types=['Conv', 'Linear'], **kwargs)

Similiar to torch optimizer’s interface.

property weight_compression

Get weight_compression.

class neural_compressor.config.KnowledgeDistillationLossConfig(temperature=1.0, loss_types=['CE', 'CE'], loss_weights=[0.5, 0.5])

Config Class for Knowledge Distillation Loss.

class neural_compressor.config.IntermediateLayersKnowledgeDistillationLossConfig(layer_mappings=[], loss_types=[], loss_weights=[], add_origin_loss=False)

Config Class for Intermediate Layers Knowledge Distillation Loss.

class neural_compressor.config.SelfKnowledgeDistillationLossConfig(layer_mappings=[], temperature=1.0, loss_types=[], loss_weights=[], add_origin_loss=False)

Config Class for Self Knowledge Distillation Loss.

class neural_compressor.config.DistillationConfig(teacher_model=None, criterion=criterion, optimizer={'SGD': {'learning_rate': 0.0001}})

Config of distillation.

Parameters:
  • teacher_model (Callable) – Teacher model for distillation. Defaults to None.

  • features (optional) – Teacher features for distillation, features and teacher_model are alternative. Defaults to None.

  • criterion (Callable, optional) – Distillation loss configure.

  • optimizer (dictionary, optional) – Optimizer configure.

property criterion

Get criterion.

property optimizer

Get optimizer.

property teacher_model

Get teacher_model.

class neural_compressor.config.MixedPrecisionConfig(device='cpu', backend='default', inputs=[], outputs=[], tuning_criterion=tuning_criterion, accuracy_criterion=accuracy_criterion, excluded_precisions=[])

Bases: PostTrainingQuantConfig

Config Class for MixedPrecision.

class neural_compressor.config.ExportConfig(dtype='int8', opset_version=14, quant_format='QDQ', example_inputs=None, input_names=None, output_names=None, dynamic_axes=None)

Config Class for Export.

property dtype

Get dtype.

property opset_version

Get opset_version.

property quant_format

Get quant_format.

property example_inputs

Get example_inputs.

property input_names

Get input_names.

property output_names

Get output_names.

property dynamic_axes

Get dynamic_axes.

class neural_compressor.config.ONNXQlinear2QDQConfig

Config Class for ONNXQlinear2QDQ.

class neural_compressor.config.Torch2ONNXConfig(dtype='int8', opset_version=14, quant_format='QDQ', example_inputs=None, input_names=None, output_names=None, dynamic_axes=None, recipe='QDQ_OP_FP32_BIAS', **kwargs)

Bases: ExportConfig

Config Class for Torch2ONNX.

class neural_compressor.config.TF2ONNXConfig(dtype='int8', opset_version=14, quant_format='QDQ', example_inputs=None, input_names=None, output_names=None, dynamic_axes=None, **kwargs)

Bases: ExportConfig

Config Class for TF2ONNX.