Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initial objective values to initial state for sample efficiency #2365

Closed
wants to merge 1 commit into from

Conversation

brunzema
Copy link
Contributor

@brunzema brunzema commented Jun 6, 2024

Motivation

Thank you for providing TuRBO as a small tutorial! In the notebook, however, the initial Y values are ignored in the TurboState which seems data inefficient. As this notebook is the starting point for multiple people if they want to compare against or use TuRBO, I believe this should be fixed.

I document my change below as the diff with notebooks is not super readable. :)

Old implementation (from https://botorch.org/tutorials/turbo_1):

X_turbo = get_initial_points(dim, n_init)
Y_turbo = torch.tensor(
    [eval_objective(x) for x in X_turbo], dtype=dtype, device=device
).unsqueeze(-1)

state = TurboState(dim, batch_size=batch_size)

Crucially, when updating the TurboState, only the most recent Y values (Y_next) are considered and, therefore, the initial points are discarded:

def update_state(state, Y_next):
    ...
    state.best_value = max(state.best_value, max(Y_next).item())

Long story short: I changed the initialization of the state to also include the initial Y values:

X_turbo = get_initial_points(dim, n_init)
Y_turbo = torch.tensor(
    [eval_objective(x) for x in X_turbo], dtype=dtype, device=device
).unsqueeze(-1)

state = TurboState(dim, batch_size=batch_size, best_value=max(Y_turbo).item())

Interestingly, this also (ever so slightly :D ) improves the final performance of TuRBO :)

OLD:
image

NEW:
image


I also added warning supression to the imports to hide my path--I hope that this is ok (I think I also saw this in other notebooks), but I can of course also change this back

Old first code cell:

import os
import math
from dataclasses import dataclass

import torch
from botorch.acquisition import qExpectedImprovement, qLogExpectedImprovement
from botorch.fit import fit_gpytorch_mll
from botorch.generation import MaxPosteriorSampling
from botorch.models import SingleTaskGP
from botorch.optim import optimize_acqf
from botorch.test_functions import Ackley
from botorch.utils.transforms import unnormalize
from torch.quasirandom import SobolEngine

import gpytorch
from gpytorch.constraints import Interval
from gpytorch.kernels import MaternKernel, ScaleKernel
from gpytorch.likelihoods import GaussianLikelihood
from gpytorch.mlls import ExactMarginalLogLikelihood
from gpytorch.priors import HorseshoePrior


device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
dtype = torch.double
SMOKE_TEST = os.environ.get("SMOKE_TEST")

New:

import os
import math
import warnings
from dataclasses import dataclass

import torch
from botorch.acquisition import qExpectedImprovement, qLogExpectedImprovement
from botorch.exceptions import BadInitialCandidatesWarning
from botorch.fit import fit_gpytorch_mll
from botorch.generation import MaxPosteriorSampling
from botorch.models import SingleTaskGP
from botorch.optim import optimize_acqf
from botorch.test_functions import Ackley
from botorch.utils.transforms import unnormalize
from torch.quasirandom import SobolEngine

import gpytorch
from gpytorch.constraints import Interval
from gpytorch.kernels import MaternKernel, ScaleKernel
from gpytorch.likelihoods import GaussianLikelihood
from gpytorch.mlls import ExactMarginalLogLikelihood


warnings.filterwarnings("ignore", category=BadInitialCandidatesWarning)
warnings.filterwarnings("ignore", category=RuntimeWarning)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
dtype = torch.double
SMOKE_TEST = os.environ.get("SMOKE_TEST")

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

I believe this minor change does not need a test plan.

Related PRs

PR does not change functionality.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jun 6, 2024
Copy link

codecov bot commented Jun 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.98%. Comparing base (8f25f5b) to head (34f7ee5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2365   +/-   ##
=======================================
  Coverage   99.98%   99.98%           
=======================================
  Files         190      190           
  Lines       16587    16587           
=======================================
  Hits        16584    16584           
  Misses          3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@facebook-github-bot
Copy link
Contributor

@sdaulton has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@sdaulton
Copy link
Contributor

lgtm, thanks!

@facebook-github-bot
Copy link
Contributor

@sdaulton merged this pull request in 8b32670.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants