neural_compressor.utils.utility
¶
quantization auto-tuning config system.
This file specifies default config options for quantization auto-tuning tool. User should not change values in this file. Instead, user should write a config file (in yaml) and use cfg_from_file(yaml_file) to load it and override the default options.
Module Contents¶
Classes¶
Lazy import python module till use. |
|
Get CPU Info. |
|
The statistics printer. |
|
Mode: Quantization, Benchmark or Pruning. |
|
Access the global model. |
Functions¶
|
Check whether version1 is less than version2. |
|
Check whether version1 is greater than version2. |
|
Check whether version1 is equal to version2. |
|
Check whether version1 is greater than version2 or is equal to it. |
|
Check whether version1 is less than version2 or is equal to it. |
|
Not displayed in API Docs. |
|
Limit the time for context execution. |
|
Recursively finds size of objects. |
|
Compute the sparsity. |
|
Make another temporary copy of the file. |
|
Check whether two dicts are same except for those ignored keys. |
|
Get the elapsed time for decorated functions. |
|
Collect layer histogram for arr and combine it with old histogram. |
|
Get the histogram of the tensor data. |
|
Get all the fp32 data. |
|
Get tuning history. |
|
Get offline recover tuned model. |
|
Get the array of the string. |
|
Dequantize the weight with min-max filter tensors. |
|
Dequantize the data with the scale_info. |
|
Load data from local pkl file. |
|
Dump data to local as pkl file. |
|
Set the random seed in config. |
|
Set the workspace in config. |
|
Set the resume_from in config. |
|
Set the tensorboard in config. |
- neural_compressor.utils.utility.version1_lt_version2(version1, version2)¶
Check whether version1 is less than version2.
- neural_compressor.utils.utility.version1_gt_version2(version1, version2)¶
Check whether version1 is greater than version2.
- neural_compressor.utils.utility.version1_eq_version2(version1, version2)¶
Check whether version1 is equal to version2.
- neural_compressor.utils.utility.version1_gte_version2(version1, version2)¶
Check whether version1 is greater than version2 or is equal to it.
- neural_compressor.utils.utility.version1_lte_version2(version1, version2)¶
Check whether version1 is less than version2 or is equal to it.
- class neural_compressor.utils.utility.LazyImport(module_name)¶
Bases:
object
Lazy import python module till use.
- neural_compressor.utils.utility.singleton(cls)¶
Not displayed in API Docs.
Singleton decorater.
- neural_compressor.utils.utility.time_limit(seconds)¶
Limit the time for context execution.
- neural_compressor.utils.utility.get_size(obj, seen=None)¶
Recursively finds size of objects.
- neural_compressor.utils.utility.compute_sparsity(tensor)¶
Compute the sparsity.
- Parameters:
tensor – Tensorflow or Pytorch tensor
- Returns:
(the original tensor size, number of zero elements, number of non-zero elements)
- neural_compressor.utils.utility.fault_tolerant_file(name)¶
Make another temporary copy of the file.
- neural_compressor.utils.utility.equal_dicts(d1, d2, compare_keys=None, ignore_keys=None)¶
Check whether two dicts are same except for those ignored keys.
- class neural_compressor.utils.utility.CpuInfo¶
Bases:
object
Get CPU Info.
- property bf16¶
Get whether it is bf16.
- property vnni¶
Get whether it is vnni.
- property cores_per_socket¶
Get the cores per socket.
- get_number_of_sockets() int ¶
Get number of sockets in platform.
- neural_compressor.utils.utility.dump_elapsed_time(customized_msg='')¶
Get the elapsed time for decorated functions.
- Parameters:
customized_msg (string, optional) – The parameter passed to decorator. Defaults to None.
- neural_compressor.utils.utility.combine_histogram(old_hist, arr)¶
Collect layer histogram for arr and combine it with old histogram.
- neural_compressor.utils.utility.get_tensor_histogram(tensor_data, bins=2048)¶
Get the histogram of the tensor data.
- neural_compressor.utils.utility.get_all_fp32_data(data)¶
Get all the fp32 data.
- neural_compressor.utils.utility.get_tuning_history(tuning_history_path)¶
Get tuning history.
- Parameters:
tuning_history_path – The tuning history path, which need users to assign
- neural_compressor.utils.utility.recover(fp32_model, tuning_history_path, num, **kwargs)¶
Get offline recover tuned model.
- Parameters:
fp32_model – Input model path
tuning_history_path – The tuning history path, which needs user to assign
num – tune index
- neural_compressor.utils.utility.str2array(s)¶
Get the array of the string.
- neural_compressor.utils.utility.DequantizeWeight(weight_tensor, min_filter_tensor, max_filter_tensor)¶
Dequantize the weight with min-max filter tensors.
- neural_compressor.utils.utility.Dequantize(data, scale_info)¶
Dequantize the data with the scale_info.
- class neural_compressor.utils.utility.Statistics(data, header, field_names, output_handle=logger.info)¶
The statistics printer.
- print_stat()¶
Print the statistics.
- class neural_compressor.utils.utility.MODE¶
Bases:
enum.Enum
Mode: Quantization, Benchmark or Pruning.
- class neural_compressor.utils.utility.GLOBAL_STATE¶
Access the global model.
- neural_compressor.utils.utility.load_data_from_pkl(path, filename)¶
Load data from local pkl file.
- Parameters:
path – The directory to load data
filename – The filename to load
- neural_compressor.utils.utility.dump_data_to_local(data, path, filename)¶
Dump data to local as pkl file.
- Parameters:
data – Data used to dump
path – The directory to save data
filename – The filename to dump
- Returns:
loaded data
- neural_compressor.utils.utility.set_random_seed(seed: int)¶
Set the random seed in config.
- neural_compressor.utils.utility.set_workspace(workspace: str)¶
Set the workspace in config.
- neural_compressor.utils.utility.set_resume_from(resume_from: str)¶
Set the resume_from in config.
- neural_compressor.utils.utility.set_tensorboard(tensorboard: bool)¶
Set the tensorboard in config.