neural_compressor.utils.create_obj_from_config

Utility methods to create corresponding objects from configuration.

Module Contents

Functions

get_func_from_config(func_dict, cfg[, compose])

Get the function or the composed function from configuration.

get_preprocess(preprocesses, cfg[, compose])

Get the preprocess function from configuration.

get_metrics(metrics, cfg[, compose])

Get the metrics function from configuration.

get_postprocess(postprocesses, cfg[, compose])

Get the postprocess function from configuration.

get_algorithm(algorithms, cfg[, compose])

Get the algorithms from configuration.

create_dataset(framework, data_source, cfg_preprocess, ...)

Create the dataset from the data source.

create_dataloader(framework, dataloader_cfg)

Create the dataloader according to the framework.

create_eval_func(framework, dataloader, adaptor, metric)

The interface to create evaluate function from config.

create_train_func(framework, dataloader, adaptor, ...)

The interface to create train function from config.

neural_compressor.utils.create_obj_from_config.get_func_from_config(func_dict, cfg, compose=True)[source]

Get the function or the composed function from configuration.

neural_compressor.utils.create_obj_from_config.get_preprocess(preprocesses, cfg, compose=True)[source]

Get the preprocess function from configuration.

neural_compressor.utils.create_obj_from_config.get_metrics(metrics, cfg, compose=True)[source]

Get the metrics function from configuration.

neural_compressor.utils.create_obj_from_config.get_postprocess(postprocesses, cfg, compose=True)[source]

Get the postprocess function from configuration.

neural_compressor.utils.create_obj_from_config.get_algorithm(algorithms, cfg, compose=False)[source]

Get the algorithms from configuration.

Parameters:
  • algorithms – the algorithm management.

  • cfg – a dict contain the algo name and use it or not.

  • compose – compose all algo or not. Defaults to False.

Returns:

All open algos.

neural_compressor.utils.create_obj_from_config.create_dataset(framework, data_source, cfg_preprocess, cfg_filter)[source]

Create the dataset from the data source.

neural_compressor.utils.create_obj_from_config.create_dataloader(framework, dataloader_cfg)[source]

Create the dataloader according to the framework.

neural_compressor.utils.create_obj_from_config.create_eval_func(framework, dataloader, adaptor, metric, postprocess_cfg=None, iteration=-1, tensorboard=False, fp32_baseline=False)[source]

The interface to create evaluate function from config.

Parameters:
  • framework (str) – The string of framework.

  • dataloader (common.DataLoader) – The object of common.DataLoader.

  • adaptor (obj) – The object of adaptor.

  • metric – The evaluation metric.

  • postprocess_cfg – The postprocess configuration.

  • iteration – The number of iterations to evaluate.

  • tensorboard – Whether to use tensorboard.

  • fp32_baseline – The fp32 baseline score.

Returns:

The constructed evaluation function

neural_compressor.utils.create_obj_from_config.create_train_func(framework, dataloader, adaptor, train_cfg, hooks=None, callbacks=None)[source]

The interface to create train function from config.

Parameters:
  • framework (str) – The string of framework.

  • dataloader (common.DataLoader) – The object of common.DataLoader.

  • adaptor (obj) – The object of adaptor.

  • train_cfg (dict) – The dict of training related config.

  • hooks (dict) – The dict of training hooks, supported keys are: on_epoch_begin, on_epoch_end, on_step_begin, on_step_end. Their values are functions to be executed in adaptor layer.

Returns:

The constructed train function