Diffusers 文件

T-GATE

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

T-GATE

T-GATE 透過在交叉注意力計算收斂後跳過其計算,來加速 Stable DiffusionPixArtLatency Consistency Model 管道的推理。這種方法不需要額外的訓練,並且可以將推理速度提高 10-50%。T-GATE 還與其他最佳化方法相容,例如 DeepCache

在開始之前,請確保已安裝 T-GATE。

pip install tgate
pip install -U torch diffusers transformers accelerate DeepCache

要將 T-GATE 與管道一起使用,您需要使用其相應的載入器。

流水線 T-GATE 載入器
PixArt TgatePixArtLoader
Stable Diffusion XL TgateSDXLLoader
Stable Diffusion XL + DeepCache TgateSDXLDeepCacheLoader
Stable Diffusion TgateSDLoader
Stable Diffusion + DeepCache TgateSDDeepCacheLoader

接下來,使用管道、門控步(停止計算交叉注意力的時間步)和推理步數建立一個 TgateLoader。然後,使用提示、門控步和推理步數在管道上呼叫 tgate 方法。

讓我們看看如何為幾種不同的管道啟用此功能。

PixArt
Stable Diffusion XL
帶有 DeepCache 的 StableDiffusionXL
潛在一致性模型

使用 T-GATE 加速 PixArtAlphaPipeline

import torch
from diffusers import PixArtAlphaPipeline
from tgate import TgatePixArtLoader

pipe = PixArtAlphaPipeline.from_pretrained("PixArt-alpha/PixArt-XL-2-1024-MS", torch_dtype=torch.float16)

gate_step = 8
inference_step = 25
pipe = TgatePixArtLoader(
       pipe,
       gate_step=gate_step,
       num_inference_steps=inference_step,
).to("cuda")

image = pipe.tgate(
       "An alpaca made of colorful building blocks, cyberpunk.",
       gate_step=gate_step,
       num_inference_steps=inference_step,
).images[0]

T-GATE 還支援 StableDiffusionPipelinePixArt-alpha/PixArt-LCM-XL-2-1024-MS

基準

模型 乘法累加運算(MACs) 引數量 延遲 MS-COCO 上的零樣本 10K-FID
SD-1.5 16.938萬億 8.5952億 7.032秒 23.927
SD-1.5 w/ T-GATE 9.875萬億 8.15557億 4.313秒 20.789
SD-2.1 38.041萬億 8.65785億 16.121秒 22.609
SD-2.1 w/ T-GATE 22.208萬億 8.15433 億 9.878秒 19.940
SD-XL 149.438萬億 25.7億 53.187秒 24.628
SD-XL w/ T-GATE 84.438萬億 20.24億 27.932秒 22.738
Pixart-Alpha 107.031萬億 6.1135億 61.502秒 38.669
Pixart-Alpha w/ T-GATE 65.318萬億 4.62585億 37.867秒 35.825
DeepCache (SD-XL) 57.888萬億 - 19.931秒 23.755
DeepCache w/ T-GATE 43.868萬億 - 14.666秒 23.999
LCM (SD-XL) 11.955萬億 25.7億 3.805秒 25.044
LCM w/ T-GATE 11.171萬億 20.24億 3.533秒 25.028
LCM (Pixart-Alpha) 8.563萬億 6.1135億 4.733秒 36.086
LCM w/ T-GATE 7.623萬億 4.62585億 4.543秒 37.048

延遲在 NVIDIA 1080TI 上測試,MACs 和引數量使用 calflops 計算,FID 使用 PytorchFID 計算。

< > 在 GitHub 上更新

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