File size: 1,046 Bytes
61f4807
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
import re

SDXL_DEFAULT_CONFIG = [
    {
        "wildcard_or_filter_func": lambda name: "up_blocks.2" not in name,
        "select_cache_step_func": lambda step: (step % 2) != 0,
    }
]

PIXART_DEFAULT_CONFIG = [
    {
        "wildcard_or_filter_func": lambda name: not re.search(
            r"transformer_blocks\.(2[1-7])\.", name
        ),
        "select_cache_step_func": lambda step: (step % 3) != 0,
    }
]

SVD_DEFAULT_CONFIG = [
    {
        "wildcard_or_filter_func": lambda name: "up_blocks.3" not in name,
        "select_cache_step_func": lambda step: (step % 2) != 0,
    }
]

SD3_DEFAULT_CONFIG = [
    {
        "wildcard_or_filter_func": lambda name: re.search(
            r"^((?!transformer_blocks\.(1[6-9]|2[0-3])).)*$", name
        ),
        "select_cache_step_func": lambda step: (step % 2) != 0,
    }
]


def replace_module(parent, name_path, new_module):
    path_parts = name_path.split(".")
    for part in path_parts[:-1]:
        parent = getattr(parent, part)
    setattr(parent, path_parts[-1], new_module)