neural_compressor.experimental.scheduler

Scheduler class.

Module Contents

Classes

Scheduler

Scheduler for neural_compressor component pipeline execution.

class neural_compressor.experimental.scheduler.Scheduler

Bases: object

Scheduler for neural_compressor component pipeline execution.

Neural Compressor supports serveral seperate components: Quantization, Pruning, Benchmarking. This scheduler will sequentially execute specified components by the order of appending. This interface provids an unique entry to pipeline execute all supported components.

There are two typical usages: 1) if all informations are set in user configuration yaml files by using neural_compressor built-in

dataloaders/datasets/metrics, the code usage is like below:

prune = Pruning(‘/path/to/pruning.yaml’) quantizer = Quantization(‘/path/to/quantization.yaml’) scheduler = Scheduler() scheduler.model(‘/path/to/model’) scheduler.append(prune) scheduler.append(quantizer) opt_model = scheduler() opt_model.save()

  1. if neural_compressor built-in dataloaders/datasets/metrics could not fully meet user requirements, customized dataloaders/datasets/metrics are needed, the code usage is like below:

    prune = Pruning(‘/path/to/pruning.yaml’) prune.train_func = … # optional if it is configured in user yaml. prune.eval_dataloader = … # optional if it is configured in user yaml. prune.eval_func = … # optional if it is configured in user yaml.

    quantizer = Quantization(‘/path/to/quantization.yaml’) quantizer.metric = … # optional if it is configured in user yaml. quantizer.calib_dataloader = … # optional if it is configured in user yaml. quantizer.eval_dataloader = … # optional if it is configured in user yaml.

    scheduler = Scheduler() scheduler.model(‘/path/to/model’) scheduler.append(prune) scheduler.append(quantizer) opt_model = scheduler() opt_model.save()

property model

Getter of model.

Returns:

The model used in the Scheduler process.

property train_func

Do not support get train_func.

property eval_func

Do not support get eval_func.

append(*args)

Add neural_compressor component into pipeline for sequential execution.

Parameters:
  • conf_fname_or_obj (string or obj) – The path to user configuration yaml file or conf class.

  • calib_dataloader (generator) – Optional. Data loader for calibration of Post- Training Static Quantization, or None for Post-Training Dynamic Quantization, or Data loader for training phase of Quantization- aware Training, or Data loader for training phase of Pruning, if its corresponding field is not configured in yaml.

  • eval_dataloader (generator) – Optional. Data loader for evaluation phase of all neural_compressor components, if its corresponding field is not configured in yaml and eval_func is not specified.

  • postprocess (Postprocess) – Optional. Object initialized from common.Postprocess.

  • metric (Metric) – Optional. Object initialized from common.Metric.

  • q_func (func) – Optional. Training function for Quantization-Aware Training and Pruning cases if user doesn’t provide training info in user configuration yaml file.

  • eval_func (func) – Optional. Evaluation function for Quantization-Aware Training and Pruning, being None for other cases.

  • kwargs (named arguments) – Reserved for interface extension.

combine(*args)

Combine neural_compressor components into a new component.

Parameters:
  • args (Component) – Components to be combined together. Input Component should be

  • combination (supported in Neural Compressor and pass the sanity check during combine. The illegal) –

  • error. ((e.g. Components uses different frameworks) returns an) –

Returns:

The return component is created as base Component class. It syncs input components configuration and creates dataloaders/functions accordingly.

Return type:

Combined Component