Skip to content

Commit 2ae2afe

Browse files
working on it
1 parent 71a50ed commit 2ae2afe

6 files changed

Lines changed: 168 additions & 133 deletions

File tree

TODO

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Residual models
2+
# run_benchmark
3+
# dataset.save() uses torch (nothing for sklearn)
4+
# LSTM model
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: default
22

33
# Metrics to compute; must match names registered via @metric in cybench/evaluation/eval.py
4-
metrics: [mse, mape, r2]
4+
metrics: [mse, mape, r2, normalized_rmse]

cybench/models/torch/trainer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
"""
99
import logging
1010
import os
11-
import random
1211
import time
1312
from functools import partial
1413
from typing import Any, Dict, Optional, Tuple
1514

1615
import numpy as np
1716
import torch
1817
import torch.nn as nn
19-
from torch.optim.lr_scheduler import LRScheduler
2018
from torch.utils.data import DataLoader
2119
from tqdm import tqdm
2220

@@ -316,7 +314,7 @@ def predict(self, dataset: TorchDataset, **kwargs) -> Tuple[np.ndarray, Dict[str
316314
return preds, info
317315

318316
def predict_items(self, X, **kwargs) -> Tuple[np.ndarray, Dict[str, Any]]:
319-
raise NotImplementedError # TODO: evaluate whether this methode is necessary
317+
raise NotImplementedError # TODO: evaluate whether this method is necessary
320318

321319
# ------------------------------------------------------------------
322320
# Persistence
@@ -340,7 +338,7 @@ def save(self, path: str, seed: int):
340338
torch.save(checkpoint, os.path.join(path, self.name + f"_{seed}.pt"))
341339

342340
@classmethod
343-
def load(cls, model_path: str, model: nn.Module, optimizer: torch.optim.Optimizer, **kwargs):
341+
def load(cls, name: str, model_path: str, model: nn.Module, optimizer: torch.optim.Optimizer, **kwargs):
344342
"""Load a saved checkpoint into a new Trainer instance."""
345343
device = kwargs.get('device', 'cuda' if torch.cuda.is_available() else 'cpu')
346344
ckpt = torch.load(model_path, map_location=device)
@@ -350,7 +348,8 @@ def load(cls, model_path: str, model: nn.Module, optimizer: torch.optim.Optimize
350348

351349
# Create new trainer instance
352350
trainer = cls(
353-
model=model,
351+
name=name,
352+
torch_model=model,
354353
optimizer=optimizer,
355354
device=device,
356355
dataloader=ckpt.get("dataloader", {}),

cybench/util/optuna_hyper_opt.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import logging
2-
import os
32
from pathlib import Path
4-
from typing import Any, Dict, Union
3+
from typing import Any, Union
54

6-
import hydra
75
import numpy as np
86
import optuna
9-
import yaml
107
from hydra.utils import instantiate
118
from omegaconf import DictConfig, OmegaConf
129

tests/datasets/test_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ def test_dataset_item(dataset):
5454
assert set(dataset[0].keys()) == set(expected_indices + expected_data)
5555

5656

57-
def test_split(dataset_cfg):
57+
def test_split():
5858
data_path_county_features = os.path.join(PATH_DATA_DIR, "features", "maize", "US")
5959
train_csv = os.path.join(data_path_county_features, "grain_maize_US_train.csv")
6060
train_df = pd.read_csv(train_csv, index_col=[KEY_LOC, KEY_YEAR])
6161
train_yields = train_df[[KEY_TARGET]].copy()
6262
feature_cols = [c for c in train_df.columns if c != KEY_TARGET]
6363
train_features = train_df[feature_cols].copy()
64-
dataset_cv = Dataset(dataset_cfg, train_yields, {KEY_COMBINED_FEATURES: train_features})
64+
dataset_cv = Dataset(None, train_yields, {KEY_COMBINED_FEATURES: train_features})
6565

6666
even_years = {x for x in dataset_cv.years if x % 2 == 0}
6767
odd_years = dataset_cv.years - even_years

0 commit comments

Comments
 (0)