Diffusers 文件

SanaPipeline

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

SanaPipeline

LoRA MPS

SANA:基於線性擴散 Transformer 的高效高解析度影像合成,由 NVIDIA 和麻省理工 HAN 實驗室的 Enze Xie、Junsong Chen、Junyu Chen、Han Cai、Haotian Tang、Yujun Lin、Zhekai Zhang、Muyang Li、Ligeng Zhu、Yao Lu、Song Han 共同完成。

論文摘要如下:

我們引入了 Sana,一個文字到影像框架,能夠高效生成高達 4096×4096 解析度的影像。Sana 能夠以極快的速度合成高解析度、高質量的影像,並且具有強大的文字-影像對齊能力,可在筆記型電腦 GPU 上部署。核心設計包括:(1) 深度壓縮自編碼器:與傳統僅壓縮影像 8 倍的自編碼器不同,我們訓練了一個可將影像壓縮 32 倍的自編碼器,有效減少了潛在令牌的數量。(2) 線性 DiT:我們用線性注意力替換了 DiT 中的所有香草注意力,這在不犧牲質量的情況下在更高解析度下更高效。(3) 僅解碼器文字編碼器:我們用現代僅解碼器小型 LLM 替換了 T5 作為文字編碼器,並設計了帶有上下文學習的複雜人工指令,以增強影像-文字對齊。(4) 高效訓練和取樣:我們提出了 Flow-DPM-Solver 以減少採樣步數,並採用高效的字幕標註和選擇來加速收斂。因此,Sana-0.6B 與現代巨型擴散模型(例如 Flux-12B)相比非常有競爭力,其模型大小小 20 倍,吞吐量快 100 倍以上。此外,Sana-0.6B 可以在 16GB 筆記型電腦 GPU 上部署,生成 1024×1024 解析度影像所需時間不到 1 秒。Sana 使得低成本內容創作成為可能。程式碼和模型將公開發布。

請務必查閱排程器指南,瞭解如何探索排程器速度與質量之間的權衡,並檢視跨管道重用元件部分,瞭解如何有效地將相同元件載入到多個管道中。

此管道由 lawrence-cjchenjy2003 貢獻。原始程式碼庫可在 此處 找到。原始權重可在 hf.co/Efficient-Large-Model 下找到。

可用模型

模型 推薦資料型別
Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers torch.bfloat16
Efficient-Large-Model/Sana_1600M_1024px_diffusers torch.float16
Efficient-Large-Model/Sana_1600M_1024px_MultiLing_diffusers torch.float16
Efficient-Large-Model/Sana_1600M_512px_diffusers torch.float16
Efficient-Large-Model/Sana_1600M_512px_MultiLing_diffusers torch.float16
Efficient-Large-Model/Sana_600M_1024px_diffusers torch.float16
Efficient-Large-Model/Sana_600M_512px_diffusers torch.float16

更多資訊請參考集合。

注意:推薦的資料型別是針對 Transformer 權重的。文字編碼器和 VAE 權重必須保持為 `torch.bfloat16` 或 `torch.float32` 才能使模型正常工作。請參考下面的推理示例,瞭解如何使用推薦的資料型別載入模型。

請務必為下載的模型檢查點傳遞 `variant` 引數,以減少磁碟空間佔用。對於推薦資料型別為 `torch.float16` 的模型,請將其設定為 `"fp16"`;對於推薦資料型別為 `torch.bfloat16` 的模型,請將其設定為 `"bf16"`。預設情況下,會下載 `torch.float32` 權重,這會佔用兩倍的磁碟儲存空間。此外,`torch.float32` 權重可以透過指定 `torch_dtype` 引數進行即時下轉換。請參閱文件瞭解更多資訊。

量化

量化有助於透過以較低精度資料型別儲存模型權重來減少大型模型的記憶體需求。但是,量化對影片質量的影響可能因影片模型而異。

有關支援的量化後端以及如何選擇適合您用例的量化後端,請參閱量化概述。以下示例演示瞭如何使用 bitsandbytes 載入量化的 SanaPipeline 進行推理。

import torch
from diffusers import BitsAndBytesConfig as DiffusersBitsAndBytesConfig, SanaTransformer2DModel, SanaPipeline
from transformers import BitsAndBytesConfig as BitsAndBytesConfig, AutoModel

quant_config = BitsAndBytesConfig(load_in_8bit=True)
text_encoder_8bit = AutoModel.from_pretrained(
    "Efficient-Large-Model/Sana_1600M_1024px_diffusers",
    subfolder="text_encoder",
    quantization_config=quant_config,
    torch_dtype=torch.float16,
)

quant_config = DiffusersBitsAndBytesConfig(load_in_8bit=True)
transformer_8bit = SanaTransformer2DModel.from_pretrained(
    "Efficient-Large-Model/Sana_1600M_1024px_diffusers",
    subfolder="transformer",
    quantization_config=quant_config,
    torch_dtype=torch.float16,
)

pipeline = SanaPipeline.from_pretrained(
    "Efficient-Large-Model/Sana_1600M_1024px_diffusers",
    text_encoder=text_encoder_8bit,
    transformer=transformer_8bit,
    torch_dtype=torch.float16,
    device_map="balanced",
)

prompt = "a tiny astronaut hatching from an egg on the moon"
image = pipeline(prompt).images[0]
image.save("sana.png")

< >

class diffusers.SanaPipeline

< >

( tokenizer: typing.Union[transformers.models.gemma.tokenization_gemma.GemmaTokenizer, transformers.models.gemma.tokenization_gemma_fast.GemmaTokenizerFast] text_encoder: Gemma2PreTrainedModel vae: AutoencoderDC transformer: SanaTransformer2DModel scheduler: DPMSolverMultistepScheduler )

使用 Sana 進行文字到影像生成的管道。

__call__

< >

( prompt: typing.Union[str, typing.List[str]] = None negative_prompt: str = '' num_inference_steps: int = 20 timesteps: typing.List[int] = None sigmas: typing.List[float] = None guidance_scale: float = 4.5 num_images_per_prompt: typing.Optional[int] = 1 height: int = 1024 width: int = 1024 eta: float = 0.0 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.Tensor] = None prompt_embeds: typing.Optional[torch.Tensor] = None prompt_attention_mask: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True clean_caption: bool = False use_resolution_binning: bool = True attention_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] max_sequence_length: int = 300 complex_human_instruction: typing.List[str] = ["Given a user prompt, generate an 'Enhanced prompt' that provides detailed visual descriptions suitable for image generation. Evaluate the level of detail in the user prompt:", '- If the prompt is simple, focus on adding specifics about colors, shapes, sizes, textures, and spatial relationships to create vivid and concrete scenes.', '- If the prompt is already detailed, refine and enhance the existing details slightly without overcomplicating.', 'Here are examples of how to transform or refine prompts:', '- User Prompt: A cat sleeping -> Enhanced: A small, fluffy white cat curled up in a round shape, sleeping peacefully on a warm sunny windowsill, surrounded by pots of blooming red flowers.', '- User Prompt: A busy city street -> Enhanced: A bustling city street scene at dusk, featuring glowing street lamps, a diverse crowd of people in colorful clothing, and a double-decker bus passing by towering glass skyscrapers.', 'Please generate only the enhanced description for the prompt below and avoid including any additional commentary or evaluations:', 'User Prompt: '] ) SanaPipelineOutputtuple

引數

  • prompt (strList[str], 可選) — 用於引導影像生成的提示詞。如果未定義,則必須傳遞 prompt_embeds
  • negative_prompt (strList[str], 可選) — 不用於引導影像生成的提示詞。如果未定義,則必須傳遞 negative_prompt_embeds。當不使用引導時(即,如果 guidance_scale 小於 1 則忽略)。
  • num_inference_steps (int, 可選, 預設為 20) — 去噪步數。更多去噪步數通常會產生更高質量的影像,但推理速度會變慢。
  • timesteps (List[int], 可選) — 自定義時間步長,用於支援 timesteps 引數的排程器中的去噪過程。如果未定義,將使用傳遞 num_inference_steps 時的預設行為。必須按降序排列。
  • sigmas (List[float], 可選) — 自定義 sigma 值,用於支援 sigmas 引數的排程器中的去噪過程。如果未定義,將使用傳遞 num_inference_steps 時的預設行為。
  • guidance_scale (float, 可選, 預設為 4.5) — 如 Classifier-Free Diffusion Guidance 中定義的引導比例。guidance_scale 定義為 Imagen Paper 中方程 2 的 w。透過設定 guidance_scale > 1 啟用引導比例。更高的引導比例鼓勵生成與文字 prompt 緊密相關的影像,通常以犧牲影像質量為代價。
  • num_images_per_prompt (int, 可選, 預設為 1) — 每個提示詞生成的影像數量。
  • height (int, 可選, 預設為 self.unet.config.sample_size) — 生成影像的高度(畫素)。
  • width (int, 可選, 預設為 self.unet.config.sample_size) — 生成影像的寬度(畫素)。
  • eta (float, 可選, 預設為 0.0) — 對應於 DDIM 論文中的引數 eta (η):https://huggingface.co/papers/2010.02502。僅適用於 schedulers.DDIMScheduler,對其他排程器將被忽略。
  • generator (torch.GeneratorList[torch.Generator], 可選) — 一個或多個 torch 生成器,用於使生成過程具有確定性。
  • latents (torch.Tensor, 可選) — 預生成的噪聲潛在變數,從高斯分佈中取樣,用作影像生成的輸入。可用於使用不同的提示詞調整相同的生成。如果未提供,將使用提供的隨機 generator 進行取樣生成潛在張量。
  • prompt_embeds (torch.Tensor, 可選) — 預生成的文字嵌入。可用於輕鬆調整文字輸入,例如提示詞加權。如果未提供,將從 prompt 輸入引數生成文字嵌入。
  • prompt_attention_mask (torch.Tensor, 可選) — 預生成的文字嵌入注意力掩碼。
  • negative_prompt_embeds (torch.Tensor, 可選) — 預生成的負面文字嵌入。對於 PixArt-Sigma,此負面提示詞應為空字串。如果未提供,將從 negative_prompt 輸入引數生成負面提示詞嵌入。
  • negative_prompt_attention_mask (torch.Tensor, 可選) — 預生成的負面文字嵌入注意力掩碼。
  • output_type (str, 可選, 預設為 "pil") — 生成影像的輸出格式。在 PIL: PIL.Image.Imagenp.array 之間選擇。
  • return_dict (bool, 可選, 預設為 True) — 是否返回 ~pipelines.stable_diffusion.IFPipelineOutput 而不是普通元組。
  • attention_kwargs — 一個 kwargs 字典,如果指定,則會傳遞給 diffusers.models.attention_processorself.processor 下定義的 AttentionProcessor
  • clean_caption (bool, 可選, 預設為 True) — 是否在建立嵌入之前清理字幕。需要安裝 beautifulsoup4ftfy。如果未安裝這些依賴項,嵌入將從原始提示生成。
  • use_resolution_binning (bool 預設為 True) — 如果設定為 True,則首先使用 ASPECT_RATIO_1024_BIN 將請求的高度和寬度對映到最接近的解析度。將生成的潛在變數解碼為影像後,它們將被調整回請求的解析度。對於生成非方形影像非常有用。
  • 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 屬性中列出的變數。
  • max_sequence_length (int,預設為 300) — 與 prompt 一起使用的最大序列長度。
  • complex_human_instruction (List[str], 可選) — 複雜人類注意力的說明:https://github.com/NVlabs/Sana/blob/main/configs/sana_app_config/Sana_1600M_app.yaml#L55

返回

SanaPipelineOutputtuple

如果 return_dictTrue,則返回 SanaPipelineOutput,否則返回一個 tuple,其中第一個元素是生成的影像列表

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

示例

>>> import torch
>>> from diffusers import SanaPipeline

>>> pipe = SanaPipeline.from_pretrained(
...     "Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers", torch_dtype=torch.float32
... )
>>> pipe.to("cuda")
>>> pipe.text_encoder.to(torch.bfloat16)
>>> pipe.transformer = pipe.transformer.to(torch.bfloat16)

>>> image = pipe(prompt='a cyberpunk cat with a neon sign that says "Sana"')[0]
>>> image[0].save("output.png")

disable_vae_slicing

< >

( )

停用切片 VAE 解碼。如果之前啟用了 enable_vae_slicing,此方法將返回一步計算解碼。

disable_vae_tiling

< >

( )

停用平鋪 VAE 解碼。如果之前啟用了 enable_vae_tiling,此方法將恢復一步計算解碼。

enable_vae_slicing

< >

( )

啟用切片 VAE 解碼。啟用此選項後,VAE 會將輸入張量分片,分步計算解碼。這有助於節省一些記憶體並允許更大的批次大小。

enable_vae_tiling

< >

( )

啟用平鋪 VAE 解碼。啟用此選項後,VAE 將把輸入張量分割成瓦片,分多步計算編碼和解碼。這對於節省大量記憶體和處理更大的影像非常有用。

encode_prompt

< >

( prompt: typing.Union[str, typing.List[str]] do_classifier_free_guidance: bool = True negative_prompt: str = '' num_images_per_prompt: int = 1 device: typing.Optional[torch.device] = None prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None prompt_attention_mask: typing.Optional[torch.Tensor] = None negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None clean_caption: bool = False max_sequence_length: int = 300 complex_human_instruction: typing.Optional[typing.List[str]] = None lora_scale: typing.Optional[float] = None )

引數

  • prompt (strList[str], 可選) — 要編碼的提示。
  • negative_prompt (strList[str], 可選) — 不引導影像生成的提示。如果未定義,則必須傳遞 negative_prompt_embeds。當不使用引導時(即,如果 guidance_scale 小於 1 則忽略)。對於 PixArt-Alpha,這應該為 ""。
  • do_classifier_free_guidance (bool, 可選, 預設為 True) — 是否使用分類器自由引導。
  • num_images_per_prompt (int, 可選, 預設為 1) — 每個提示應生成的影像數量。
  • device — (torch.device, 可選): 用於放置結果嵌入的 torch 裝置。
  • prompt_embeds (torch.Tensor, 可選) — 預生成的文字嵌入。可用於輕鬆調整文字輸入,例如提示權重。如果未提供,則將從 prompt 輸入引數生成文字嵌入。
  • negative_prompt_embeds (torch.Tensor, 可選) — 預生成的負文字嵌入。對於 Sana,它應該是 "" 字串的嵌入。
  • clean_caption (bool, 預設為 False) — 如果為 True,函式將在編碼前預處理並清理提供的字幕。
  • max_sequence_length (int, 預設為 300) — 用於提示的最大序列長度。
  • complex_human_instruction (list[str], 預設為 complex_human_instruction) — 如果 complex_human_instruction 不為空,函式將使用複雜的 Human 指令作為提示。

將提示編碼為文字編碼器隱藏狀態。

SanaPAGPipeline

class diffusers.SanaPAGPipeline

< >

( tokenizer: typing.Union[transformers.models.gemma.tokenization_gemma.GemmaTokenizer, transformers.models.gemma.tokenization_gemma_fast.GemmaTokenizerFast] text_encoder: Gemma2PreTrainedModel vae: AutoencoderDC transformer: SanaTransformer2DModel scheduler: FlowMatchEulerDiscreteScheduler pag_applied_layers: typing.Union[str, typing.List[str]] = 'transformer_blocks.0' )

用於使用 Sana 進行文字到影像生成的管道。此管道支援使用 擾動注意力引導 (PAG)

__call__

< >

( prompt: typing.Union[str, typing.List[str]] = None negative_prompt: str = '' num_inference_steps: int = 20 timesteps: typing.List[int] = None sigmas: typing.List[float] = None guidance_scale: float = 4.5 num_images_per_prompt: typing.Optional[int] = 1 height: int = 1024 width: int = 1024 eta: float = 0.0 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.Tensor] = None prompt_embeds: typing.Optional[torch.Tensor] = None prompt_attention_mask: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True clean_caption: bool = False use_resolution_binning: 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'] max_sequence_length: int = 300 complex_human_instruction: typing.List[str] = ["Given a user prompt, generate an 'Enhanced prompt' that provides detailed visual descriptions suitable for image generation. Evaluate the level of detail in the user prompt:", '- If the prompt is simple, focus on adding specifics about colors, shapes, sizes, textures, and spatial relationships to create vivid and concrete scenes.', '- If the prompt is already detailed, refine and enhance the existing details slightly without overcomplicating.', 'Here are examples of how to transform or refine prompts:', '- User Prompt: A cat sleeping -> Enhanced: A small, fluffy white cat curled up in a round shape, sleeping peacefully on a warm sunny windowsill, surrounded by pots of blooming red flowers.', '- User Prompt: A busy city street -> Enhanced: A bustling city street scene at dusk, featuring glowing street lamps, a diverse crowd of people in colorful clothing, and a double-decker bus passing by towering glass skyscrapers.', 'Please generate only the enhanced description for the prompt below and avoid including any additional commentary or evaluations:', 'User Prompt: '] pag_scale: float = 3.0 pag_adaptive_scale: float = 0.0 ) ImagePipelineOutputtuple

引數

  • prompt (strList[str], 可選) — 用於引導影像生成的提示。如果未定義,則必須傳遞 prompt_embeds
  • negative_prompt (strList[str], 可選) — 不引導影像生成的提示。如果未定義,則必須傳遞 negative_prompt_embeds。當不使用引導時(即,如果 guidance_scale 小於 1 則忽略)。
  • num_inference_steps (int, 可選, 預設為 20) — 去噪步驟的數量。更多的去噪步驟通常會導致更高質量的影像,但推理速度會變慢。
  • timesteps (List[int], 可選) — 自定義時間步長,用於去噪過程,適用於其 set_timesteps 方法支援 timesteps 引數的排程器。如果未定義,將使用傳遞 num_inference_steps 時的預設行為。必須按降序排列。
  • sigmas (List[float], 可選) — 自定義 sigma,用於去噪過程,適用於其 set_timesteps 方法支援 sigmas 引數的排程器。如果未定義,將使用傳遞 num_inference_steps 時的預設行為。
  • guidance_scale (float, 可選, 預設為 4.5) — 無分類器擴散引導 中定義的引導比例。guidance_scale 定義為 Imagen 論文 中公式 2 的 w。透過設定 guidance_scale > 1 來啟用引導比例。更高的引導比例鼓勵生成與文字 prompt 緊密相關的影像,通常以犧牲較低影像質量為代價。
  • num_images_per_prompt (int, 可選, 預設為 1) — 每個提示要生成的影像數量。
  • height (int, 可選, 預設為 self.unet.config.sample_size) — 生成影像的高度(畫素)。
  • width (int, 可選, 預設為 self.unet.config.sample_size) — 生成影像的寬度(畫素)。
  • eta (float, 可選, 預設為 0.0) — 對應於 DDIM 論文中的引數 eta (η):https://huggingface.co/papers/2010.02502。僅適用於 schedulers.DDIMScheduler,對其他排程器將忽略。
  • generator (torch.GeneratorList[torch.Generator], 可選) — 一個或多個 torch generator(s),用於使生成具有確定性。
  • latents (torch.Tensor, 可選) — 預生成的帶噪聲的潛在變數,從高斯分佈中取樣,用作影像生成的輸入。可用於使用不同的提示調整相同的生成。如果未提供,則將使用提供的隨機 generator 取樣生成潛在張量。
  • prompt_embeds (torch.Tensor, 可選) — 預生成的文字嵌入。可用於輕鬆調整文字輸入,例如提示權重。如果未提供,則將從 prompt 輸入引數生成文字嵌入。
  • prompt_attention_mask (torch.Tensor, 可選) — 文字嵌入的預生成注意力掩碼。
  • negative_prompt_embeds (torch.Tensor, 可選) — 預生成的負文字嵌入。對於 PixArt-Sigma,此負提示應為 ""。如果未提供,negative_prompt_embeds 將從 negative_prompt 輸入引數生成。
  • negative_prompt_attention_mask (torch.Tensor, 可選) — 負文字嵌入的預生成注意力掩碼。
  • output_type (str, 可選, 預設為 "pil") — 生成影像的輸出格式。選擇 PIL: PIL.Image.Imagenp.array
  • return_dict (bool, 可選, 預設為 True) — 是否返回 ~pipelines.stable_diffusion.IFPipelineOutput 而不是普通元組。
  • clean_caption (bool, 可選, 預設為 True) — 在建立嵌入之前是否清理字幕。需要安裝 beautifulsoup4ftfy。如果未安裝依賴項,將從原始提示建立嵌入。
  • use_resolution_binning (bool 預設為 True) — 如果設定為 True,請求的高度和寬度將首先使用 ASPECT_RATIO_1024_BIN 對映到最接近的解析度。生成的潛在變數被解碼為影像後,它們將被調整回請求的解析度。這對於生成非方形影像很有用。
  • 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 屬性中列出的變數。
  • max_sequence_length (int,預設為 300) — 與 prompt 一起使用的最大序列長度。
  • complex_human_instruction (List[str], 可選) — 複雜人類注意力的說明:https://github.com/NVlabs/Sana/blob/main/configs/sana_app_config/Sana_1600M_app.yaml#L55
  • pag_scale (float, 可選, 預設為 3.0) — 擾動注意力引導的比例因子。如果設定為 0.0,則不使用擾動注意力引導。
  • pag_adaptive_scale (float, 可選, 預設為 0.0) — 擾動注意力引導的自適應比例因子。如果設定為 0.0,則使用 pag_scale

返回

ImagePipelineOutputtuple

如果 return_dictTrue,則返回 ImagePipelineOutput,否則返回一個 tuple,其中第一個元素是生成的影像列表

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

示例

>>> import torch
>>> from diffusers import SanaPAGPipeline

>>> pipe = SanaPAGPipeline.from_pretrained(
...     "Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers",
...     pag_applied_layers=["transformer_blocks.8"],
...     torch_dtype=torch.float32,
... )
>>> pipe.to("cuda")
>>> pipe.text_encoder.to(torch.bfloat16)
>>> pipe.transformer = pipe.transformer.to(torch.bfloat16)

>>> image = pipe(prompt='a cyberpunk cat with a neon sign that says "Sana"')[0]
>>> image[0].save("output.png")

disable_vae_slicing

< >

( )

停用切片 VAE 解碼。如果之前啟用了 enable_vae_slicing,此方法將返回一步計算解碼。

disable_vae_tiling

< >

( )

停用平鋪 VAE 解碼。如果之前啟用了 enable_vae_tiling,此方法將恢復一步計算解碼。

enable_vae_slicing

< >

( )

啟用切片 VAE 解碼。啟用此選項後,VAE 會將輸入張量分片,分步計算解碼。這有助於節省一些記憶體並允許更大的批次大小。

enable_vae_tiling

< >

( )

啟用平鋪 VAE 解碼。啟用此選項後,VAE 將把輸入張量分割成瓦片,分多步計算編碼和解碼。這對於節省大量記憶體和處理更大的影像非常有用。

encode_prompt

< >

( prompt: typing.Union[str, typing.List[str]] do_classifier_free_guidance: bool = True negative_prompt: str = '' num_images_per_prompt: int = 1 device: typing.Optional[torch.device] = None prompt_embeds: typing.Optional[torch.Tensor] = None negative_prompt_embeds: typing.Optional[torch.Tensor] = None prompt_attention_mask: typing.Optional[torch.Tensor] = None negative_prompt_attention_mask: typing.Optional[torch.Tensor] = None clean_caption: bool = False max_sequence_length: int = 300 complex_human_instruction: typing.Optional[typing.List[str]] = None )

引數

  • prompt (strList[str], 可選) — 要編碼的提示詞
  • negative_prompt (strList[str], 可選) — 不引導影像生成的提示詞。如果未定義,則必須傳遞 negative_prompt_embeds。當不使用引導時(即,如果 guidance_scale 小於 1),則忽略此引數。對於 PixArt-Alpha,此引數應為 ""。
  • do_classifier_free_guidance (bool, 可選, 預設為 True) — 是否使用無分類器引導
  • num_images_per_prompt (int, 可選, 預設為 1) — 每個提示詞應生成的影像數量
  • device — (torch.device, 可選): 將生成的嵌入放置在哪個 torch 裝置上
  • prompt_embeds (torch.Tensor, 可選) — 預先生成的文字嵌入。可用於輕鬆調整文字輸入,例如提示詞加權。如果未提供,將從 prompt 輸入引數生成文字嵌入。
  • negative_prompt_embeds (torch.Tensor, 可選) — 預先生成的負面文字嵌入。對於 Sana,它應該是“ ”字串的嵌入。
  • clean_caption (bool, 預設為 False) — 如果為 True,函式將在編碼前預處理和清理提供的標題。
  • max_sequence_length (int, 預設為 300) — 用於提示詞的最大序列長度。
  • complex_human_instruction (list[str], 預設為 complex_human_instruction) — 如果 complex_human_instruction 不為空,函式將使用複雜的“人類指令”作為提示詞。

將提示編碼為文字編碼器隱藏狀態。

SanaPipelineOutput

class diffusers.pipelines.sana.pipeline_output.SanaPipelineOutput

< >

( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )

引數

  • images (List[PIL.Image.Image]np.ndarray) — 長度為 batch_size 的去噪 PIL 影像列表,或形狀為 (batch_size, height, width, num_channels) 的 numpy 陣列。PIL 影像或 numpy 陣列表示擴散管道的去噪影像。

Sana 管道的輸出類。

< > 在 GitHub 上更新

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