Buckets:

hf-doc-build/doc / diffusers /v0.43.0 /zh /api /configuration.md
mishig's picture
|
download
raw
7.66 kB

配置

来自 SchedulerMixin 的调度器和来自 ModelMixin 的模型都继承自 ConfigMixin,后者会将传入其各自 __init__ 方法的所有参数存储在一个 JSON 配置文件中。

要使用私有或 受限 模型,请使用 hf auth login 登录。

ConfigMixin[[diffusers.ConfigMixin]]

diffusers.ConfigMixin[[diffusers.ConfigMixin]]

diffusers.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[[diffusers.ConfigMixin.load_config]]

load_config(pretrained_model_name_or_path: str | os.PathLike, return_unused_kwargs = False, return_commit_hash = False, **kwargs)

源代码

参数:

pretrained_model_name_or_path (str 或 os.PathLike,可选) : 可以是以下之一: - 一个字符串,即托管在 Hub 上的预训练模型的 model id(例如 google/ddpm-celebahq-256)。 - 一个指向 目录 的路径(例如 ./my_model_directory),其中包含使用 save_config() 保存的模型权重。

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 承载者授权令牌。如果为 True,则使用由 diffusers-cli login 生成的令牌(存储在 ~/.huggingface 中)。

revision (str,可选,默认为 "main"):要使用的特定模型版本。它可以是分支名称、标签名称、提交 ID,或 Git 允许的任何标识符。

subfolder (str,可选,默认为 ""):模型文件在 Hub 或本地的大型模型仓库中的子文件夹位置。

return_unused_kwargs (bool,可选,默认为 `False):是否返回配置中未使用的关键字参数。

return_commit_hash (bool, optional, defaults to False) : Whether the commit_hash` of the loaded configuration are returned.

返回: dict

存储在 JSON 配置文件中的所有参数的字典。

加载模型或调度器配置。

from_config[[diffusers.ConfigMixin.from_config]]

from_config(config: diffusers.configuration_utils.FrozenDict | dict[str, typing.Any] = None, return_unused_kwargs = False, **kwargs)

源代码

参数:

config (dict[str, Any]) : 用于实例化 Python 类的配置字典。请确保仅加载兼容类的配置文件。

return_unused_kwargs (bool,可选,默认为 False):是否返回未被 Python 类消费的 kwargs。

kwargs (其余关键字参数字典,可选):可用于在配置对象加载后对其进行更新,并初始化 Python 类。**kwargs 会直接传递给底层调度器/模型的 __init__ 方法,并最终覆盖 config 中同名的参数。

返回: ModelMixin 或 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[[diffusers.ConfigMixin.save_config]]

save_config(save_directory: str | os.PathLike, push_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[[diffusers.ConfigMixin.to_json_file]]

to_json_file(json_file_path: str | os.PathLike)

源代码

参数:

json_file_path (str 或 os.PathLike):用于保存配置实例参数的 JSON 文件路径。

将配置实例的参数保存到 JSON 文件中。

to_json_string[[diffusers.ConfigMixin.to_json_string]]

to_json_string()

源代码

返回: str

以 JSON 格式包含构成配置实例的所有属性的字符串。

将配置实例序列化为 JSON 字符串。

Xet Storage Details

Size:
7.66 kB
·
Xet hash:
2eac1682ab0d1fe8cea4949d7b3cad09095ae26eeeb4b2d3a1e71f05d0bbfcc2

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.