set_config.py 2.33 KB
Newer Older
1
import json
2
import os
3
from easydict import EasyDict
4
from loguru import logger
5
6


helloyongyang's avatar
helloyongyang committed
7
8
9
10
11
12
13
14
15
16
17
def get_default_config():
    default_config = {
        "do_mm_calib": False,
        "cpu_offload": False,
        "max_area": False,
        "vae_stride": (4, 8, 8),
        "patch_size": (1, 2, 2),
        "feature_caching": "NoCaching",  # ["NoCaching", "TaylorSeer", "Tea"]
        "teacache_thresh": 0.26,
        "use_ret_steps": False,
        "use_bfloat16": True,
18
        "lora_configs": None,  # List of dicts with 'path' and 'strength' keys
19
        "mm_config": {},
helloyongyang's avatar
helloyongyang committed
20
        "use_prompt_enhancer": False,
21
        "parallel": False,
helloyongyang's avatar
helloyongyang committed
22
23
24
25
    }
    return default_config


26
def set_config(args):
helloyongyang's avatar
helloyongyang committed
27
28
    config = get_default_config()
    config.update({k: v for k, v in vars(args).items()})
29
30
    config = EasyDict(config)

helloyongyang's avatar
helloyongyang committed
31
    with open(config.config_json, "r") as f:
helloyongyang's avatar
helloyongyang committed
32
33
        config_json = json.load(f)
    config.update(config_json)
34

helloyongyang's avatar
helloyongyang committed
35
36
    if os.path.exists(os.path.join(config.model_path, "config.json")):
        with open(os.path.join(config.model_path, "config.json"), "r") as f:
helloyongyang's avatar
helloyongyang committed
37
38
39
40
            model_config = json.load(f)
        config.update(model_config)
    elif os.path.exists(os.path.join(config.model_path, "low_noise_model", "config.json")):  # 需要一个更优雅的update方法
        with open(os.path.join(config.model_path, "low_noise_model", "config.json"), "r") as f:
41
42
            model_config = json.load(f)
        config.update(model_config)
gushiqiao's avatar
gushiqiao committed
43
44
45
46
47
    elif os.path.exists(os.path.join(config.model_path, "original", "config.json")):
        with open(os.path.join(config.model_path, "original", "config.json"), "r") as f:
            model_config = json.load(f)
        config.update(model_config)
    # load quantized config
gushiqiao's avatar
gushiqiao committed
48
49
50
51
52
53
54
    if config.get("dit_quantized_ckpt", None) is not None:
        config_path = os.path.join(config.dit_quantized_ckpt, "config.json")
        if os.path.exists(config_path):
            with open(config_path, "r") as f:
                model_config = json.load(f)
            config.update(model_config)

Watebear's avatar
Watebear committed
55
56
57
58
    if config.task == "i2v":
        if config.target_video_length % config.vae_stride[0] != 1:
            logger.warning(f"`num_frames - 1` has to be divisible by {config.vae_stride[0]}. Rounding to the nearest number.")
            config.target_video_length = config.target_video_length // config.vae_stride[0] * config.vae_stride[0] + 1
59

60
    return config