afe.core.utils ============== .. py:module:: afe.core.utils Attributes ---------- .. autoapisummary:: afe.core.utils.T Classes ------- .. autoapisummary:: afe.core.utils.LengthHintedIterable Functions --------- .. autoapisummary:: afe.core.utils.parse_yaml afe.core.utils.dataclass_to_dict afe.core.utils.load_configs_from_yaml afe.core.utils.dump_configs_to_yaml afe.core.utils.dump_yaml_npz afe.core.utils.convert_data_generator_to_iterable afe.core.utils.length_hinted afe.core.utils.save_files afe.core.utils.wrap_parameters_to_model_configs afe.core.utils.wrap_parameters_to_transformer_configs afe.core.utils.wrap_parameters_to_optimization_configs Module Contents --------------- .. py:data:: T .. py:function:: parse_yaml(yaml_filepath: str) -> Dict .. py:function:: dataclass_to_dict(_class) .. py:function:: load_configs_from_yaml(file_path: str) -> Tuple[afe.core.configs.ModelConfigs, afe.core.configs.OptimizationConfigs] .. py:function:: dump_configs_to_yaml(model_config: afe.core.configs.ModelConfigs, opt_config: afe.core.configs.OptimizationConfigs) -> None Dump the YAML file containing ModelConfigs and OptimizationConfigs to directory: {model_config.output_dir}/{model_config.model_name}.yaml .. py:function:: dump_yaml_npz(model_config: afe.core.configs.ModelConfigs, net: Optional[afe.ir.net.AwesomeNet] = None, name_prefix: str = '', name_postfix: str = '') -> None 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 .. py:function:: convert_data_generator_to_iterable(g: sima_utils.data.data_generator.DataGenerator, *, length_limit: Optional[int] = None) -> Iterable[Any] Convert a data generator to an iterable object. Although DataGenerator has methods like an iterable object, it does not implement the iterable interface properly. :param g: Data generator :param length_limit: If not None, the maximum number of items to use from the data generator. Excess items are ignored. :return: Iterable over the sequence g[0], g[1], .... The data generator must not be modified while the iterable is being used. .. py:class:: LengthHintedIterable(length_hint: int, iterable: Iterable[T]) 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) .. py:method:: get_length() .. py:function:: length_hinted(length_hint: int, iterable: Iterable[T]) -> LengthHintedIterable[T] 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. .. py:function:: save_files() -> bool .. py:function:: wrap_parameters_to_model_configs(name: str, framework: str = '', input_names: Optional[List[str]] = None, input_shapes: Optional[List[afe.ir.defines.InputShape]] = None, input_dtypes: Optional[List[str]] = None, layout: str = '', model_path: str = '', model_file_paths: Optional[List[str]] = None, output_names: Optional[List[str]] = None, output_directory: Optional[str] = None, is_quantized: bool = False) -> afe.core.configs.ModelConfigs Given the list of model parameters, create ModelConfigs data structure. :param name: str. Model name. :param framework: str. Framework used in a model. :param input_names: Optional[List[str]]. List of input names to a model, if any. :param input_shapes: Optional[List[InputShape]]. List of input shapes, if any. :param input_dtypes: Optional[List[str]]. List of input types to a model, if any. :param layout: str. Data layout used in a model. :param model_path: str. The file path from which the model is loaded. :param 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. :param output_names: Optional[List[str]]. List of output names, if any. :param output_directory: Optional[str]. Output directory path used to store generated files, if any. :param is_quantized: Whether the model is pre-quantized. Default is False :return: ModelConfigs. .. py:function:: wrap_parameters_to_transformer_configs(indices_to_backend_dict: dict[int, afe.backends.Backend] | None = None) -> afe.core.configs.TransformerConfigs Given the list of model transformation parameters, create TransformerConfigs data structure. :param indices_to_backend_dict: Optional[Dict[int, Backend]]. Dictionary containing mapping of layer indices to their targeted Backend, if any. :return: TransformerConfigs. .. py:function:: wrap_parameters_to_optimization_configs(asymmetry: bool, per_channel: bool) -> afe.core.configs.OptimizationConfigs Given the list of model optimization parameters, create OptimizationConfigs data structure. :param asymmetry: bool. Whether to use asymmetry in quantization. :param per_channel: bool. Whether to use per channel quantization. :return: OptimizationConfigs.