-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
49 lines (35 loc) · 1.33 KB
/
example.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
from typing import Literal
import hydra
import optuna
from omegaconf import DictConfig
from hydra_trainer import BaseDataset, BaseTrainer
class ExampleDataset(BaseDataset):
def __init__(self, cfg: DictConfig, dataset_key: Literal["train", "eval"]):
super().__init__(cfg)
self.dataset_key = dataset_key
# TODO: implement dataset loading and preprocessing
raise NotImplementedError
def __len__(self):
# TODO: implement this method
raise NotImplementedError
def __getitem__(self, idx):
# TODO: implement this method
raise NotImplementedError
class ExampleTrainer(BaseTrainer[ExampleDataset, DictConfig]):
def model_init_factory(self):
def model_init(trial: optuna.Trial | None = None):
model_cfg = self.get_trial_model_cfg(trial, self.cfg)
# TODO: implement model initialization
raise NotImplementedError
return model_init
def dataset_factory(
self, dataset_cfg: DictConfig, dataset_key: Literal["train", "eval"]
) -> ExampleDataset:
# TODO: implement this method
raise NotImplementedError
@hydra.main(config_path="hydra_trainer", config_name="base", version_base=None)
def main(cfg: DictConfig):
trainer = ExampleTrainer(cfg)
trainer.train()
if __name__ == "__main__":
main()