Sampler change
I'm trying to control the sampler, but can't find a way to do it. How can I change the sampler?
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")
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.
Related to: https://github.com/huggingface/diffusers/issues/336
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