-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.py
59 lines (50 loc) · 1.65 KB
/
commands.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
import fire
from hydra import initialize
from mlopscourse.infer import Inferencer
from mlopscourse.train import Trainer
def train(
config_name: str,
config_path: str = "configs/",
hydra_version_base: str = "1.3",
**kwargs: dict,
) -> None:
"""
Trains the chosen model on the train split of the dataset and saves the checkpoint.
Parameters
----------
config_name : str
The name of the configuration file to use for model, training and inference
hyperparameters.
config_path : str
The path to the configuration files.
hydra_version_base : str
The compatibility level of hydra to use.
**kwargs : dict, optional
Values of the configuration file to override.
"""
with initialize(config_path=config_path, version_base=hydra_version_base):
Trainer(config_name, **kwargs).train()
def infer(
config_name: str,
config_path: str = "configs/",
hydra_version_base: str = "1.3",
**kwargs: dict,
) -> None:
"""
Runs the chosen model on the test set of the dataset and calculates the R^2 metric.
Parameters
----------
config_name : str
The name of the configuration file to use for model, training and inference
hyperparameters.
config_path : str
The path to the configuration files.
hydra_version_base : str
The compatibility level of hydra to use.
**kwargs : dict, optional
Values of the configuration file to override.
"""
with initialize(config_path=config_path, version_base=hydra_version_base):
Inferencer(config_name, **kwargs).infer()
if __name__ == "__main__":
fire.Fire()