-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.py
More file actions
32 lines (25 loc) · 971 Bytes
/
util.py
File metadata and controls
32 lines (25 loc) · 971 Bytes
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
import torch
def compile_sdfast(model, reuse_layernorm = False):
from sfast.compilers.diffusion_pipeline_compiler import (compile,
CompilationConfig)
config = CompilationConfig.Default()
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')
config.enable_cuda_graph = True
config.reuse_layernorm = reuse_layernorm
model = compile(model, config)
return model
def compile_torch(pipe):
if hasattr(pipe, 'transformer'):
pipe.transformer = torch.compile(pipe.transformer, mode='reduce-overhead', fullgraph=True)
if hasattr(pipe, 'unet'):
pipe.unet = torch.compile(pipe.unet, mode='reduce-overhead', fullgraph=True)
return pipe