Diffusers 文件

配置

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

配置

來自 SchedulerMixin 的排程器和來自 ModelMixin 的模型都繼承自 ConfigMixin,它將所有傳遞給其各自 __init__ 方法的引數儲存在一個 JSON 配置檔案中。

要使用私有或封閉模型,請使用 huggingface-cli login 登入。

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

< >

( pretrained_model_name_or_path: typing.Union[str, os.PathLike] return_unused_kwargs = False return_commit_hash = False **kwargs ) dict

引數

  • pretrained_model_name_or_path (stros.PathLike, 可選) — 可以是:

    • Hub 上託管的預訓練模型的模型ID字串(例如 google/ddpm-celebahq-256)。
    • 包含使用 save_config() 儲存的模型權重的目錄路徑(例如 ./my_model_directory)。
  • cache_dir (Union[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 (strbool, 可選) — 用於遠端檔案的 HTTP bearer 授權令牌。如果為 True,則使用從 diffusers-cli login 生成的令牌(儲存在 ~/.huggingface 中)。
  • revision (str, 可選, 預設為 "main") — 要使用的特定模型版本。它可以是分支名稱、標籤名稱、提交ID或Git允許的任何識別符號。
  • subfolder (str, 可選, 預設為 "") — 模型檔案在 Hub 或本地較大模型倉庫中的子資料夾位置。
  • return_unused_kwargs (bool, 可選, 預設為 False) — 是否返回配置中未使用的關鍵字引數。
  • return_commit_hash (bool, 可選, 預設為 False) — 是否返回載入配置的 commit_hash

返回

字典

儲存在 JSON 配置檔案中的所有引數的字典。

載入模型或排程器配置。

from_config

< >

( config: typing.Union[diffusers.configuration_utils.FrozenDict, typing.Dict[str, typing.Any]] = None return_unused_kwargs = False **kwargs ) ModelMixinSchedulerMixin

引數

  • config (Dict[str, Any]) — 從中例項化 Python 類的配置字典。確保僅載入相容類的配置檔案。
  • return_unused_kwargs (bool, 可選, 預設為 False) — 是否返回未被 Python 類使用的 kwargs。
  • kwargs (剩餘的關鍵字引數字典, 可選) — 可用於更新配置物件(載入後)並初始化 Python 類。**kwargs 直接傳遞給底層排程器/模型的 __init__ 方法,並最終覆蓋 config 中同名的引數。

返回

ModelMixinSchedulerMixin

從配置字典例項化的模型或排程器物件。

從配置字典例項化 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

< >

( save_directory: typing.Union[str, os.PathLike] push_to_hub: bool = False **kwargs )

引數

  • save_directory (stros.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

< >

( json_file_path: typing.Union[str, os.PathLike] )

引數

  • json_file_path (stros.PathLike) — 儲存配置例項引數的 JSON 檔案路徑。

將配置例項的引數儲存到 JSON 檔案。

to_json_string

< >

( ) str

返回

字串

包含所有構成配置例項的屬性的 JSON 格式字串。

將配置例項序列化為 JSON 字串。

< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.