【深度学习】PixArt-Sigma 实战【3】速度测试

css 复制代码
import time

import torch
from diffusers import Transformer2DModel, PixArtSigmaPipeline
from diffusers import ConsistencyDecoderVAE

device = torch.device("cuda:1" if torch.cuda.is_available() else "cpu")
weight_dtype = torch.float16

pipe = PixArtSigmaPipeline.from_pretrained(
    "./PixArt-Sigma-XL-2-1024-MS",
    torch_dtype=weight_dtype,
    use_safetensors=True,
)
pipe.to(device)

# transformer = Transformer2DModel.from_pretrained(
#     # "PixArt-alpha/PixArt-Sigma-XL-2-1024-MS",
#     # "/ssd/xiedong/PixArt/PixArt-Sigma-XL-2-2K-MS",
#     "/ssd/xiedong/PixArt/PixArt-Sigma-XL-2-2K-MS",
#     subfolder='transformer',
#     torch_dtype=weight_dtype,
# )
# pipe = PixArtSigmaPipeline.from_pretrained(
#     # "PixArt-alpha/pixart_sigma_sdxlvae_T5_diffusers",
#     "/ssd/xiedong/PixArt/PixArt-sigma/output/pixart_sigma_sdxlvae_T5_diffusers",
#     transformer=transformer,
#     torch_dtype=weight_dtype,
#     use_safetensors=True,
# )
# pipe.vae = ConsistencyDecoderVAE.from_pretrained("/ssd/xiedong/PixArt/consistency-decoder", torch_dtype=torch.float16)
# pipe.to(device)

# Enable memory optimizations.
# pipe.enable_model_cpu_offload()

time1 = time.time()
prompt = "A small cactus with a happy face in the Sahara desert."
image = pipe(prompt).images[0]
time2 = time.time()
print(f"time use:{time2 - time1}")
image.save("./catcus.png")

time1 = time.time()
prompt = "A small cactus with a happy face in the Sahara desert."
image = pipe(prompt).images[0]
time2 = time.time()
print(f"time use:{time2 - time1}")
image.save("./catcus.png")

A100速度 20轮4.4秒。

Loading pipeline components...: 0%| | 0/5 00:00\You are using the default legacy behaviour of the <class 'transformers.models.t5.tokenization_t5.T5Tokenizer'>. This is expected, and simply means that the legacy (previous) behavior will be used so nothing changes for you. If you want to use the new behaviour, set legacy=False. This should only be set if you understand what it means, and thouroughly read the reason why this was added as explained in https://github.com/huggingface/transformers/pull/24565

Loading pipeline components...: 60%|██████ | 3/5 00:01\<00:01, 1.65it/s

Loading checkpoint shards: 0%| | 0/2 00:00\

Loading checkpoint shards: 50%|█████ | 1/2 00:01\<00:01, 1.83s/it

Loading checkpoint shards: 100%|██████████| 2/2 00:03\<00:00, 1.70s/it

Loading pipeline components...: 100%|██████████| 5/5 00:11\<00:00, 2.29s/it

100%|██████████| 20/20 00:05\<00:00, 3.89it/s

time use:6.027105093002319

100%|██████████| 20/20 00:04\<00:00, 4.94it/s

time use:4.406545162200928

相关推荐
云器科技20 分钟前
湖上原地加速:存量数据平台最低风险的降本增效与AI演进之路
人工智能
向量引擎21 分钟前
腾讯混元 API 接入与国内模型统一入口实践:API Key、OpenAI 兼容调用、向量引擎中转配置与企业安全检查
人工智能·gpt·aigc·ai编程·ai写作·agi·api调用
ACP广源盛1392462567327 分钟前
GSV2221 显示转换芯片@ACP#赋能 RTX Spark 端侧 AI 设备,构建多屏全模态视觉交互新生态
大数据·人工智能·嵌入式硬件·gpt·spark·电脑·音视频
basketball6161 小时前
AI Infra 硬件体系与编程模型:5. Tensor Core 解析
人工智能
2601_955767421 小时前
iPhone 17 OLED 屏幕偏振光学分析 & AR 镀膜与双护技术实践解析
人工智能·科技·ios·iphone·圆偏振光
DeniuHe2 小时前
深度学习中的MLP层
人工智能·深度学习
IT_陈寒2 小时前
Vite项目build后路由404了?你可能漏了这个小配置
前端·人工智能·后端
海兰2 小时前
【小程序】基于 AI 大语言模型驱动的中国古典诗词 Web 应用详细设计指南
人工智能·语言模型·小程序
有浔则灵2 小时前
从零开始构建 AI Agent(一):理解 Eino 的 Component 抽象与流式对话
人工智能·log4j