配置
来自 SchedulerMixin 的调度器和来自 ModelMixin 的模型都继承自 ConfigMixin,后者会将传入其各自 __init__ 方法的所有参数存储在一个 JSON 配置文件中。
要使用私有或 受限 模型,请使用
hf auth login登录。
ConfigMixin
所有配置类的基类。所有配置参数都存储在 self.config 下。同时提供 from_config() 和 save_config() 方法,用于加载、下载和保存继承自 ConfigMixin 的类。
类属性:
- config_name (
str) — 调用 save_config() 时用于存储配置的配置文件名(应由父类覆盖)。 - ignore_for_config (
list[str]) — 不应保存在配置中的属性列表(应由子类覆盖)。 - has_compatibles (
bool) — 该类是否具有兼容类(应由子类重写)。 - _deprecated_kwargs (
list[str]) — 已弃用的关键字参数。请注意,init函数只有在至少有一个参数被弃用时才应包含kwargs参数(应由子类覆盖)。
load_config
< source >( pretrained_model_name_or_path: str | os.PathLikereturn_unused_kwargs = Falsereturn_commit_hash = False**kwargs ) → dict
参数
- pretrained_model_name_or_path (
str或os.PathLike, 可选) — 可以是以下之一:- 一个字符串,即托管在 Hub 上的预训练模型的 model id(例如
google/ddpm-celebahq-256)。 - 指向一个目录的路径(例如
./my_model_directory),其中包含使用 save_config() 保存的模型权重。
- 一个字符串,即托管在 Hub 上的预训练模型的 model id(例如
- cache_dir (
str | os.PathLike, 可选) — 如果未使用标准缓存,则下载的预训练模型配置将被缓存到的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, 可选,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only (
bool,可选,默认为False) — 是否仅加载本地的模型权重和配置文件。如果设置为True,则不会从 Hub 下载模型。 - token (
str或 bool,可选) — 用于远程文件的 HTTP bearer 授权令牌。如果为True,则使用由diffusers-cli login生成的令牌(存储在~/.huggingface中)。 - revision (
str, 可选, 默认为"main") — 要使用的特定模型版本。它可以是分支名称、标签名称、提交 id,或 Git 允许的任何标识符。 - subfolder (
str,可选,默认为"") — 模型文件在 Hub 或本地更大的模型仓库中的子文件夹位置。 - return_unused_kwargs (
bool,可选,默认为 `False) — 是否返回配置中未使用的关键字参数。 - return_commit_hash (
bool, optional, defaults toFalse) -- Whether thecommit_hash` of the loaded configuration are returned.
返回值
dict
存储在 JSON 配置文件中的所有参数的字典。
加载模型或调度器配置。
from_config
< source >( config: diffusers.configuration_utils.FrozenDict | dict[str, typing.Any] = Nonereturn_unused_kwargs = False**kwargs ) → ModelMixin or SchedulerMixin
从配置字典实例化一个 Python 类。
示例:
>>> 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_config
< source >( save_directory: str | os.PathLikepush_to_hub: bool = False**kwargs )
参数
- save_directory (
str或os.PathLike) — 保存配置 JSON 文件的目录(如果该目录不存在,将会创建)。 - push_to_hub (
bool,可选,默认为False) — 是否在保存模型后将其推送到 Hugging Face Hub。您可以使用repo_id指定要推送到的仓库(默认使用您命名空间中save_directory的名称)。 - kwargs (
dict[str, Any],可选) — 传递给 push_to_hub() 方法的额外关键字参数。
将配置对象保存到 save_directory 指定的目录中,以便使用 from_config() 类方法重新加载。
to_json_file
< source >( json_file_path: str | os.PathLike )
将配置实例的参数保存到 JSON 文件中。
将配置实例序列化为 JSON 字符串。