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

相关推荐
蹦蹦跳跳真可爱5892 小时前
Python----深度学习(基于深度学习Pytroch簇分类,圆环分类,月牙分类)
人工智能·pytorch·python·深度学习·分类
蚂蚁20144 小时前
卷积神经网络(二)
人工智能·计算机视觉
z_mazin6 小时前
反爬虫机制中的验证码识别:类型、技术难点与应对策略
人工智能·计算机视觉·目标跟踪
lixy5797 小时前
深度学习3.7 softmax回归的简洁实现
人工智能·深度学习·回归
youhebuke2257 小时前
利用deepseek快速生成甘特图
人工智能·甘特图·deepseek
訾博ZiBo7 小时前
AI日报 - 2025年04月26日
人工智能
郭不耐7 小时前
DeepSeek智能时空数据分析(三):专业级地理数据可视化赏析-《杭州市国土空间总体规划(2021-2035年)》
人工智能·信息可视化·数据分析·毕业设计·数据可视化·城市规划
AI军哥7 小时前
MySQL8的安装方法
人工智能·mysql·yolo·机器学习·deepseek
余弦的倒数7 小时前
知识蒸馏和迁移学习的区别
人工智能·机器学习·迁移学习
Allen Bright7 小时前
【机器学习-线性回归-2】理解线性回归中的连续值与离散值
人工智能·机器学习·线性回归