File size: 775 Bytes
f949b3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import importlib
from functools import partialmethod


def instantiate_object(cls_path: str, *args, **kwargs):
    class_ = get_class(cls_path, *args, **kwargs)
    obj = class_()
    return obj


def get_class(cls_path: str, *args, **kwargs):
    module_name = ".".join(cls_path.split(".")[:-1])
    module = importlib.import_module(module_name)

    class_ = getattr(module, cls_path.split(".")[-1])
    class_.__init__ = partialmethod(class_.__init__, *args, **kwargs)
    return class_


if __name__ == "__main__":

    class_ = get_class(
        "diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler")
    scheduler = class_.from_config("stabilityai/stable-diffusion-2-1",
                                   subfolder="scheduler")
    print(scheduler)