-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.py
More file actions
70 lines (55 loc) · 2.27 KB
/
run.py
File metadata and controls
70 lines (55 loc) · 2.27 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import yaml
import logging
import argparse
# Set up logging configuration
logging.addLevelName(35, 'INFO')
logging.basicConfig(level='INFO', format='%(asctime)s - %(levelname)s - %(message)s')
# Importing main functions from the modules
from src.inference import main as inference
from src.merge_and_upload import main as merge_and_upload
from src.models.granite_vision.finetune import main as granite_vision_finetune
def run(config_path: str):
"""
Run modules based on the configuration file.
:param config_path: Path to the YAML configuration file.
"""
# Load the YAML configuration
with open(config_path, 'r') as file:
config = yaml.safe_load(file)
modules = config.get('modules', [])
if not modules:
logging.error("No modules configuration found in the YAML file.")
sys.exit(1)
# Map module names to their functions
module_map = {
'inference': lambda params: inference(**params),
'merge_and_upload': lambda params: merge_and_upload(**params),
'granite_vision_finetune': lambda params: granite_vision_finetune(**params)
}
try:
for step in modules:
module = step.get('module')
run = step.get('run', False)
params = step.get('params', {})
if not run:
logging.log(35, f"Skipping module: {module}...")
continue
if module not in module_map:
logging.error(f"Unknown module: {module}")
continue
logging.log(35, f"Running module: {module}{f' with params: {params}' if params else ''}...")
module_map[module](params)
logging.log(35, "Modules execution completed successfully.")
except Exception as e:
logging.error(f"An error occurred during the module execution: {e}", exc_info=True)
sys.exit(1)
def parse_arguments():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(description="Run the desired modules using a YAML configuration.")
parser.add_argument('--config', type=str, required=False, help="Path to the YAML configuration file.",
default='run_config.yaml')
return parser.parse_args()
if __name__ == '__main__':
args = parse_arguments()
run(args.config)