Diffusers 文件

Würstchen

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

Würstchen

LoRA

Wuerstchen: 用於大規模文字到影像擴散的高效架構模型 由 Pablo Pernias, Dominic Rampas, Mats L. Richter, Christopher Pal 和 Marc Aubreville 撰寫。

論文摘要如下:

我們引入了 Würstchen,這是一種用於文字到影像合成的新型架構,它結合了競爭效能和前所未有的大規模文字到影像擴散模型成本效益。我們工作的一個關鍵貢獻是開發了一種潛在擴散技術,在該技術中,我們學習了一種詳細但極其緊湊的語義影像表示,用於指導擴散過程。與語言的潛在表示相比,這種高度壓縮的影像表示提供了更詳細的指導,這顯著降低了實現最先進結果所需的計算要求。我們的方法還根據我們的使用者偏好研究改進了文字條件影像生成的質量。我們方法的訓練需求包括 24,602 個 A100-GPU 小時——而 Stable Diffusion 2.1 需要 200,000 個 GPU 小時。我們的方法也需要更少的訓練資料才能獲得這些結果。此外,我們緊湊的潛在表示使我們的推理速度提高了一倍以上,大大降低了最先進 (SOTA) 擴散模型的通常成本和碳足跡,而不會影響最終效能。在與 SOTA 模型的更廣泛比較中,我們的方法效率更高,並在影像質量方面表現良好。我們相信這項工作促使人們更加重視效能和計算可訪問性的優先排序。

Würstchen 概述

Würstchen 是一種擴散模型,其文字條件模型在高度壓縮的影像潛在空間中工作。這為什麼重要?壓縮資料可以成倍地降低訓練和推理的計算成本。在 1024x1024 影像上訓練比在 32x32 影像上訓練昂貴得多。通常,其他工作使用相對較小的壓縮,空間壓縮範圍為 4 倍 - 8 倍。Würstchen 將其推向了極致。透過其新穎的設計,我們實現了 42 倍的空間壓縮。這在以前是前所未有的,因為常見方法在 16 倍空間壓縮後無法忠實地重建詳細影像。Würstchen 採用兩階段壓縮,我們稱之為階段 A 和階段 B。階段 A 是 VQGAN,階段 B 是擴散自編碼器(更多細節可在論文中找到)。第三個模型,階段 C,在那個高度壓縮的潛在空間中學習。這種訓練所需的計算量僅為當前頂級模型所需計算量的一小部分,同時還允許更便宜、更快的推理。

Würstchen v2 登陸 Diffusers

在最初的論文釋出之後,我們改進了架構、訓練和取樣中的許多方面,使 Würstchen 在許多方面與當前最先進的模型具有競爭力。我們很高興與 Diffusers 一起釋出這個新版本。以下是改進列表。

  • 更高解析度(1024x1024 到 2048x2048)
  • 更快的推理
  • 多縱橫比解析度取樣
  • 更好的質量

我們正在釋出文字條件影像生成模型(階段 C)的 3 個檢查點。它們是:

  • v2-base
  • v2-aesthetic
  • (預設)v2-interpolated(v2-base 和 v2-aesthetic 之間的 50% 插值)

我們建議使用 v2-interpolated,因為它兼具照片真實感和美感。v2-base 適用於微調,因為它沒有風格偏見;v2-aesthetic 適用於非常藝術化的生成。比較結果如下:

文字到影像生成

為了便於使用,Würstchen 可以與單個管道一起使用。該管道可以按如下方式使用:

import torch
from diffusers import AutoPipelineForText2Image
from diffusers.pipelines.wuerstchen import DEFAULT_STAGE_C_TIMESTEPS

pipe = AutoPipelineForText2Image.from_pretrained("warp-ai/wuerstchen", torch_dtype=torch.float16).to("cuda")

caption = "Anthropomorphic cat dressed as a fire fighter"
images = pipe(
    caption,
    width=1024,
    height=1536,
    prior_timesteps=DEFAULT_STAGE_C_TIMESTEPS,
    prior_guidance_scale=4.0,
    num_images_per_prompt=2,
).images

出於解釋目的,我們還可以單獨初始化 Würstchen 的兩個主要管道。Würstchen 由 3 個階段組成:階段 C、階段 B、階段 A。它們都有不同的作用,並且只有協同工作。當生成文字條件影像時,階段 C 將首先在高度壓縮的潛在空間中生成潛在表示。這就是 `prior_pipeline` 中發生的情況。然後,生成的潛在表示將傳遞給階段 B,它將潛在表示解壓縮到 VQGAN 的更大潛在空間中。這些潛在表示然後可以由 VQGAN(即階段 A)解碼為畫素空間。階段 B 和階段 A 都封裝在 `decoder_pipeline` 中。有關更多詳細資訊,請參閱論文

import torch
from diffusers import WuerstchenDecoderPipeline, WuerstchenPriorPipeline
from diffusers.pipelines.wuerstchen import DEFAULT_STAGE_C_TIMESTEPS

device = "cuda"
dtype = torch.float16
num_images_per_prompt = 2

prior_pipeline = WuerstchenPriorPipeline.from_pretrained(
    "warp-ai/wuerstchen-prior", torch_dtype=dtype
).to(device)
decoder_pipeline = WuerstchenDecoderPipeline.from_pretrained(
    "warp-ai/wuerstchen", torch_dtype=dtype
).to(device)

caption = "Anthropomorphic cat dressed as a fire fighter"
negative_prompt = ""

prior_output = prior_pipeline(
    prompt=caption,
    height=1024,
    width=1536,
    timesteps=DEFAULT_STAGE_C_TIMESTEPS,
    negative_prompt=negative_prompt,
    guidance_scale=4.0,
    num_images_per_prompt=num_images_per_prompt,
)
decoder_output = decoder_pipeline(
    image_embeddings=prior_output.image_embeddings,
    prompt=caption,
    negative_prompt=negative_prompt,
    guidance_scale=0.0,
    output_type="pil",
).images[0]
decoder_output

加速推理

你可以使用 torch.compile 函式,並獲得約 2-3 倍的速度提升

prior_pipeline.prior = torch.compile(prior_pipeline.prior, mode="reduce-overhead", fullgraph=True)
decoder_pipeline.decoder = torch.compile(decoder_pipeline.decoder, mode="reduce-overhead", fullgraph=True)

侷限性

  • 由於 Würstchen 採用高壓縮,生成的影像可能缺乏大量的細節。在我們人眼看來,這在面部、手部等方面尤為明顯。
  • 影像只能以 128 畫素的步長生成,例如,1024x1024 之後的下一個更高解析度是 1152x1152
  • 該模型無法在影像中渲染正確的文字
  • 該模型通常無法達到照片真實感
  • 對於模型來說,複雜的合成提示很難處理

原始程式碼庫以及實驗性想法可以在 dome272/Wuerstchen 上找到。

WuerstchenCombinedPipeline

class diffusers.WuerstchenCombinedPipeline

< >

( tokenizer: CLIPTokenizer text_encoder: CLIPTextModel decoder: WuerstchenDiffNeXt scheduler: DDPMWuerstchenScheduler vqgan: PaellaVQModel prior_tokenizer: CLIPTokenizer prior_text_encoder: CLIPTextModel prior_prior: WuerstchenPrior prior_scheduler: DDPMWuerstchenScheduler )

引數

  • tokenizer (CLIPTokenizer) — 用於文字輸入的解碼器分詞器。
  • text_encoder (CLIPTextModel) — 用於文字輸入的解碼器文字編碼器。
  • decoder (WuerstchenDiffNeXt) — 用於解碼器影像生成管道的解碼器模型。
  • scheduler (DDPMWuerstchenScheduler) — 用於解碼器影像生成管道的排程器。
  • vqgan (PaellaVQModel) — 用於解碼器影像生成管道的 VQGAN 模型。
  • prior_tokenizer (CLIPTokenizer) — 用於文字輸入的前置分詞器。
  • prior_text_encoder (CLIPTextModel) — 用於文字輸入的前置文字編碼器。
  • prior_prior (WuerstchenPrior) — 用於前置管道的前置模型。
  • prior_scheduler (DDPMWuerstchenScheduler) — 用於前置管道的排程器。

Wuerstchen 文字到影像生成組合管道

該模型繼承自 DiffusionPipeline。有關庫為所有管道實現的通用方法(例如下載或儲存、在特定裝置上執行等),請檢視超類文件。

__call__

< >

( prompt: typing.Union[str, typing.List[str], NoneType] = None height: int = 512 width: int = 512 prior_num_inference_steps: int = 60 prior_timesteps: typing.Optional[typing.List[float]] = None prior_guidance_scale: float = 4.0 num_inference_steps: int = 12 decoder_timesteps: typing.Optional[typing.List[float]] = None decoder_guidance_scale: float = 0.0 negative_prompt: typing.Union[str, typing.List[str], NoneType] = None prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None num_images_per_prompt: int = 1 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.Tensor] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True prior_callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None prior_callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] **kwargs )

引數

  • prompt (strList[str]) — 用於指導先驗和解碼器影像生成的提示或提示列表。
  • negative_prompt (strList[str], 可選) — 不用於指導影像生成的提示或提示列表。當不使用引導時(即,如果 guidance_scale 小於 1 時),將被忽略。
  • prompt_embeds (torch.Tensor, 可選) — 預生成的先驗文字嵌入。可用於輕鬆調整文字輸入,例如提示詞加權。如果未提供,將從 prompt 輸入引數生成文字嵌入。
  • negative_prompt_embeds (torch.Tensor, 可選) — 預生成的先驗負面文字嵌入。可用於輕鬆調整文字輸入,例如提示詞加權。如果未提供,將從 negative_prompt 輸入引數生成負面文字嵌入。
  • num_images_per_prompt (int, 可選, 預設為 1) — 每個提示要生成的影像數量。
  • height (int, 可選, 預設為 512) — 生成影像的高度(畫素)。
  • width (int, 可選, 預設為 512) — 生成影像的寬度(畫素)。
  • prior_guidance_scale (float, 可選, 預設為 4.0) — 如 Classifier-Free Diffusion Guidance 中定義的引導比例。prior_guidance_scale 定義為 Imagen Paper 中公式 2 的 w。透過設定 prior_guidance_scale > 1 啟用引導比例。更高的引導比例鼓勵生成與文字 prompt 緊密關聯的影像,通常會犧牲影像質量。
  • prior_num_inference_steps (Union[int, Dict[float, int]], 可選, 預設為 60) — 先驗去噪步數。更多去噪步數通常會帶來更高質量的影像,但推理速度會變慢。對於更具體的時間步間隔,可以傳遞自定義的 prior_timesteps
  • num_inference_steps (int, 可選, 預設為 12) — 解碼器去噪步數。更多去噪步數通常會帶來更高質量的影像,但推理速度會變慢。對於更具體的時間步間隔,可以傳遞自定義的 timesteps
  • prior_timesteps (List[float], 可選) — 用於先驗去噪過程的自定義時間步。如果未定義,則使用等間距的 prior_num_inference_steps 時間步。必須按降序排列。
  • decoder_timesteps (List[float], 可選) — 用於解碼器去噪過程的自定義時間步。如果未定義,則使用等間距的 num_inference_steps 時間步。必須按降序排列。
  • decoder_guidance_scale (float, 可選, 預設為 0.0) — 如 Classifier-Free Diffusion Guidance 中定義的引導比例。guidance_scale 定義為 Imagen Paper 中公式 2 的 w。透過設定 guidance_scale > 1 啟用引導比例。更高的引導比例鼓勵生成與文字 prompt 緊密關聯的影像,通常會犧牲影像質量。
  • generator (torch.GeneratorList[torch.Generator], 可選) — 一個或多個 torch 生成器,用於使生成具有確定性。
  • latents (torch.Tensor, 可選) — 預先生成的噪聲潛在變數,從高斯分佈中取樣,用作影像生成的輸入。可用於使用不同提示調整相同的生成。如果未提供,將使用提供的隨機 generator 取樣生成潛在張量。
  • output_type (str, 可選, 預設為 "pil") — 生成影像的輸出格式。在 "pil" (PIL.Image.Image)、"np" (np.array) 或 "pt" (torch.Tensor) 中選擇。
  • return_dict (bool, 可選, 預設為 True) — 是否返回 ImagePipelineOutput 而不是普通元組。
  • prior_callback_on_step_end (Callable, 可選) — 推理過程中在每個去噪步驟結束時呼叫的函式。該函式以以下引數呼叫:prior_callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)
  • prior_callback_on_step_end_tensor_inputs (List, 可選) — prior_callback_on_step_end 函式的張量輸入列表。列表中指定的張量將作為 callback_kwargs 引數傳遞。您只能包含管道類的 ._callback_tensor_inputs 屬性中列出的變數。
  • callback_on_step_end (Callable, 可選) — 推理過程中在每個去噪步驟結束時呼叫的函式。該函式以以下引數呼叫:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)callback_kwargs 將包含 callback_on_step_end_tensor_inputs 中指定的所有張量列表。
  • callback_on_step_end_tensor_inputs (List, 可選) — callback_on_step_end 函式的張量輸入列表。列表中指定的張量將作為 callback_kwargs 引數傳遞。您只能包含管道類的 ._callback_tensor_inputs 屬性中列出的變數。

呼叫管道進行生成時呼叫的函式。

示例

>>> from diffusions import WuerstchenCombinedPipeline

>>> pipe = WuerstchenCombinedPipeline.from_pretrained("warp-ai/Wuerstchen", torch_dtype=torch.float16).to(
...     "cuda"
... )
>>> prompt = "an image of a shiba inu, donning a spacesuit and helmet"
>>> images = pipe(prompt=prompt)

enable_model_cpu_offload

< >

( gpu_id: typing.Optional[int] = None device: typing.Union[torch.device, str] = None )

使用 accelerate 將所有模型解除安裝到 CPU,減少記憶體使用,對效能影響較小。與 enable_sequential_cpu_offload 相比,此方法在呼叫其 forward 方法時一次將一個完整的模型移動到 GPU,並且該模型保留在 GPU 中直到下一個模型執行。記憶體節省低於 enable_sequential_cpu_offload,但由於 unet 的迭代執行,效能要好得多。

enable_sequential_cpu_offload

< >

( gpu_id: typing.Optional[int] = None device: typing.Union[torch.device, str] = None )

使用 🤗 Accelerate 將所有模型(unettext_encodervaesafety checker 狀態字典)解除安裝到 CPU,顯著減少記憶體使用。模型被移動到 torch.device('meta'),並且僅在其特定子模組的 forward 方法被呼叫時才載入到 GPU 上。解除安裝是基於子模組進行的。記憶體節省高於使用 enable_model_cpu_offload,但效能較低。

WuerstchenPriorPipeline

class diffusers.WuerstchenPriorPipeline

< >

( tokenizer: CLIPTokenizer text_encoder: CLIPTextModel prior: WuerstchenPrior scheduler: DDPMWuerstchenScheduler latent_mean: float = 42.0 latent_std: float = 1.0 resolution_multiple: float = 42.67 )

引數

  • prior (Prior) — 用於從文字嵌入中近似影像嵌入的規範 unCLIP 先驗。
  • text_encoder (CLIPTextModelWithProjection) — 凍結的文字編碼器。
  • tokenizer (CLIPTokenizer) — CLIPTokenizer 類的分詞器。
  • scheduler (DDPMWuerstchenScheduler) — 與 prior 結合使用以生成影像嵌入的排程器。
  • latent_mean (‘float’, 可選, 預設為 42.0) — 潛在擴散器的平均值。
  • latent_std (‘float’, 可選, 預設為 1.0) — 潛在擴散器的標準值。
  • resolution_multiple (‘float’, 可選, 預設為 42.67) — 生成多張影像的預設解析度。

用於生成 Wuerstchen 模型影像先驗的管道。

該模型繼承自 DiffusionPipeline。有關庫為所有管道實現的通用方法(例如下載或儲存、在特定裝置上執行等),請檢視超類文件。

該管道還繼承了以下載入方法

__call__

< >

( prompt: typing.Union[str, typing.List[str], NoneType] = None height: int = 1024 width: int = 1024 num_inference_steps: int = 60 timesteps: typing.List[float] = None guidance_scale: float = 8.0 negative_prompt: typing.Union[str, typing.List[str], NoneType] = None prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None num_images_per_prompt: typing.Optional[int] = 1 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.Tensor] = None output_type: typing.Optional[str] = 'pt' return_dict: bool = True callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] **kwargs )

引數

  • prompt (strList[str]) — 用於指導影像生成的提示或提示列表。
  • height (int, 可選, 預設為 1024) — 生成影像的高度(畫素)。
  • width (int, 可選, 預設為 1024) — 生成影像的寬度(畫素)。
  • num_inference_steps (int, 可選, 預設為 60) — 去噪步數。更多去噪步數通常會帶來更高質量的影像,但推理速度會變慢。
  • timesteps (List[int], 可選) — 用於去噪過程的自定義時間步。如果未定義,則使用等間距的 num_inference_steps 時間步。必須按降序排列。
  • guidance_scale (float, 可選, 預設為 8.0) — 如 Classifier-Free Diffusion Guidance 中定義的引導比例。decoder_guidance_scale 定義為 Imagen Paper 中公式 2 的 w。透過設定 decoder_guidance_scale > 1 啟用引導比例。更高的引導比例鼓勵生成與文字 prompt 緊密關聯的影像,通常會犧牲影像質量。
  • negative_prompt (strList[str], 可選) — 不用於指導影像生成的提示或提示列表。當不使用引導時(即,如果 decoder_guidance_scale 小於 1 則忽略),此引數被忽略。
  • prompt_embeds (torch.Tensor, 可選) — 預生成的文字嵌入。可用於輕鬆調整文字輸入,例如提示權重。如果未提供,將根據 prompt 輸入引數生成文字嵌入。
  • negative_prompt_embeds (torch.Tensor, 可選) — 預生成的負文字嵌入。可用於輕鬆調整文字輸入,例如提示權重。如果未提供,負提示嵌入將根據 negative_prompt 輸入引數生成。
  • num_images_per_prompt (int, 可選, 預設為 1) — 每個提示生成的影像數量。
  • generator (torch.GeneratorList[torch.Generator], 可選) — 一個或多個 torch 生成器,用於使生成具有確定性。
  • latents (torch.Tensor, 可選) — 預生成的噪聲潛在變數,從高斯分佈中取樣,用作影像生成的輸入。可用於使用不同提示調整相同的生成。如果未提供,將使用提供的隨機 generator 取樣生成潛在張量。
  • output_type (str, 可選, 預設為 "pil") — 生成影像的輸出格式。在 "pil" (PIL.Image.Image)、"np" (np.array) 或 "pt" (torch.Tensor) 中選擇。
  • return_dict (bool, 可選, 預設為 True) — 是否返回 ImagePipelineOutput 而不是普通元組。
  • callback_on_step_end (Callable, 可選) — 推理過程中在每個去噪步驟結束時呼叫的函式。該函式以以下引數呼叫:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)callback_kwargs 將包含 callback_on_step_end_tensor_inputs 中指定的所有張量列表。
  • callback_on_step_end_tensor_inputs (List, 可選) — callback_on_step_end 函式的張量輸入列表。列表中指定的張量將作為 callback_kwargs 引數傳遞。您只能包含管道類的 ._callback_tensor_inputs 屬性中列出的變數。

呼叫管道進行生成時呼叫的函式。

示例

>>> import torch
>>> from diffusers import WuerstchenPriorPipeline

>>> prior_pipe = WuerstchenPriorPipeline.from_pretrained(
...     "warp-ai/wuerstchen-prior", torch_dtype=torch.float16
... ).to("cuda")

>>> prompt = "an image of a shiba inu, donning a spacesuit and helmet"
>>> prior_output = pipe(prompt)

WuerstchenPriorPipelineOutput

class diffusers.pipelines.wuerstchen.pipeline_wuerstchen_prior.WuerstchenPriorPipelineOutput

< >

( image_embeddings: typing.Union[torch.Tensor, numpy.ndarray] )

引數

  • image_embeddings (torch.Tensornp.ndarray) — 文字提示的先驗影像嵌入。

WuerstchenPriorPipeline 的輸出類。

WuerstchenDecoderPipeline

class diffusers.WuerstchenDecoderPipeline

< >

( tokenizer: CLIPTokenizer text_encoder: CLIPTextModel decoder: WuerstchenDiffNeXt scheduler: DDPMWuerstchenScheduler vqgan: PaellaVQModel latent_dim_scale: float = 10.67 )

引數

  • tokenizer (CLIPTokenizer) — CLIP 分詞器。
  • text_encoder (CLIPTextModel) — CLIP 文字編碼器。
  • decoder (WuerstchenDiffNeXt) — WuerstchenDiffNeXt unet 解碼器。
  • vqgan (PaellaVQModel) — VQGAN 模型。
  • scheduler (DDPMWuerstchenScheduler) — 與 prior 結合使用以生成影像嵌入的排程器。
  • latent_dim_scale (float, 可選, 預設為 10.67) — 確定 VQ 潛在空間大小與影像嵌入的乘數。如果影像嵌入的高度為 24 且寬度為 24,則 VQ 潛在形狀需要為 height=int(2410.67)=256 和 width=int(2410.67)=256 才能匹配訓練條件。

用於從 Wuerstchen 模型生成影像的管道。

該模型繼承自 DiffusionPipeline。有關庫為所有管道實現的通用方法(例如下載或儲存、在特定裝置上執行等),請檢視超類文件。

__call__

< >

( image_embeddings: typing.Union[torch.Tensor, typing.List[torch.Tensor]] prompt: typing.Union[str, typing.List[str]] = None num_inference_steps: int = 12 timesteps: typing.Optional[typing.List[float]] = None guidance_scale: float = 0.0 negative_prompt: typing.Union[str, typing.List[str], NoneType] = None num_images_per_prompt: int = 1 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.Tensor] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] **kwargs )

引數

  • image_embedding (torch.TensorList[torch.Tensor]) — 從影像中提取或由 Prior 模型生成的影像嵌入。
  • prompt (strList[str]) — 用於引導影像生成的提示詞。
  • num_inference_steps (int, 可選, 預設為 12) — 去噪步數。更多的去噪步數通常會帶來更高質量的影像,但推理速度會變慢。
  • timesteps (List[int], 可選) — 用於去噪過程的自定義時間步。如果未定義,則使用等間距的 num_inference_steps 時間步。必須按降序排列。
  • guidance_scale (float, 可選, 預設為 0.0) — 如 Classifier-Free Diffusion Guidance 中所定義的引導比例。decoder_guidance_scale 被定義為 Imagen Paper 方程 2 中的 w。透過設定 decoder_guidance_scale > 1 來啟用引導比例。更高的引導比例會鼓勵生成與文字 prompt 緊密相關的影像,通常以犧牲較低影像質量為代價。
  • negative_prompt (strList[str], 可選) — 不用於引導影像生成的提示詞。不使用引導時(即 decoder_guidance_scale 小於 1 時),此引數會被忽略。
  • num_images_per_prompt (int, 可選, 預設為 1) — 每個提示詞生成的影像數量。
  • generator (torch.GeneratorList[torch.Generator], 可選) — 一個或多個 torch 生成器,用於使生成具有確定性。
  • latents (torch.Tensor, 可選) — 預生成的帶噪潛變數,從高斯分佈中取樣,用作影像生成的輸入。可用於使用不同的提示詞調整相同的生成。如果未提供,將使用提供的隨機 generator 取樣生成一個潛變數張量。
  • output_type (str, 可選, 預設為 "pil") — 生成影像的輸出格式。在以下選項中選擇:"pil" (PIL.Image.Image)、"np" (np.array) 或 "pt" (torch.Tensor)。
  • return_dict (bool, 可選, 預設為 True) — 是否返回 ImagePipelineOutput 而不是普通元組。
  • callback_on_step_end (Callable, 可選) — 在推理過程中,每個去噪步驟結束時呼叫的函式。該函式以以下引數呼叫:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)callback_kwargs 將包含 callback_on_step_end_tensor_inputs 中指定的所有張量列表。
  • callback_on_step_end_tensor_inputs (List, 可選) — callback_on_step_end 函式的張量輸入列表。列表中指定的張量將作為 callback_kwargs 引數傳遞。您只能包含管道類中 ._callback_tensor_inputs 屬性中列出的變數。

呼叫管道進行生成時呼叫的函式。

示例

>>> import torch
>>> from diffusers import WuerstchenPriorPipeline, WuerstchenDecoderPipeline

>>> prior_pipe = WuerstchenPriorPipeline.from_pretrained(
...     "warp-ai/wuerstchen-prior", torch_dtype=torch.float16
... ).to("cuda")
>>> gen_pipe = WuerstchenDecoderPipeline.from_pretrain("warp-ai/wuerstchen", torch_dtype=torch.float16).to(
...     "cuda"
... )

>>> prompt = "an image of a shiba inu, donning a spacesuit and helmet"
>>> prior_output = pipe(prompt)
>>> images = gen_pipe(prior_output.image_embeddings, prompt=prompt)

引用

      @misc{pernias2023wuerstchen,
            title={Wuerstchen: An Efficient Architecture for Large-Scale Text-to-Image Diffusion Models},
            author={Pablo Pernias and Dominic Rampas and Mats L. Richter and Christopher J. Pal and Marc Aubreville},
            year={2023},
            eprint={2306.00637},
            archivePrefix={arXiv},
            primaryClass={cs.CV}
      }
< > 在 GitHub 上更新

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