File size: 1,166 Bytes
173ea2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import yaml
import os
import glob

CONFIG_DIR = "./BeamDiffusionModel/models/diffusionModel/configs"  # Directory containing config files

def load_all_configs():
    config = {}  # Start with an empty config

    # Find all YAML files in the directory (sorted for consistency)
    config_files = sorted(glob.glob(os.path.join(CONFIG_DIR, "*.yml")))

    for file_path in config_files:
        with open(file_path, "r") as file:
            new_config = yaml.safe_load(file) or {}  # Load config (avoid None)
            config = deep_merge(config, new_config)  # Merge into main config

    return config

def deep_merge(dict1, dict2):
    """Recursively merges two dictionaries (deep merge)."""
    for key, value in dict2.items():
        if isinstance(value, dict) and key in dict1 and isinstance(dict1[key], dict):
            dict1[key] = deep_merge(dict1[key], value)  # Recursively merge
        else:
            dict1[key] = value  # Overwrite
    return dict1

# Load and merge all configs automatically
CONFIG = load_all_configs()

print(os.getcwd())
print("Final Merged Config:")
print(CONFIG)  # Display merged config