Schedulers from SchedulerMixin and models from ModelMixin inherit from ConfigMixin which conveniently takes care of storing all the parameters that are
passed to their respective __init__
methods in a JSON-configuration file.
Base class for all configuration classes. Stores all configuration parameters under self.config
Also handles all
methods for loading/downloading/saving classes inheriting from ConfigMixin with
Class attributes:
str
) — A filename under which the config should stored when calling
save_config() (should be overridden by parent class).List[str]
) — A list of attributes that should not be saved in the config (should be
overridden by subclass).bool
) — Whether the class has compatible classes (should be overridden by subclass).List[str]
) — Keyword arguments that are deprecated. Note that the init function
should only have a kwargs
argument if at least one argument is deprecated (should be overridden by
subclass).(
pretrained_model_name_or_path: typing.Union[str, os.PathLike]
return_unused_kwargs = False
return_commit_hash = False
**kwargs
)
→
dict
Parameters
str
or os.PathLike
, optional) —
Can be either:
google/ddpm-celebahq-256
) of a pretrained model hosted on
the Hub../my_model_directory
) containing model weights saved with
save_config().Union[str, os.PathLike]
, optional) —
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
is not used.
bool
, optional, defaults to False
) —
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
cached versions if they exist.
bool
, optional, defaults to False
) —
Whether or not to resume downloading the model weights and configuration files. If set to False, any
incompletely downloaded files are deleted.
Dict[str, str]
, optional) —
A dictionary of proxy servers to use by protocol or endpoint, for example, {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}
. The proxies are used on each request.
bool
, optional, defaults to False
) —
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
bool
, optional, defaults to False
) —
Whether to only load local model weights and configuration files or not. If set to True, the model
won’t be downloaded from the Hub.
str
or bool, optional) —
The token to use as HTTP bearer authorization for remote files. If True
, the token generated from
diffusers-cli login
(stored in ~/.huggingface
) is used.
str
, optional, defaults to "main"
) —
The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
allowed by Git.
str
, optional, defaults to ""
) —
The subfolder location of a model file within a larger model repository on the Hub or locally.
bool
, optional, defaults to `False) —
Whether unused keyword arguments of the config are returned.
bool
, optional, defaults to False) -- Whether the
commit_hash` of the loaded configuration are returned.
Returns
dict
A dictionary of all the parameters stored in a JSON configuration file.
Load a model or scheduler configuration.
To use private or gated models, log-in with
huggingface-cli login
. You can also activate the special
“offline-mode” to use this method in a
firewalled environment.
( config: typing.Union[diffusers.configuration_utils.FrozenDict, typing.Dict[str, typing.Any]] = None return_unused_kwargs = False **kwargs ) → ModelMixin or SchedulerMixin
Parameters
Dict[str, Any]
) —
A config dictionary from which the Python class will be instantiated. Make sure to only load
configuration files of compatible classes.
bool
, optional, defaults to False
) —
Whether kwargs that are not consumed by the Python class should be returned or not.
**kwargs
are directly passed to the underlying scheduler/model’s __init__
method and eventually
overwrite same named arguments in config
.
Returns
A model or scheduler object instantiated from a config dictionary.
Instantiate a Python class from a config dictionary.
Examples:
>>> from diffusers import DDPMScheduler, DDIMScheduler, PNDMScheduler
>>> # Download scheduler from huggingface.co and cache.
>>> scheduler = DDPMScheduler.from_pretrained("google/ddpm-cifar10-32")
>>> # Instantiate DDIM scheduler class with same config as DDPM
>>> scheduler = DDIMScheduler.from_config(scheduler.config)
>>> # Instantiate PNDM scheduler class with same config as DDPM
>>> scheduler = PNDMScheduler.from_config(scheduler.config)
( save_directory: typing.Union[str, os.PathLike] push_to_hub: bool = False **kwargs )
Save a configuration object to the directory save_directory
, so that it can be re-loaded using the
from_config() class method.
( json_file_path: typing.Union[str, os.PathLike] )
Save this instance to a JSON file.
(
)
→
str
Returns
str
String containing all the attributes that make up this configuration instance in JSON format.
Serializes this instance to a JSON string.