You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to use HyperBand and define a total budget as shown in the documentation. However, the actual budget that is used by SMAC does not match the requested budget.
from __future__ importannotationsimportnumpyasnpfromConfigSpaceimportConfiguration, ConfigurationSpace, FloatfrommatplotlibimportpyplotaspltfromsmacimportMultiFidelityFacade, RunHistory, Scenariofromsmac.intensifier.hyperband_utilsimportget_n_trials_for_hyperband_multifidelity__copyright__="Copyright 2021, AutoML.org Freiburg-Hannover"__license__="3-clause BSD"classQuadraticFunction:
max_budget=500@propertydefconfigspace(self) ->ConfigurationSpace:
cs=ConfigurationSpace(seed=0)
x=Float("x", (-5, 5), default=-5)
cs.add([x])
returncsdeftrain(self, config: Configuration, seed: int=0, budget: float|None=None) ->float:
"""Returns the y value of a quadratic function with a minimum we know to be at x=0."""x=config["x"]
ifbudgetisNone:
multiplier=1else:
multiplier=1+budget/self.max_budgetreturnx**2*multiplierif__name__=="__main__":
model=QuadraticFunction()
total_budget=10000min_budget=10# minimum budget per trialmax_budget=500# maximum budget per trialeta=3# standard HB parameter influencing the number of stages# Let's calculate how many trials we need to exhaust the total optimization budget (in terms of# fidelity units)n_trials=get_n_trials_for_hyperband_multifidelity(
total_budget=total_budget, # this is the total optimization budget we specify in terms of fidelity unitsmin_budget=min_budget, # This influences the Hyperband rounds, minimum budget per trialmax_budget=max_budget, # This influences the Hyperband rounds, maximum budget per trialeta=eta, # This influences the Hyperband roundsprint_summary=True,
)
# Scenario object specifying the optimization "environment"scenario=Scenario(
model.configspace, deterministic=True, n_trials=n_trials, min_budget=min_budget, max_budget=max_budget
)
# Now we use SMAC to find the best hyperparameterssmac=MultiFidelityFacade(
scenario,
model.train, # We pass the target function hereoverwrite=True, # Overrides any previous results that are found that are inconsistent with the meta-dataintensifier=MultiFidelityFacade.get_intensifier(scenario=scenario, eta=eta),
)
incumbent=smac.optimize()
total_budget_used=sum([trial.budgetfortrialinsmac.runhistory])
print(f"Total budget defined: {total_budget}")
print(f"Total budget used: {total_budget_used}")
Expected Results
After calling get_n_trials_for_hyperband_multifidelity with a total budget of 10_000 I would expect the actual used budget to be less than or equal to 10_000.
Actual Results
The actual used budget is 25_611.11.
Versions
2.2.0
The text was updated successfully, but these errors were encountered:
becktepe
changed the title
[BUG]
[BUG] Problem with HyperBand setup given a total budget
Dec 6, 2024
Description
I wanted to use HyperBand and define a total budget as shown in the documentation. However, the actual budget that is used by SMAC does not match the requested budget.
The bug is caused by this line:
SMAC3/smac/intensifier/hyperband_utils.py
Line 47 in 9d19475
When computing the total budget of a HyperBand bracket we need to multiply the number of configs per budget by the respective budget:
After fixing this, the actual budget is
9_999.99
.Steps/Code to Reproduce
This is basically the example mentioned above:
Expected Results
After calling
get_n_trials_for_hyperband_multifidelity
with a total budget of10_000
I would expect the actual used budget to be less than or equal to10_000
.Actual Results
The actual used budget is
25_611.11
.Versions
2.2.0
The text was updated successfully, but these errors were encountered: