-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment_runner.py
39 lines (28 loc) · 1.17 KB
/
experiment_runner.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
from utils.datasets import *
from utils.evaluations import *
from utils.models import *
from utils.trainer import *
import torch
def multiple_runs(experiment_description = "", n_runs = 1, n_epochs = 5,
model_args = dict(), data_args = dict(), optimizer_args = dict()):
from tqdm import tqdm
runs_losses = []
# experiments loop
for run in tqdm(range(n_runs)):
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# create data
data_experiment = TransferDatasetExperiment(description = 'sbm', data_args = data_args)
data_src, data_tgt = data_experiment.get_dataloaders()
data_src = data_src.to(device)
data_tgt = data_tgt.to(device)
# create model
model = create_model(model_args).to(device)
# training stuff initializations
optimizer = torch.optim.Adam(model.parameters(), **optimizer_args)
criterion = torch.nn.CrossEntropyLoss()
# training loop
trainer = Trainer(device, model, data_src, data_tgt, optimizer,
criterion, log_epochs = False)
trainer.train(epochs = n_epochs)
runs_losses.append(trainer.losses)
return get_results(runs_losses)