File size: 1,063 Bytes
96a9519
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
from typing import Optional

from sfast.compilers.stable_diffusion_pipeline_compiler import CompilationConfig, compile

from ...pipeline import StreamDiffusion


def accelerate_with_stable_fast(
    stream: StreamDiffusion,
    config: Optional[CompilationConfig] = None,
):
    if config is None:
        config = CompilationConfig.Default()
        # xformers and Triton are suggested for achieving best performance.
        try:
            import xformers

            config.enable_xformers = True
        except ImportError:
            print("xformers not installed, skip")
        try:
            import triton

            config.enable_triton = True
        except ImportError:
            print("Triton not installed, skip")
        # CUDA Graph is suggested for small batch sizes and small resolutions to reduce CPU overhead.
        config.enable_cuda_graph = True
    stream.pipe = compile(stream.pipe, config)
    stream.unet = stream.pipe.unet
    stream.vae = stream.pipe.vae
    stream.text_encoder = stream.pipe.text_encoder
    return stream