Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let users swap schedulers #360

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docker_images/diffusers/app/pipelines/text_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
from typing import TYPE_CHECKING
import importlib

import torch
from app import idle, lora, timing, validation
Expand Down Expand Up @@ -65,6 +66,11 @@ def __init__(self, model_id: str):
if torch.cuda.is_available():
kwargs["torch_dtype"] = torch.float16

custom_scheduler = None
if "scheduler" in kwargs:
custom_scheduler = kwargs["scheduler"]
kwargs.pop("scheduler")

has_model_index = any(
file.rfilename == "model_index.json" for file in model_data.siblings
)
Expand Down Expand Up @@ -127,7 +133,14 @@ def __init__(self, model_id: str):
self.ldm.__class__.__init__.__annotations__.get("scheduler", None)
== KarrasDiffusionSchedulers
)
if self.is_karras_compatible:
if custom_scheduler:
compatibles = self.ldm.compatibles
is_compatible_scheduler = [cls for cls in compatibles if cls.__name__ == custom_scheduler]
if(is_compatible_scheduler):
SchedulerClass = getattr(importlib.import_module("diffusers.schedulers"), custom_scheduler)
self.ldm.scheduler = SchedulerClass.from_config(self.ldm.scheduler.config)

if self.is_karras_compatible and ((not custom_scheduler) or (custom_scheduler and not is_compatible_scheduler)):
self.ldm.scheduler = EulerAncestralDiscreteScheduler.from_config(
self.ldm.scheduler.config
)
Expand Down
Loading