diffusers/tools
1128
1#!/usr/bin/env python32import time3import torch4import safetensors.torch5from diffusers import StableDiffusionXLPipeline6 7pipe = StableDiffusionXLPipeline.from_pretrained(8 "stabilityai/stable-diffusion-xl-base-1.0",9 torch_dtype=torch.float16,10 variant="fp16",11 use_safetensors=True,12 local_files_only=True,13)14 15pipe = pipe.to("cuda")16 17# !wget https://civitai.com/api/download/models/135931 -O loras/pixel-art-xl.safetensors18lora_weights = safetensors.torch.load_file(19 "pixel-art-xl.safetensors", device="cpu"20)21 22for _ in range(5):23 t0 = time.perf_counter()24 pipe.load_lora_weights(lora_weights.copy())25 pipe.unload_lora_weights()26 print("Load + unload cycle took: ", time.perf_counter() - t0)27 