def from_yaml(cls, yml: Union[IO, str]) -> "OptimizationConfig":
        """
        Construct an ``OptimizationConfig`` instance from a YAML file.
        The YAML file 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 YAML file that creates an optimization config for weight palettization:

        ::

            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 YAML file:

        ::

            config_type: OpThresholdPrunerConfig
            global_config:
                threshold: 0.01
            op_type_configs:
                conv:
                    config_type: OpMagnitudePrunerConfig
                    n_m_ratio: [3, 4]

        Parameters
        ----------

        yml: str, IO
            A YAML file or the path to the file.
        """
        if isinstance(yml, str):
            with open(yml, "r") as file:
                config_dict = yaml.safe_load(file)
        else:
            config_dict = yaml.safe_load(yml)
        return cls.from_dict(config_dict)

        Construct an ``OptimizationConfig`` instance from a YAML file.
        The YAML file 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 YAML file that creates an optimization config for weight palettization:

        ::

            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 YAML file:

        ::

            config_type: OpThresholdPrunerConfig
            global_config:
                threshold: 0.01
            op_type_configs:
                conv:
                    config_type: OpMagnitudePrunerConfig
                    n_m_ratio: [3, 4]

        Parameters
        ----------

        yml: str, IO
            A YAML file or the path to the file.
        
coremltools/optimize/coreml/_config.py