r""" Instantiate a model from a config dictionary or a pretrained model configuration file with random weights (no pretrained weights are loaded). Parameters: pretrained_model_name_or_path_or_dict (`str`, `os.PathLike`, or `dict`): Can be either:
(cls, pretrained_model_name_or_path_or_dict: str | os.PathLike | dict | None = None, **kwargs)
| 37 | |
| 38 | @classmethod |
| 39 | def from_config(cls, pretrained_model_name_or_path_or_dict: str | os.PathLike | dict | None = None, **kwargs): |
| 40 | r""" |
| 41 | Instantiate a model from a config dictionary or a pretrained model configuration file with random weights (no |
| 42 | pretrained weights are loaded). |
| 43 | |
| 44 | Parameters: |
| 45 | pretrained_model_name_or_path_or_dict (`str`, `os.PathLike`, or `dict`): |
| 46 | Can be either: |
| 47 | |
| 48 | - A string, the *model id* (for example `google/ddpm-celebahq-256`) of a pretrained model |
| 49 | configuration hosted on the Hub. |
| 50 | - A path to a *directory* (for example `./my_model_directory`) containing a model configuration |
| 51 | file. |
| 52 | - A config dictionary. |
| 53 | |
| 54 | cache_dir (`Union[str, os.PathLike]`, *optional*): |
| 55 | Path to a directory where a downloaded pretrained model configuration is cached if the standard cache |
| 56 | is not used. |
| 57 | force_download (`bool`, *optional*, defaults to `False`): |
| 58 | Whether or not to force the (re-)download of the model configuration, overriding the cached version if |
| 59 | it exists. |
| 60 | proxies (`Dict[str, str]`, *optional*): |
| 61 | A dictionary of proxy servers to use by protocol or endpoint. |
| 62 | local_files_only(`bool`, *optional*, defaults to `False`): |
| 63 | Whether to only load local model configuration files or not. |
| 64 | token (`str` or *bool*, *optional*): |
| 65 | The token to use as HTTP bearer authorization for remote files. |
| 66 | revision (`str`, *optional*, defaults to `"main"`): |
| 67 | The specific model version to use. |
| 68 | trust_remote_code (`bool`, *optional*, defaults to `False`): |
| 69 | Whether to trust remote code. |
| 70 | subfolder (`str`, *optional*, defaults to `""`): |
| 71 | The subfolder location of a model file within a larger model repository on the Hub or locally. |
| 72 | |
| 73 | Returns: |
| 74 | A model object instantiated from the config with random weights. |
| 75 | |
| 76 | Example: |
| 77 | |
| 78 | ```py |
| 79 | from diffusers import AutoModel |
| 80 | |
| 81 | model = AutoModel.from_config("stable-diffusion-v1-5/stable-diffusion-v1-5", subfolder="unet") |
| 82 | ``` |
| 83 | """ |
| 84 | subfolder = kwargs.pop("subfolder", None) |
| 85 | trust_remote_code = kwargs.pop("trust_remote_code", False) |
| 86 | |
| 87 | hub_kwargs_names = [ |
| 88 | "cache_dir", |
| 89 | "force_download", |
| 90 | "local_files_only", |
| 91 | "proxies", |
| 92 | "revision", |
| 93 | "token", |
| 94 | ] |
| 95 | hub_kwargs = {name: kwargs.pop(name, None) for name in hub_kwargs_names} |
| 96 |