diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

Sampler change

Open BoazKG93 opened this issue 3 years ago • 4 comments

I'm trying to control the sampler, but can't find a way to do it. How can I change the sampler?

BoazKG93 avatar Sep 07 '22 13:09 BoazKG93

A sampler is also called a scheduler.

There is an example of changing schedulers on the main readme:

from diffusers import LMSDiscreteScheduler

lms = LMSDiscreteScheduler(
    beta_start=0.00085, 
    beta_end=0.012, 
    beta_schedule="scaled_linear"
)

pipe = StableDiffusionPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4", 
    revision="fp16", 
    torch_dtype=torch.float16,
    scheduler=lms,
    use_auth_token=True
)
pipe = pipe.to("cuda")

prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cuda"):
    image = pipe(prompt).images[0]  
    
image.save("astronaut_rides_horse.png")

exo-pla-net avatar Sep 08 '22 02:09 exo-pla-net

thanks a lot for the answer @exo-pla-net ! We can always pass different schedulers when loading the pipeline.

Note: it's hacky and not recommneded but one can also set pipe.scheduler on already loaded pipeline.

patil-suraj avatar Sep 09 '22 11:09 patil-suraj

Related to: https://github.com/huggingface/diffusers/issues/336

patrickvonplaten avatar Sep 13 '22 16:09 patrickvonplaten

As discussed offline with @patrickvonplaten , re-opening this issue:

It has become a common practice to use different schedulers with SD but right now there isn't a clean way to change scheduler in a loaded pipeline. Also, it's not recommended to set pipeline.scheduler directly as it could lead to silent errors cf https://github.com/huggingface/diffusers/pull/1089#discussion_r1010756888

We will now allow this by making pipeline.scheduler a setter property method, which will do checks to see if the scheduler can be swapped and adopt the internal config accordingly. Also cc @pcuenca @anton-l

patil-suraj avatar Nov 02 '22 10:11 patil-suraj