neural_compressor.tensorflow.utils.utility

Module Contents

Classes

CpuInfo

Get CPU Info.

Statistics

The statistics printer.

CaptureOutputToFile

Not displayed in API Docs.

LazyImport

Lazy import python module till use.

Functions

version1_lt_version2(version1, version2)

Check whether version1 is less than version2.

version1_gt_version2(version1, version2)

Check whether version1 is greater than version2.

version1_eq_version2(version1, version2)

Check whether version1 is equal to version2.

version1_gte_version2(version1, version2)

Check whether version1 is greater than version2 or is equal to it.

version1_lte_version2(version1, version2)

Check whether version1 is less than version2 or is equal to it.

register_algo(name)

Decorator function to register algorithms in the algos_mapping dictionary.

deep_get(dictionary, keys[, default])

Get the dot key's item in nested dict

itex_installed()

Check if the Intel® Extension for TensorFlow has been installed.

dump_elapsed_time([customized_msg])

Get the elapsed time for decorated functions.

combine_histogram(old_hist, arr)

Collect layer histogram for arr and combine it with old histogram.

get_all_fp32_data(data)

Get all the fp32 data.

get_tensor_histogram(tensor_data[, bins])

Get the histogram of the tensor data.

Dequantize(data, scale_info)

Dequantize the data with the scale_info.

dequantize_weight(weight_tensor, min_filter_tensor, ...)

Dequantize the weight with min-max filter tensors.

dump_data_to_local(data, path, filename)

Dump data to local as pkl file.

load_data_from_pkl(path, filename)

Load data from local pkl file.

singleton(cls)

Not displayed in API Docs.

disable_random([seed])

A Decorator to disable tf random seed.

valid_keras_format(model)

Check if the input model is Sequential or Functional model.

neural_compressor.tensorflow.utils.utility.version1_lt_version2(version1, version2)[source]

Check whether version1 is less than version2.

neural_compressor.tensorflow.utils.utility.version1_gt_version2(version1, version2)[source]

Check whether version1 is greater than version2.

neural_compressor.tensorflow.utils.utility.version1_eq_version2(version1, version2)[source]

Check whether version1 is equal to version2.

neural_compressor.tensorflow.utils.utility.version1_gte_version2(version1, version2)[source]

Check whether version1 is greater than version2 or is equal to it.

neural_compressor.tensorflow.utils.utility.version1_lte_version2(version1, version2)[source]

Check whether version1 is less than version2 or is equal to it.

neural_compressor.tensorflow.utils.utility.register_algo(name)[source]

Decorator function to register algorithms in the algos_mapping dictionary.

Usage example:

@register_algo(name=example_algo) def example_algo(model: tf.keras.Model, quant_config: StaticQuantConfig) -> tf.keras.Model:

Parameters:

name (str) – The name under which the algorithm function will be registered.

Returns:

The decorator function to be used with algorithm functions.

Return type:

decorator

neural_compressor.tensorflow.utils.utility.deep_get(dictionary, keys, default=None)[source]
Get the dot key’s item in nested dict

eg person = {‘person’:{‘name’:{‘first’:’John’}}} deep_get(person, “person.name.first”) will output ‘John’.

Parameters:
  • dictionary (dict) – The dict object to get keys

  • keys (dict) – The deep keys

  • default (object) – The return item if key not exists

Returns:

the item of the deep dot keys

Return type:

item

neural_compressor.tensorflow.utils.utility.itex_installed()[source]

Check if the Intel® Extension for TensorFlow has been installed.

neural_compressor.tensorflow.utils.utility.dump_elapsed_time(customized_msg='')[source]

Get the elapsed time for decorated functions.

Parameters:

customized_msg (string, optional) – The parameter passed to decorator. Defaults to None.

neural_compressor.tensorflow.utils.utility.combine_histogram(old_hist, arr)[source]

Collect layer histogram for arr and combine it with old histogram.

neural_compressor.tensorflow.utils.utility.get_all_fp32_data(data)[source]

Get all the fp32 data.

neural_compressor.tensorflow.utils.utility.get_tensor_histogram(tensor_data, bins=2048)[source]

Get the histogram of the tensor data.

neural_compressor.tensorflow.utils.utility.Dequantize(data, scale_info)[source]

Dequantize the data with the scale_info.

neural_compressor.tensorflow.utils.utility.dequantize_weight(weight_tensor, min_filter_tensor, max_filter_tensor)[source]

Dequantize the weight with min-max filter tensors.

neural_compressor.tensorflow.utils.utility.dump_data_to_local(data, path, filename)[source]

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.tensorflow.utils.utility.load_data_from_pkl(path, filename)[source]

Load data from local pkl file.

Parameters:
  • path – The directory to load data

  • filename – The filename to load

neural_compressor.tensorflow.utils.utility.singleton(cls)[source]

Not displayed in API Docs.

Singleton decorator.

neural_compressor.tensorflow.utils.utility.disable_random(seed=1)[source]

A Decorator to disable tf random seed.

neural_compressor.tensorflow.utils.utility.valid_keras_format(model)[source]

Check if the input model is Sequential or Functional model.

class neural_compressor.tensorflow.utils.utility.CpuInfo[source]

Get CPU Info.

class neural_compressor.tensorflow.utils.utility.Statistics(data, header, field_names, output_handle=logger.info)[source]

The statistics printer.

class neural_compressor.tensorflow.utils.utility.CaptureOutputToFile(tmp_file_path, stream=sys.stderr)[source]

Not displayed in API Docs.

Capture the output to file.

class neural_compressor.tensorflow.utils.utility.LazyImport(module_name)[source]

Lazy import python module till use.