def from_dict(cls, config_dict: Dict[str, Any]) -> "OptimizationConfig":
        """
        Construct an ``OptimizationConfig`` instance from a nested dictionary.
        The dictionary should have the structure that only contains (if any) the following four ``str`` keys:

        * ``"config_type"``: Specify the configuration class type.
        * ``"global_config"``: Parameters for ``global_config``.
        * ``"op_type_configs"``: A nested dictionary for ``op_type_configs``.
        * ``"op_name_config"``: A nested dictionary for ``op_name_configs``.

        The following is a nested dictionary that creates an optimization config for weight palettization:

        .. code-block:: python

            config_dict = {
                "config_type": "OpPalettizerConfig",
                "global_config": {
                    "mode": "kmeans",
                    "nbits": 4,
                },
                "op_type_configs": {
                    "conv": {
                        "mode": "uniform",
                        "nbits": 1,
                    }
                },
                "op_name_configs": {
                    "conv_1": {
                        "mode": "unique",
                    }
                },
            }

        Note that you can override the ``config_type``. For instance, if you want to do threshold-based
        pruning to the model in addition to the convolution layers in which magnitude pruning is applied, the following is an
        example of the nested dictionary:

        .. code-block:: python

            config_dict = {
                "config_type": "OpThresholdPrunerConfig",
                "global_config": {
                    "threshold": 0.01,
                },
                "op_type_configs": {
                    "conv": {
                        "config_type": "OpMagnitudePrunerConfig",
                        "n_m_ratio": [3, 4],
                    }
                },
            }

        Parameters
        ----------

        config_dict: dict[str, Any]
            A dictionary that represents the configuration structure.
        """
        def _get_cls_instance(cls_type, cls_attrs):
            if cls_attrs is None:
                return None
            converter = cattrs.Converter(forbid_extra_keys=True)
            if "config_type" in cls_attrs:
                cls_type = cls_attrs["config_type"]
                del cls_attrs["config_type"]
            class_type = getattr(sys.modules[__name__], cls_type)
            return class_type._from_dict(cls_attrs)

        def _check_config_dict(config_dict):
            valid_keys = ("config_type", "global_config", "op_name_configs", "op_type_configs")
            for k in config_dict:
                if k not in valid_keys:
                    raise ValueError(
                        f"Invalid key {k} to construct an OptimizationConfig object. Supported keys are {valid_keys}."
                    )

        _check_config_dict(config_dict)

        config_type = config_dict.get("config_type", None)
        if config_type is None or not isinstance(config_type, str):
            raise ValueError("config_type must be provided with type of string.")

        cls_attrs = {}
        if config_dict.get("global_config", None) is not None:
            cls_attrs["global_config"] = _get_cls_instance(
                config_type, config_dict["global_config"]
            )
        for key in ["op_type_configs", "op_name_configs"]:
            if config_dict.get(key, None) is None:
                continue
            if not isinstance(config_dict[key], dict):
                raise ValueError(f"{key} must be type of dict. Got {type(config_dict[key])}")
            cls_attrs[key] = {
                k: _get_cls_instance(config_type, v) for k, v in config_dict[key].items()
            }

        return cls(**cls_attrs)

        Construct an ``OptimizationConfig`` instance from a nested dictionary.
        The dictionary should have the structure that only contains (if any) the following four ``str`` keys:

        * ``"config_type"``: Specify the configuration class type.
        * ``"global_config"``: Parameters for ``global_config``.
        * ``"op_type_configs"``: A nested dictionary for ``op_type_configs``.
        * ``"op_name_config"``: A nested dictionary for ``op_name_configs``.

        The following is a nested dictionary that creates an optimization config for weight palettization:

        .. code-block:: python

            config_dict = {
                "config_type": "OpPalettizerConfig",
                "global_config": {
                    "mode": "kmeans",
                    "nbits": 4,
                },
                "op_type_configs": {
                    "conv": {
                        "mode": "uniform",
                        "nbits": 1,
                    }
                },
                "op_name_configs": {
                    "conv_1": {
                        "mode": "unique",
                    }
                },
            }

        Note that you can override the ``config_type``. For instance, if you want to do threshold-based
        pruning to the model in addition to the convolution layers in which magnitude pruning is applied, the following is an
        example of the nested dictionary:

        .. code-block:: python

            config_dict = {
                "config_type": "OpThresholdPrunerConfig",
                "global_config": {
                    "threshold": 0.01,
                },
                "op_type_configs": {
                    "conv": {
                        "config_type": "OpMagnitudePrunerConfig",
                        "n_m_ratio": [3, 4],
                    }
                },
            }

        Parameters
        ----------

        config_dict: dict[str, Any]
            A dictionary that represents the configuration structure.
        
coremltools/optimize/coreml/_config.py