forked from AntreasAntoniou/CAPIT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
124 lines (105 loc) · 4.19 KB
/
run.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import os
import dotenv
import hydra
from hydra.core.config_store import ConfigStore
from omegaconf import DictConfig
from rich.traceback import install
# load environment variables from `.env` file if it exists
# recursively searches for `.env` in all folders starting from work dir
dotenv.load_dotenv(override=True, verbose=True)
install(show_locals=False, extra_lines=1, word_wrap=True, width=350)
def collect_config_store():
from mlproject.configs.config_tree import Config, base_callbacks, wandb_callbacks
from mlproject.configs.datamodules import (
InstagramImageTextMultiModalDataModuleConfig,
)
from mlproject.configs.hydra import add_hydra_configs
from mlproject.configs.loggers import (
TensorboardLoggerConfig,
WeightsAndBiasesLoggerConfig,
)
from mlproject.configs.mode import BaseMode
from mlproject.configs.models import CLIPImageTextMultiModalDatasetConfig
from mlproject.configs.optimizers import AdamWOptimizerConfig
from mlproject.configs.trainers import (
BaseTrainer,
DDPTrainer,
DPTrainer,
MPSTrainer,
)
config_store = ConfigStore.instance()
###################################################################################
config_store.store(name="config", node=Config)
###################################################################################
config_store.store(
group="callbacks",
name="base",
node=base_callbacks,
)
config_store.store(
group="callbacks",
name="wandb",
node=wandb_callbacks,
)
###################################################################################
config_store.store(
group="logger",
name="wandb",
node=dict(wandb_logger=WeightsAndBiasesLoggerConfig()),
)
config_store.store(
group="logger", name="tb", node=dict(logger=TensorboardLoggerConfig())
)
config_store.store(
group="logger",
name="wandb+tb",
node=dict(
tensorboard_logger=TensorboardLoggerConfig(),
wandb_logger=WeightsAndBiasesLoggerConfig(),
),
)
###################################################################################
config_store.store(
group="model",
name="clip-image-text",
node=CLIPImageTextMultiModalDatasetConfig,
)
###################################################################################
config_store.store(
group="datamodule",
name="InstagramImageTextMultiModal",
node=InstagramImageTextMultiModalDataModuleConfig,
)
###################################################################################
config_store.store(group="trainer", name="base", node=BaseTrainer)
config_store.store(group="trainer", name="gpu-dp", node=DPTrainer)
config_store.store(group="trainer", name="gpu-ddp", node=DDPTrainer)
config_store.store(group="trainer", name="mps", node=MPSTrainer)
###################################################################################
config_store = add_hydra_configs(config_store)
###################################################################################
config_store.store(
group="mode",
name="base",
node=BaseMode(),
)
###################################################################################
config_store.store(group="optimizer", name="AdamW", node=AdamWOptimizerConfig)
return config_store
config_store = collect_config_store()
@hydra.main(version_base=None, config_name="config")
def main(config: DictConfig):
# Imports can be nested inside @hydra.main to optimize tab completion
# https://github.com/facebookresearch/hydra/issues/934
from mlproject.base import utils
from mlproject.train_eval import train_eval
# A couple of optional utilities:
# - disabling python warnings
# - forcing debug-friendly configuration
# - verifying experiment name is set when running in experiment mode
# You can safely get rid of this line if you don't want those
utils.extras(config)
os.environ["WANDB_PROGRAM"] = config.code_dir
return train_eval(config)
if __name__ == "__main__":
main()