def from_yaml(cls, yml: _Union[_IO, str]) -> "DictableDataClass":
        """
        Create class from a yaml stream.

        Args:
            yml: An :py:class:`IO` stream containing yaml or a :obj:`str`
                path to the yaml file.
        """
        if isinstance(yml, str):
            with open(yml, "r") as file:
                dict_from_yml = _yaml.safe_load(file)
        else:
            dict_from_yml = _yaml.safe_load(yml)
        if dict_from_yml is None:
            dict_from_yml = {}
        assert isinstance(dict_from_yml, dict), (
            "Invalid yaml received. yaml stream should return a dict "
            f"on parsing. Received type: {type(dict_from_yml)}."
        )
        return cls.from_dict(dict_from_yml)

        Create class from a yaml stream.

        Args:
            yml: An :py:class:`IO` stream containing yaml or a :obj:`str`
                path to the yaml file.
        
coremltools/optimize/torch/_utils/python_utils.py