Skip to content

Commit

Permalink
Reset inputs when changing runs
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-segel authored and Sarah Krebs committed Jan 5, 2024
2 parents ea8554c + b806b00 commit 6a71ac9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Version 1.1.4

## Enhancements
- Fix lower bounds of dependency versions.

## Bug-Fixes
- Don't convert BOHB runs with status 'running' (consistent with SMAC).
- Reset inputs to fix error when subsequently selecting runs with different configspaces, objectives or budgets (#106)

# Version 1.1.3

Expand Down
14 changes: 9 additions & 5 deletions deepcave/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,15 @@ def plugin_input_update(pathname: str, *inputs_list: str) -> List[str]:
# because `run` would be removed.
# Also: We want to keep the current run name.
update_dict(_inputs, self.load_inputs())

# TODO: Reset only inputs which are not available in another run.
# E.g. if options from budget in run_2 and run_3 are the same
# take the budget from run_2 if changed to run_3. Otherwise,
# reset budgets.
# Reset inputs
if "objective_id" in _inputs.keys():
update_dict(_inputs, {"objective_id": {"value": None}})
if "budget_id" in _inputs.keys():
update_dict(_inputs, {"budget_id": {"value": None}})
if "hyperparameter_name_1" in _inputs.keys():
update_dict(_inputs, {"hyperparameter_name_1": {"value": None}})
if "hyperparameter_name_2" in _inputs.keys():
update_dict(_inputs, {"hyperparameter_name_2": {"value": None}})

selected_run = run_handler.get_run(_run_id)

Expand Down
4 changes: 4 additions & 0 deletions deepcave/plugins/hyperparameter/pdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ def load_dependency_inputs(self, run, previous_inputs, inputs):
objective_value = inputs["objective_id"]["value"]
budget_value = inputs["budget_id"]["value"]
hp1_value = inputs["hyperparameter_name_1"]["value"]
hp2_value = inputs["hyperparameter_name_2"]["value"]

if objective_value is None:
objective_value = objective_ids[0]
if budget_value is None:
budget_value = budget_ids[-1]
if hp1_value is None:
hp1_value = hp_names[0]

return {
Expand All @@ -160,6 +163,7 @@ def load_dependency_inputs(self, run, previous_inputs, inputs):
},
"hyperparameter_name_2": {
"options": get_checklist_options([None] + hp_names),
"value": hp2_value,
},
}

Expand Down
1 change: 1 addition & 0 deletions deepcave/plugins/objective/configuration_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def load_dependency_inputs(self, run, _, inputs):
# Pre-set values
if objective_value is None:
objective_value = objective_ids[0]
if budget_value is None:
budget_value = budget_ids[-1]
else:
budget_value = inputs["budget_id"]["value"]
Expand Down
6 changes: 2 additions & 4 deletions examples/record/mnist_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ def __init__(self, activation="relu", learning_rate=1e-4, dropout_rate=0.1, batc
]
)

self.accuracy = Accuracy()
self.accuracy = Accuracy(task="multiclass", num_classes=self.num_classes)

def prepare_data(self):
# download
MNIST(self.data_dir, train=True, download=True)
MNIST(self.data_dir, train=False, download=True)

def setup(self, stage=None):

# Assign train/val datasets for use in dataloaders
if stage == "fit" or stage is None:
mnist_full = MNIST(self.data_dir, train=True, transform=self.transform)
Expand Down Expand Up @@ -257,10 +256,9 @@ def get_configspace(seed):

# The model weights are trained
trainer = pl.Trainer(
accelerator="gpu",
accelerator="cpu",
devices=1,
num_sanity_val_steps=0, # No validation sanity
auto_scale_batch_size="power",
deterministic=True,
min_epochs=epochs,
max_epochs=epochs,
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
wheel
setuptools
wheel>=0.41.2
setuptools==68.2.2
absl-py>=1.0.0
jsonlines>=3.0.0
pandas>=1.3.4
numpy>=1.22.2
matplotlib>=3.5.1
seaborn>=0.13.0
pyyaml
pyyaml>=6.0.1

# AutoML packages
ConfigSpace==0.6.1
Expand All @@ -24,4 +24,4 @@ rq>=1.10.1
# Pinning might be removed for dash>2.3.0
werkzeug==2.0.3

pyPDPPartitioner
pyPDPPartitioner>=0.1.8
24 changes: 12 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ def read_file(file_name):
"dev": [
# Tests
"pytest>=4.6",
"pytest-cov",
"pytest-xdist",
"pytest-timeout",
"mypy",
"isort",
"black",
"pydocstyle",
"pre-commit",
"flake8",
"pytest-cov>=4.1.0",
"pytest-xdist>=3.3.1",
"pytest-timeout>=2.2.0",
"mypy>=1.6.1",
"isort>=5.12.0",
"black>=23.11.0",
"pydocstyle>=6.3.0",
"pre-commit>=3.5.0",
"flake8>=6.1.0",
# Docs
"automl-sphinx-theme>=0.1.10",
],
"examples": [
"torch",
"torchvision",
"pytorch-lightning",
"torch>=2.1.0",
"torchvision>=0.16.0",
"pytorch-lightning>=2.1.1",
],
}

Expand Down

0 comments on commit 6a71ac9

Please sign in to comment.