File size: 3,049 Bytes
69f6fc2
62fc896
69f6fc2
 
 
 
 
 
62fc896
 
 
 
 
 
 
69f6fc2
 
62fc896
 
 
 
 
69f6fc2
 
62fc896
69f6fc2
62fc896
 
 
 
 
 
 
 
69f6fc2
62fc896
 
 
 
 
 
 
 
 
 
 
 
69f6fc2
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
from diffusers import DiffusionPipeline, StableDiffusionPipeline, KDPM2DiscreteScheduler, KDPM2AncestralDiscreteScheduler, HeunDiscreteScheduler, DDIMScheduler, EulerDiscreteScheduler, EulerAncestralDiscreteScheduler, PNDMScheduler, LMSDiscreteScheduler, DPMSolverMultistepScheduler
import torch
import os

seed = 33
inference_steps = 25

#old_pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-base", custom_pipeline="/home/patrick_huggingface_co/diffusers/examples/community/sd_text2img_k_diffusion.py")
#old_pipe = old_pipe.to("cuda")
#old_pipe.set_progress_bar_config(disable=True)
pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2", torch_dtype=torch.float16)
#pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-base", torch_dtype=torch.float16)
pipe = pipe.to("cuda")


for prompt in ["astronaut riding horse", "whale falling from sky", "magical forest", "highly photorealistic picture of johnny depp"]:
    for sampler in ["sample_dpm_2_ancestral", "euler_ancestral", "sample_dpm_2", "sample_heun", "lms", "ddim", "euler", "pndm", "dpm"]:
#    for sampler in ["sample_dpm_2_ancestral"]:
#        old_pipe.set_sampler(sampler)
#        torch.manual_seed(0)
#        image = old_pipe(prompt, height=512, width=512, num_inference_steps=inference_steps).images[0]
        folder = f"a_{'_'.join(prompt.split())}"
        os.makedirs(f"/home/patrick_huggingface_co/images/{folder}", exist_ok=True)
#        image.save(f"/home/patrick_huggingface_co/images/{folder}/{sampler}.png")

#        pipe = StableDiffusionPipeline(**old_pipe.components)
#        pipe = pipe.to("cuda")
#        pipe.set_progress_bar_config(disable=True)
        if sampler == "sample_dpm_2":
            pipe.scheduler = KDPM2DiscreteScheduler.from_config(pipe.scheduler.config)
        elif sampler == "sample_dpm_2_ancestral":
            pipe.scheduler = KDPM2AncestralDiscreteScheduler.from_config(pipe.scheduler.config)
        elif sampler == "sample_heun":
            pipe.scheduler = HeunDiscreteScheduler.from_config(pipe.scheduler.config)
        elif sampler == "ddim":
            pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
        elif sampler == "dpm":
            pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
        elif sampler == "euler":
            pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
        elif sampler == "euler_ancestral":
            pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
        elif sampler == "pndm":
            pipe.scheduler = PNDMScheduler.from_config(pipe.scheduler.config)
        elif sampler == "lms":
            pipe.scheduler = LMSDiscreteScheduler.from_config(pipe.scheduler.config)

        torch.manual_seed(0)
        image = pipe(prompt, num_inference_steps=inference_steps).images[0]

        image.save(f"/home/patrick_huggingface_co/images/{folder}/hf_{sampler}.png")
    break