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

feat: New surrogate models API #669

Merged
merged 6 commits into from
May 15, 2023
Merged

feat: New surrogate models API #669

merged 6 commits into from
May 15, 2023

Conversation

jgolebiowski
Copy link
Collaborator

@jgolebiowski jgolebiowski commented May 15, 2023

Implementation of the new surrogate models API as discussed during the Surrogate-models-in-Syne-Tune meeting.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -0,0 +1,102 @@
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you think of a different name than contributed?

This sounds like we discourage contributions on the BO side.

cand_lst = [
hp_ranges.to_ndarray(config) for config in state.pending_configurations()
]
cand_lst = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change needs some comment, I am not sure this works out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was commited by mistake, already removed in the new commit.

@@ -174,31 +174,3 @@ def transform_state_to_data(
targets = np.vstack([targets * np.ones((1, num_fantasy_samples))] + fanta_lst)
features = np.vstack([features] + cand_lst)
return TransformedData(features, targets, mean, std)


class EstimatorFromTransformedData(Estimator):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove this one? I thought this is something we wanted to have

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

EstimatorWrapper now implements this function, its a rename + move rather than a removal.

raise NotImplementedError()


class ContributedPredictorWrapper(BasePredictor):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this one should move to models/contributed_estimator.py (except that "contributed" should become something else).

This is like for GP: The wrappers are in bayesopt/models (both estimator and predictor in the same wrapper code file), the code is in bayesopt/gpautograd

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok makes sense, will move.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And note that your code in bayesopt/contributed need not adhere to the estimator / predictor split, but you can keep everything in a single class. The split into two is only required one level up, in the wrappers.

That's what I did for the GP code, and also what we discussed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thats a good point but I wanted to keep them separated to make it more streamlined. This way we rely on the decoupled view through all the levels and I think it will be easier to follow for newer contributors. I know that I was confused by couplig/decoupling in GP code the first time I saw it.

return False


class ContributedEstimatorWrapper(Estimator):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should also move to models/contributed_estimator.py, and why not inherit from EstimatorFromTransformedData ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is just a rename of EstimatorFromTransformedData. I wanted to make estimator/predictor consistant with each other.

@codecov
Copy link

codecov bot commented May 15, 2023

Codecov Report

Patch coverage: 95.45% and project coverage change: +0.15 🎉

Comparison is base (80993db) 65.98% compared to head (bf829b0) 66.13%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #669      +/-   ##
==========================================
+ Coverage   65.98%   66.13%   +0.15%     
==========================================
  Files         381      386       +5     
  Lines       26917    27003      +86     
==========================================
+ Hits        17760    17859      +99     
+ Misses       9157     9144      -13     
Impacted Files Coverage Δ
.../schedulers/searchers/bayesopt/models/estimator.py 90.00% <ø> (+5.51%) ⬆️
...archers/bayesopt/tuning_algorithms/base_classes.py 84.52% <ø> (+1.19%) ⬆️
...schedulers/searchers/bayesopt/sklearn/predictor.py 71.42% <71.42%> (ø)
...schedulers/searchers/bayesopt/sklearn/estimator.py 87.50% <87.50%> (ø)
...ers/searchers/bayesopt/models/sklearn_predictor.py 94.11% <94.11%> (ø)
...ers/searchers/bayesopt/models/sklearn_estimator.py 100.00% <100.00%> (ø)
tst/schedulers/bayesopt/test_sklearn_surrogate.py 100.00% <100.00%> (ø)

... and 9 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mseeger
Copy link
Collaborator

mseeger commented May 15, 2023

OK, I think my main comment would be that only the wrapper code (in bayesopt/models) needs to follow predictor / estimator split, and not the code in the subdirectory.

@jgolebiowski jgolebiowski requested a review from mseeger May 15, 2023 11:29
mseeger
mseeger previously approved these changes May 15, 2023
Copy link
Collaborator

@mseeger mseeger left a comment

Choose a reason for hiding this comment

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

Just a small comment change.

input points ``inputs``. By default:

* "mean": Predictive means.
- "std": Predictive stddevs, shape ``(n,)``
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • instead of -

Copy link
Collaborator

Choose a reason for hiding this comment

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

But you could also drop this comment, because it is kind of just what the superclass has.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I wated to change it for both but dropped it. Adjusted this and the base class now.

@mseeger mseeger merged commit f803b85 into main May 15, 2023
30 checks passed
@mseeger mseeger deleted the 2022-05-11-surrogate-models branch May 15, 2023 19:15
@wesk wesk added the feature label May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants