File size: 634 Bytes
f4b268b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from diffusers import StableDiffusionInpaintPipeline
from DeepCache import DeepCacheSDHelper
from importlib.util import find_spec


def optimize_sd_model(
    sd_model: StableDiffusionInpaintPipeline,
):
    """
    Optimizes a Stable Diffusion model for faster inference and less memory usage,
    and then returns the model
    """

    xformers_available = find_spec("xformers") is not None

    if xformers_available:
        sd_model.enable_xformers_memory_efficient_attention()

    helper = DeepCacheSDHelper(pipe=sd_model)
    helper.set_params(
        cache_interval=3,
        cache_branch_id=0,
    )

    return sd_model