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

probabilistic reparameterization #1533

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sdaulton
Copy link
Contributor

Summary: Probabilistic reparameterization

Differential Revision: D41629217

@facebook-github-bot facebook-github-bot added CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported labels Nov 30, 2022
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D41629217

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D41629217

sdaulton added a commit to sdaulton/botorch that referenced this pull request Feb 4, 2023
Summary:
Pull Request resolved: pytorch#1533

Probabilistic reparameterization

Differential Revision: D41629217

fbshipit-source-id: 9e2cbd0686491a20dd12c82e5d86e72542a631df
@@ -273,7 +276,7 @@ def _optimize_batch_candidates(
if timeout_sec is not None:
timeout_sec = (timeout_sec - start_time) / len(batched_ics)

scipy_kws = {
gen_kws = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the variable is defined as gen_kws but line 296 uses gen_kwargs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! I have fixed this in the underlying PR. #1655

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding your comment in the PR repo about pure categorical spaces. Here is a WIP notebook on using pure categorical spaces. Not this implementation and notebook is still in development
discrete_mixed_bo_categorical.ipynb.txt

sdaulton added a commit to sdaulton/botorch that referenced this pull request Feb 8, 2023
Summary:
Pull Request resolved: pytorch#1533

Probabilistic reparameterization

Differential Revision: D41629217

fbshipit-source-id: 9b34a786a1e45a9c4d700369bf80b9342c5fa9b3
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D41629217

sdaulton added a commit to sdaulton/botorch that referenced this pull request Feb 8, 2023
Summary:
Pull Request resolved: pytorch#1533

Probabilistic reparameterization

Differential Revision: https://internalfb.com/D41629217

fbshipit-source-id: 0c30ef871080aa1b55c20b808212dfff39479f66
@codecov
Copy link

codecov bot commented Feb 8, 2023

Codecov Report

Merging #1533 (8be7d28) into main (63dd0cd) will decrease coverage by 2.71%.
The diff coverage is 12.71%.

❗ Current head 8be7d28 differs from pull request most recent head 7ce1389. Consider uploading reports for the commit 7ce1389 to get more accurate results

@@             Coverage Diff             @@
##              main    #1533      +/-   ##
===========================================
- Coverage   100.00%   97.29%   -2.71%     
===========================================
  Files          169      171       +2     
  Lines        14518    14949     +431     
===========================================
+ Hits         14518    14544      +26     
- Misses           0      405     +405     
Impacted Files Coverage Δ
...ch/acquisition/probabilistic_reparameterization.py 0.00% <0.00%> (ø)
botorch/models/transforms/input.py 67.79% <5.42%> (-32.21%) ⬇️
botorch/models/transforms/factory.py 71.79% <8.33%> (-28.21%) ⬇️
botorch/acquisition/fixed_feature.py 100.00% <100.00%> (ø)
botorch/acquisition/penalized.py 100.00% <100.00%> (ø)
botorch/acquisition/proximal.py 100.00% <100.00%> (ø)
botorch/acquisition/utils.py 100.00% <100.00%> (ø)
botorch/acquisition/wrapper.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@exs-hkenlay
Copy link

Hello @sdaulton. Thank you for providing the notebook. However it does not seem to work for me (I'm using commit e313e4c). I get an error in the BO loop at the line

new_x_pr, new_obj_pr = optimize_acqf_pr_and_get_observation(
    ei_pr, analytic=False
)

Which gives IndexError: index 0 is out of bounds for dimension 0 with size 0. This error comes from line 351 of botorch/acquisition/probabilistic_reparameterization.py. I set a flag in my debugger for this line and find unnormalized_X has shape (1, 17) but both self.integer_indices and self.integer_bounds are an empty torch.tensor([]) which is what causes this index error.

I tried adding the line integer_indices=list(categorical_features.keys()) in optimize_acqf_pr_and_get_observation so pr_acq_func is given by

pr_acq_func = MCProbabilisticReparameterization(
    acq_function=acq_func,
    one_hot_bounds=one_hot_bounds,
    categorical_features=categorical_features,
    integer_indices = list(categorical_features.keys()), # new line here
    batch_limit=128,
    mc_samples=4 if SMOKE_TEST else 128,
)

This seems to get the code to progress but then a different error is triggered on line 366 of botorch/acquisition/probabilistic_reparameterization.py. The error is RuntimeError: The expanded size of the tensor (1) must match the existing size (3) at non-singleton dimension 1. Target sizes: [1, 1]. Tensor sizes: [3].

Am I using the correct commit? You can run the notebook without errors?

sdaulton and others added 3 commits February 14, 2023 16:31
Summary:
Pull Request resolved: pytorch#1532

Add a wrapper for modifying inputs/outputs. This is useful for not only probabilistic reparameterization, but will also simplify other integrated AFs (e.g. MCMC) as well as fixed feature AFs and things like prior-guided AFs

Differential Revision: https://internalfb.com/D41629186

fbshipit-source-id: c2d3b339edf44a3167804b095d213b3ba98b5e13
Summary: Creates a new helper method for checking both if a given AF is an instance of a class or if the given AF wraps a base AF that is an instance of a class

Differential Revision: D43127722

fbshipit-source-id: 9f5f31b991f15f2b32931f1b9625422c7907495d
Summary:
Pull Request resolved: pytorch#1533

Probabilistic reparameterization

Differential Revision: D41629217

fbshipit-source-id: a6067c73ce534daf6f6a180fc49720f305827d58
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D41629217

sdaulton added a commit to sdaulton/botorch that referenced this pull request Feb 15, 2023
Summary:
Pull Request resolved: pytorch#1533

Probabilistic reparameterization

Differential Revision: https://internalfb.com/D41629217

fbshipit-source-id: f0719b974a8b9de4a1fe8fb62a9c73e9a1fbb551
@sdaulton
Copy link
Contributor Author

@hkenlay Sorry about that. I forgot to include the changes in there for categoricals. Let me know if you still have issues on 7ce1389

@exs-hkenlay
Copy link

Works great, and really exciting work, thanks @sdaulton.

@facebook-github-bot
Copy link
Contributor

Hi @sdaulton!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@dsanyal
Copy link

dsanyal commented Jul 7, 2023

Hello @sdaulton and @Balandat, thanks for this very exciting piece of work! Is there any timeline when this PR might be merged? :)

@sdaulton
Copy link
Contributor Author

Not at the moment. It's been fairly low priority. If this is of interest, I can work on prioritizing getting it ready

@dsanyal
Copy link

dsanyal commented Jul 11, 2023

Not at the moment. It's been fairly low priority. If this is of interest, I can work on prioritizing getting it ready

Thanks @sdaulton. I recently went through the paper, fantastic piece of work! I'd be very interested to try it out with botorch, especially to check out in practice how the new approach results in a speed-up over the brute-force combinatorical approach for mixed search spaces where the discrete parameter space contains several dimensions and levels.

@Ruan-Yixiang
Copy link

Ruan-Yixiang commented Jul 18, 2023

@hkenlay Sorry about that. I forgot to include the changes in there for categoricals. Let me know if you still have issues on 7ce1389

I recently read your interesting work. @sdaulton I try to use it in parallel chemical reaction optimization. In the notebook you provide I changed q=1 to q=2 in function optimize_acqf_pr_and_get_observation:

    candidates, _ = optimize_acqf(
        acq_function=pr_acq_func,
        bounds=standard_bounds,
        q=2,
        num_restarts=NUM_RESTARTS,
        raw_samples=RAW_SAMPLES,  # used for intialization heuristic
        options={
            "batch_limit": 5,
            "maxiter": 200,
            "rel_tol": float("-inf"),  # run for a full 200 steps
        },
        # use Adam for Monte Carlo PR
        gen_candidates=gen_candidates_torch if not analytic else gen_candidates_scipy,
    )

which raises error: AssertionError: Expected X to be `batch_shape x q=1 x d`, but got X with shape torch.Size([1024, 128, 2, 17]).
Did I make some mistake? Do you have the case whose batch size > 1 and space is mixed?
Thanks!

@sdaulton
Copy link
Contributor Author

Hi @Ruan-Yixiang, We didn't test q>1, so it is quite possible that this PR needs updating to support q>1. The MC formulation of PR could get pretty expensive if one is also using a MC acquisition function too (e.g. for q>1). It would be interesting to test out PR in the batch setting and determine ways of speeding things up.

@Ruan-Yixiang
Copy link

Ruan-Yixiang commented Jul 18, 2023

thanks for your apply! @sdaulton I may continue trying it. By the way, I tested the wall time of MC PR. It is strange that gen_candidates_torch in 4090 GPU is much slower (about 3 times) than gen_candidates_scipy in i9-13900k CPU. Do you know why? And have you compared the wall time of PR to Botorch's optimize_acqf_mixed which is achieved by enumerating combinations of categorical variables?

@dsanyal
Copy link

dsanyal commented Aug 19, 2023

@sdaulton Hi, may I ask if this PR is in progress? :)
Again, many thanks for your efforts!

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. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants