neural_compressor.common.utils.utility

The utility of common module.

Classes

LazyImport

Lazy import python module till use.

CpuInfo

Get CPU Info.

ProcessorType

The processor type.

Statistics

The statistics printer.

Functions

singleton(cls)

Singleton decorator.

dump_elapsed_time([customized_msg])

Get the elapsed time for decorated functions.

set_random_seed(seed)

Set the random seed in config.

set_workspace(workspace)

Set the workspace in config.

get_workspace()

Get the workspace in config.

set_resume_from(resume_from)

Set the resume_from in config.

set_tensorboard(tensorboard)

Set the tensorboard in config.

log_process([mode])

Decorator function that logs the stage of process.

call_counter(func)

A decorator that keeps track of the number of times a function is called.

detect_processor_type_based_on_hw()

Detects the processor type based on the hardware configuration.

Module Contents

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

Singleton decorator.

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

Lazy import python module till use.

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

Get CPU Info.

neural_compressor.common.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.common.utils.utility.set_random_seed(seed: int)[source]

Set the random seed in config.

neural_compressor.common.utils.utility.set_workspace(workspace: str)[source]

Set the workspace in config.

neural_compressor.common.utils.utility.get_workspace()[source]

Get the workspace in config.

neural_compressor.common.utils.utility.set_resume_from(resume_from: str)[source]

Set the resume_from in config.

neural_compressor.common.utils.utility.set_tensorboard(tensorboard: bool)[source]

Set the tensorboard in config.

neural_compressor.common.utils.utility.log_process(mode=Mode.QUANTIZE)[source]

Decorator function that logs the stage of process.

Parameters:

mode (Mode) – The mode of the process.

Returns:

The decorated function.

neural_compressor.common.utils.utility.call_counter(func)[source]

A decorator that keeps track of the number of times a function is called.

Parameters:

func – The function to be decorated.

Returns:

The decorated function.

class neural_compressor.common.utils.utility.ProcessorType[source]

The processor type.

neural_compressor.common.utils.utility.detect_processor_type_based_on_hw()[source]

Detects the processor type based on the hardware configuration.

Returns:

The detected processor type (Server or Client).

Return type:

ProcessorType

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

The statistics printer.