1from diffusers.models import AutoencoderKL
2from diffusers import StableDiffusionPipeline
3from diffusers.schedulers.scheduling_dpmsolver_multistep import DPMSolverMultistepScheduler
4from PIL import Image
5import torch
6
7DPM_SOLVER_MULTI_STEP_SCHEDULER_CONFIG = {
8 "algorithm_type": "dpmsolver++",
9 "beta_end": 0.012,
10 "beta_schedule": "scaled_linear",
11 "beta_start": 0.00085,
12 "clip_sample": False,
13 "dynamic_thresholding_ratio": 0.995,
14 "euler_at_final": False,
15 "final_sigmas_type": "zero",
16 "lambda_min_clipped": float("-inf"),
17 "lower_order_final": True,
18 "num_train_timesteps": 1000,
19 "prediction_type": "epsilon",
20 "sample_max_value": 1.0,
21 "set_alpha_to_one": False,
22 "solver_order": 2,
23 "solver_type": "midpoint",
24 "steps_offset": 1,
25 "thresholding": False,
26 "timestep_spacing": "linspace",
27 "trained_betas": None,
28 "use_karras_sigmas": True,
29 "use_lu_lambdas": False,
30 "variance_type": None,
31}
32
33if __name__ == "__main__":
34 width = 512
35 height = int((width * 1.25 // 8) * 8)
36
37 vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse")
38 pipe = StableDiffusionPipeline.from_pretrained(
39 "runwayml/stable-diffusion-v1-5",
40 use_safetensors=True,
41 safety_checker=None,
42 vae=vae
43 ).to("cuda")
44 pipe.scheduler = DPMSolverMultistepScheduler.from_config(
45 DPM_SOLVER_MULTI_STEP_SCHEDULER_CONFIG,
46 )
47
48 prompt = "a cute robot digital illustration, full pose"
49 seed = 2544574284
50
51 images = []
52 scales = [-1, 0, 1, 1.5]
53
54 for scale in scales:
55 generator = torch.Generator(device="cpu").manual_seed(seed)
56 pipe.load_lora_weights("scenario-labs/more_details", weight_name="more_details.safetensors")
57 pipe.fuse_lora(lora_scale=scale)
58 image = pipe(
59 prompt,
60 generator=generator,
61 num_inference_steps=25,
62 num_samples=1,
63 width=width,
64 height=height
65 ).images[0]
66 pipe.unfuse_lora()
67 images.append(image)
68
69 # Combine images into a single row
70 combined_image = Image.new('RGB', (width * len(images), height))
71 x_offset = 0
72 for image in images:
73 combined_image.paste(image, (x_offset, 0))
74 x_offset += width
75
76 # Display the combined image
77 combined_image.save("demo.png")
78