set_config.py 1.47 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
18
19
20
21
def get_default_config():
    default_config = {
        "do_mm_calib": False,
        "cpu_offload": False,
        "parallel_attn_type": None,  # [None, "ulysses", "ring"]
        "parallel_vae": 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,
        "lora_path": None,
        "strength_model": 1.0,
22
        "mm_config": {},
helloyongyang's avatar
helloyongyang committed
23
        "use_prompt_enhancer": False,
helloyongyang's avatar
helloyongyang committed
24
25
26
27
    }
    return default_config


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

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

helloyongyang's avatar
helloyongyang committed
37
38
    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:
39
40
41
            model_config = json.load(f)
        config.update(model_config)

42
43
44
45
    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

46
    return config