AWS Trainium & Inferentia 文件
PixArt-α
並獲得增強的文件體驗
開始使用
PixArt-α
概述
PixArt-α: Fast Training of Diffusion Transformer for Photorealistic Text-to-Image Synthesis 是 Junsong Chen、Jincheng Yu、Chongjian Ge、Lewei Yao、Enze Xie、Yue Wu、Zhongdao Wang、James Kwok、Ping Luo、Huchuan Lu 和 Zhenguo Li 的作品。
關於此管道的一些注意事項
- 它使用 Transformer 主幹(而不是 UNet)進行去噪。因此,它具有與 DiT 相似的架構。
- 它使用從 T5 計算的文字條件進行訓練。這使得該管道更擅長遵循具有複雜細節的複雜文字提示。
- 它擅長以不同的縱橫比生成高解析度影像。為了獲得最佳結果,作者推薦了一些尺寸範圍,可以在此處找到。
- 它在質量上與最先進的文字到影像生成系統(截至本文撰寫時)如 Stable Diffusion XL、Imagen 和 DALL-E 2 媲美,同時比它們更高效。
您可以在 PixArt-alpha/PixArt-alpha 找到原始程式碼庫,在 PixArt-alpha 找到所有可用檢查點。
🤗 Optimum
擴充套件了 Diffusers
以支援在第二代 Neuron 裝置(支援 Trainium 和 Inferentia 2)上進行推理。它旨在繼承 Diffusers 在 Neuron 上的易用性。
匯出到 Neuron
要在 PixArt-α 管道中部署模型,您需要將它們編譯為針對 AWS Neuron 最佳化的 TorchScript。有四個元件需要匯出為 .neuron
格式以提高效能
- 文字編碼器
- 轉換器
- VAE 編碼器
- VAE 解碼器
您可以透過 CLI 或 NeuronPixArtAlphaPipeline
類編譯並匯出 PixArt-α 檢查點。
選項 1:CLI
optimum-cli export neuron --model PixArt-alpha/PixArt-XL-2-512x512 --batch_size 1 --height 512 --width 512 --num_images_per_prompt 1 --torch_dtype bfloat16 --sequence_length 120 pixart_alpha_neuron_512/
我們建議使用 inf2.8xlarge
或更大的例項進行模型編譯。您也可以在僅有 CPU 的例項上使用 Optimum CLI 編譯模型(需要約 35 GB 記憶體),然後在 inf2.xlarge
上執行預編譯的模型以降低費用。在這種情況下,請不要忘記透過新增 --disable-validation
引數來停用推理驗證。
選項 2:Python API
import torch
from optimum.neuron import NeuronPixArtAlphaPipeline
# Compile
compiler_args = {"auto_cast": "none"}
input_shapes = {"batch_size": 1, "height": 512, "width": 512, "sequence_length": 120}
neuron_model = NeuronPixArtAlphaPipeline.from_pretrained("PixArt-alpha/PixArt-XL-2-512x512", torch_dtype=torch.bfloat16, export=True, disable_neuron_cache=True, **compiler_args, **input_shapes)
# Save locally
neuron_model.save_pretrained("pixart_alpha_neuron_512/")
# Upload to the HuggingFace Hub
neuron_model.push_to_hub(
"pixart_alpha_neuron_512/", repository_id="Jingya/PixArt-XL-2-512x512-neuronx" # Replace with your HF Hub repo id
)
文字到影像
NeuronPixArtAlphaPipeline
類允許您在 Neuron 裝置上透過文字提示生成影像,體驗與 Diffusers
相似。
使用預編譯的 PixArt-α 模型,現在在 Neuron 上用提示生成影像
from optimum.neuron import NeuronPixArtAlphaPipeline
neuron_model = NeuronPixArtAlphaPipeline.from_pretrained("pixart_alpha_neuron_512/")
prompt = "Oppenheimer sits on the beach on a chair, watching a nuclear exposition with a huge mushroom cloud, 120mm."
image = neuron_model(prompt=prompt).images[0]

NeuronPixArtAlphaPipeline
用於文字到影像生成的 PixArt-α 管道。
您希望我們在 🤗Optimum-neuron
中支援其他擴散功能嗎?請提交問題到 Optimum-neuron
Github 倉庫,或在 HuggingFace 社群論壇與我們討論,謝謝 🤗!