neural_compressor
¶
Intel® Neural Compressor: An open-source Python library supporting popular model compression techniques.
Subpackages¶
neural_compressor.algorithm
neural_compressor.contrib
neural_compressor.data
neural_compressor.data.datasets
neural_compressor.data.datasets.bert_dataset
neural_compressor.data.datasets.coco_dataset
neural_compressor.data.datasets.dataset
neural_compressor.data.datasets.dummy_dataset
neural_compressor.data.datasets.dummy_dataset_v2
neural_compressor.data.datasets.imagenet_dataset
neural_compressor.data.datasets.style_transfer_dataset
neural_compressor.data.filters
neural_compressor.data.transforms
neural_compressor.experimental
neural_compressor.experimental.common
neural_compressor.experimental.common.criterion
neural_compressor.experimental.common.dataloader
neural_compressor.experimental.common.metric
neural_compressor.experimental.common.model
neural_compressor.experimental.common.optimizer
neural_compressor.experimental.common.postprocess
neural_compressor.experimental.common.torch_utils
neural_compressor.experimental.data
neural_compressor.experimental.export
neural_compressor.experimental.metric
neural_compressor.experimental.metric.bleu
neural_compressor.experimental.metric.bleu_util
neural_compressor.experimental.metric.coco_label_map
neural_compressor.experimental.metric.coco_tools
neural_compressor.experimental.metric.evaluate_squad
neural_compressor.experimental.metric.f1
neural_compressor.experimental.metric.metric
neural_compressor.experimental.nas
neural_compressor.experimental.pruning_recipes
neural_compressor.experimental.pytorch_pruner
neural_compressor.experimental.pytorch_pruner.logger
neural_compressor.experimental.pytorch_pruner.patterns
neural_compressor.experimental.pytorch_pruner.prune_utils
neural_compressor.experimental.pytorch_pruner.pruner
neural_compressor.experimental.pytorch_pruner.pruning
neural_compressor.experimental.pytorch_pruner.scheduler
neural_compressor.experimental.benchmark
neural_compressor.experimental.component
neural_compressor.experimental.distillation
neural_compressor.experimental.graph_optimization
neural_compressor.experimental.mixed_precision
neural_compressor.experimental.model_conversion
neural_compressor.experimental.pruning
neural_compressor.experimental.pruning_v2
neural_compressor.experimental.quantization
neural_compressor.experimental.scheduler
neural_compressor.metric
neural_compressor.model
neural_compressor.pruner
neural_compressor.pruner.pruner_legacy
neural_compressor.pruner.criteria
neural_compressor.pruner.logger
neural_compressor.pruner.patterns
neural_compressor.pruner.pruners
neural_compressor.pruner.pruning
neural_compressor.pruner.regs
neural_compressor.pruner.schedulers
neural_compressor.pruner.utils
neural_compressor.strategy
neural_compressor.strategy.utils
neural_compressor.strategy.auto_mixed_precision
neural_compressor.strategy.basic
neural_compressor.strategy.bayesian
neural_compressor.strategy.conservative
neural_compressor.strategy.exhaustive
neural_compressor.strategy.hawq_v2
neural_compressor.strategy.mse
neural_compressor.strategy.mse_v2
neural_compressor.strategy.random
neural_compressor.strategy.strategy
neural_compressor.utils
neural_compressor.utils.collect_layer_histogram
neural_compressor.utils.constant
neural_compressor.utils.create_obj_from_config
neural_compressor.utils.kl_divergence
neural_compressor.utils.load_huggingface
neural_compressor.utils.logger
neural_compressor.utils.options
neural_compressor.utils.pytorch
neural_compressor.utils.utility
neural_compressor.ux
neural_compressor.ux.components
neural_compressor.ux.components.benchmark
neural_compressor.ux.components.config_generator
neural_compressor.ux.components.configuration_wizard
neural_compressor.ux.components.db_manager
neural_compressor.ux.components.diagnosis
neural_compressor.ux.components.file_browser
neural_compressor.ux.components.graph
neural_compressor.ux.components.jobs_management
neural_compressor.ux.components.model
neural_compressor.ux.components.model_zoo
neural_compressor.ux.components.names_mapper
neural_compressor.ux.components.optimization
neural_compressor.ux.components.profiling
neural_compressor.ux.components.manage_workspace
neural_compressor.ux.utils
neural_compressor.ux.utils.templates
neural_compressor.ux.utils.workload
neural_compressor.ux.utils.consts
neural_compressor.ux.utils.environment
neural_compressor.ux.utils.exceptions
neural_compressor.ux.utils.executor
neural_compressor.ux.utils.expiring_dict
neural_compressor.ux.utils.github_info
neural_compressor.ux.utils.hw_info
neural_compressor.ux.utils.json_serializer
neural_compressor.ux.utils.logger
neural_compressor.ux.utils.parser
neural_compressor.ux.utils.proc
neural_compressor.ux.utils.processes
neural_compressor.ux.utils.singleton
neural_compressor.ux.utils.status_updates
neural_compressor.ux.utils.utils
neural_compressor.ux.utils.yaml_utils
neural_compressor.ux.web
neural_compressor.ux.inc_bench
Submodules¶
Package Contents¶
Classes¶
Benchmark class can be used to evaluate the model performance. |
|
Config of distillation. |
|
Config Class for Post Training Quantization. |
|
Similiar to torch optimizer's interface. |
|
Config Class for Quantization Aware Training. |
Functions¶
|
Set the random seed in config. |
|
Set the tensorboard in config. |
|
Set the workspace in config. |
- class neural_compressor.Benchmark(conf_fname_or_obj)¶
Bases:
object
Benchmark class can be used to evaluate the model performance.
With the objective setting, user can get the data of what they configured in yaml.
- Parameters:
conf_fname_or_obj (string or obj) – The path to the YAML configuration file or Benchmark_Conf class containing accuracy goal, tuning objective and preferred calibration & quantization tuning space etc.
- dataloader(dataset, batch_size=1, collate_fn=None, last_batch='rollover', sampler=None, batch_sampler=None, num_workers=0, pin_memory=False, shuffle=False, distributed=False)¶
Set dataloader for benchmarking.
- metric(name, metric_cls, **kwargs)¶
Set the metric class and Neural Compressor will initialize this class when evaluation.
Neural Compressor has many built-in metrics, but users can set specific metrics through this api. The metric class should take the outputs of the model or postprocess (if have) as inputs. Neural Compressor built-in metrics always take (predictions, labels) as inputs for update, and user_metric.metric_cls should be a sub_class of neural_compressor.metric.metric or an user-defined metric object
- Parameters:
metric_cls (cls) – Should be a sub_class of neural_compressor.metric.BaseMetric, which takes (predictions, labels) as inputs
name (str, optional) – Name for metric. Defaults to ‘user_metric’.
- postprocess(name, postprocess_cls, **kwargs)¶
Set postprocess class and neural_compressor will initialize this class when evaluation.
The postprocess function should take the outputs of the model as inputs, and outputs (predictions, labels) as inputs for metric updates.
Args: name (str, optional): Name for postprocess. postprocess_cls (cls): Should be a sub_class of neural_compressor.data.transforms.postprocess.
- neural_compressor.set_random_seed(seed: int)¶
Set the random seed in config.
- neural_compressor.set_tensorboard(tensorboard: bool)¶
Set the tensorboard in config.
- neural_compressor.set_workspace(workspace: str)¶
Set the workspace in config.
- class neural_compressor.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.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.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.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.