afe.core.utils

Attributes

T

Classes

LengthHintedIterable

Wrapper class, which wraps Iterables and their length hints. Used for length hint in our API.

Functions

parse_yaml(→ Dict)

dataclass_to_dict(_class)

load_configs_from_yaml(...)

dump_configs_to_yaml(→ None)

Dump the YAML file containing ModelConfigs and OptimizationConfigs to directory:

dump_yaml_npz(→ None)

Dump the yaml and npz to directory:

convert_data_generator_to_iterable(→ Iterable[Any])

Convert a data generator to an iterable object.

length_hinted(→ LengthHintedIterable[T])

Used to create Length hinted iterable, and use it on our API. Example of usage:

save_files(→ bool)

wrap_parameters_to_model_configs(...)

Given the list of model parameters, create ModelConfigs data structure.

wrap_parameters_to_transformer_configs(...)

Given the list of model transformation parameters, create TransformerConfigs data structure.

wrap_parameters_to_optimization_configs(...)

Given the list of model optimization parameters, create OptimizationConfigs data structure.

Module Contents

afe.core.utils.T[source]
afe.core.utils.parse_yaml(yaml_filepath: str) Dict[source]
afe.core.utils.dataclass_to_dict(_class)[source]
afe.core.utils.load_configs_from_yaml(file_path: str) Tuple[afe.core.configs.ModelConfigs, afe.core.configs.OptimizationConfigs][source]
afe.core.utils.dump_configs_to_yaml(model_config: afe.core.configs.ModelConfigs, opt_config: afe.core.configs.OptimizationConfigs) None[source]
Dump the YAML file containing ModelConfigs and OptimizationConfigs to directory:

{model_config.output_dir}/{model_config.model_name}.yaml

afe.core.utils.dump_yaml_npz(model_config: afe.core.configs.ModelConfigs, net: afe.ir.net.AwesomeNet | None = None, name_prefix: str = '', name_postfix: str = '') None[source]
Dump the yaml and npz to directory:

{model_config.output_dir}/{name_prefix}{model_config.model_name}{name_postfix}.yaml {model_config.output_dir}/{name_prefix}{model_config.model_name}{name_postfix}.npz

afe.core.utils.convert_data_generator_to_iterable(g: sima_utils.data.data_generator.DataGenerator, *, length_limit: int | None = None) Iterable[Any][source]

Convert a data generator to an iterable object.

Although DataGenerator has methods like an iterable object, it does not implement the iterable interface properly.

Parameters:
  • g – Data generator

  • length_limit – If not None, the maximum number of items to use from the data generator. Excess items are ignored.

Returns:

Iterable over the sequence g[0], g[1], …. The data generator must not be modified while the iterable is being used.

class afe.core.utils.LengthHintedIterable(length_hint: int, iterable: Iterable[T])[source]

Wrapper class, which wraps Iterables and their length hints. Used for length hint in our API. It is intended to be instantiated with method length_hinted(). model = loaded_net.quantize(length_hinted(24, data_source), default_quantization)

get_length()[source]
afe.core.utils.length_hinted(length_hint: int, iterable: Iterable[T]) LengthHintedIterable[T][source]

Used to create Length hinted iterable, and use it on our API. Example of usage: model = loaded_net.quantize(length_hinted(24, data_source), default_quantization) :param length_hint: Specified number of examples :param iterable: Input examples as Iterable.

afe.core.utils.save_files() bool[source]
afe.core.utils.wrap_parameters_to_model_configs(name: str, framework: str = '', input_names: List[str] | None = None, input_shapes: List[afe.ir.defines.InputShape] | None = None, input_dtypes: List[str] | None = None, layout: str = '', model_path: str = '', model_file_paths: List[str] | None = None, output_names: List[str] | None = None, output_directory: str | None = None, is_quantized: bool = False) afe.core.configs.ModelConfigs[source]

Given the list of model parameters, create ModelConfigs data structure.

Parameters:
  • name – str. Model name.

  • framework – str. Framework used in a model.

  • input_names – Optional[List[str]]. List of input names to a model, if any.

  • input_shapes – Optional[List[InputShape]]. List of input shapes, if any.

  • input_dtypes – Optional[List[str]]. List of input types to a model, if any.

  • layout – str. Data layout used in a model.

  • model_path – str. The file path from which the model is loaded.

  • model_file_paths – Optional[List[str]]. The file paths used for model loading. Used in cases where multiple files are needed to load a model.

  • output_names – Optional[List[str]]. List of output names, if any.

  • output_directory – Optional[str]. Output directory path used to store generated files, if any.

  • is_quantized – Whether the model is pre-quantized. Default is False

Returns:

ModelConfigs.

afe.core.utils.wrap_parameters_to_transformer_configs(indices_to_backend_dict: dict[int, afe.backends.Backend] | None = None) afe.core.configs.TransformerConfigs[source]

Given the list of model transformation parameters, create TransformerConfigs data structure.

Parameters:

indices_to_backend_dict – Optional[Dict[int, Backend]]. Dictionary containing mapping of layer indices to their targeted Backend, if any.

Returns:

TransformerConfigs.

afe.core.utils.wrap_parameters_to_optimization_configs(asymmetry: bool, per_channel: bool) afe.core.configs.OptimizationConfigs[source]

Given the list of model optimization parameters, create OptimizationConfigs data structure.

Parameters:
  • asymmetry – bool. Whether to use asymmetry in quantization.

  • per_channel – bool. Whether to use per channel quantization.

Returns:

OptimizationConfigs.