【深度学习】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

相关推荐
柯南4668几秒前
【AI工程师精讲】09:LoRA:几十兆的文件,凭什么能改变一个大模型
人工智能·ai编程
198******126343 分钟前
Work Agent深度解读:AI长程任务如何重塑办公自动化
人工智能
自养Agent4 分钟前
Agent Harness 从用到会造:上下文塞满了,它为什么反而变笨
人工智能
喵叔哟5 分钟前
第 2 章 Spec Kit 到底是什么?
人工智能
科创致远7 分钟前
2026 ESOP系统选型指南:从轻MES到独立ESOP怎么选
大数据·人工智能·制造·精益工程
Rosanci8 分钟前
AI 编程工具该知道什么、能做什么?从仓库上下文到测试执行的权限分层
人工智能·自动化·ai 编程
进制树9 分钟前
第18章 计算机视觉与感知集成
人工智能·计算机视觉
陈嘿萌13 分钟前
学术速递|2026年8月 arXiv 图像融合论文汇总(08.01–08.31)29 篇最新成果
图像处理·人工智能·深度学习·计算机视觉·图像融合·学术研究与理论基础
stereohomology14 分钟前
用Step 5 preview给Solomd 5.0加上自定义主题
人工智能·语言模型·llm·薅羊毛
志栋智能14 分钟前
预算敏感型企业的自动化之路:IT运维低成本转型
运维·人工智能·自动化