【深度学习】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<?, ?it/s]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<?, ?it/s]

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

相关推荐
Mxsoft61910 分钟前
某次联邦学习训练模型不准,发现协议转换字段映射错,手动校验救场!
人工智能
shayudiandian40 分钟前
用PyTorch训练一个猫狗分类器
人工智能·pytorch·深度学习
这儿有一堆花1 小时前
把 AI 装进终端:Gemini CLI 上手体验与核心功能解析
人工智能·ai·ai编程
子午1 小时前
【蘑菇识别系统】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积网络+resnet50算法
人工智能·python·深度学习
模型启动机1 小时前
Langchain正式宣布,Deep Agents全面支持Skills,通用AI代理的新范式?
人工智能·ai·langchain·大模型·agentic ai
Python私教1 小时前
别让 API Key 裸奔:基于 TRAE SOLO 的大模型安全配置最佳实践
人工智能
Python私教1 小时前
Vibe Coding 体验报告:我让 TRAE SOLO 替我重构了 2000 行屎山代码,结果...
人工智能
prog_61031 小时前
【笔记】和各大AI语言模型写项目——手搓SDN后得到的经验
人工智能·笔记·语言模型
zhangfeng11331 小时前
深入剖析Kimi K2 Thinking与其他大规模语言模型(Large Language Models, LLMs)之间的差异
人工智能·语言模型·自然语言处理
paopao_wu2 小时前
人脸检测与识别-InsightFace:特征向量提取与识别
人工智能·目标检测