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

Is there a way to set a random seed for the Ax Service API. #151

Closed
aagarwal1999 opened this issue Aug 14, 2019 · 8 comments
Closed

Is there a way to set a random seed for the Ax Service API. #151

aagarwal1999 opened this issue Aug 14, 2019 · 8 comments
Assignees
Labels
fixready Fix has landed on master. question Further information is requested

Comments

@aagarwal1999
Copy link

I have a use case in which users want to be able to view the trials they are going to run before they run them and I would like to show the exact values of the trials that are going to be run. Is there a way to set a random seed for the service API for reproducibility.

@lena-kashtelyan
Copy link
Contributor

lena-kashtelyan commented Aug 14, 2019

@aagarwal1999, yep, there is –– you will need to make a custom generation strategy. You can get one by resetting it right after your experiment:

ax_client = AxClient()
ax_client.create_experiment(...)
ax_client.generation_strategy = choose_generation_strategy(
    search_space=ax_client.experiment.search_space,
    random_seed=239,  # Whatever random seed you want.
)

You can import choose_generation_strategy from here:

def choose_generation_strategy(

Then, you will need to set the torch seed before each call to ax_client.get_next_trial, like so: torch.manual_seed(1000). More on the torch seed in this issue: #95.

Let me know if that fully solves the issue.

@lena-kashtelyan lena-kashtelyan self-assigned this Aug 14, 2019
@lena-kashtelyan lena-kashtelyan added the question Further information is requested label Aug 14, 2019
@aagarwal1999
Copy link
Author

aagarwal1999 commented Aug 15, 2019

I am getting an error stating:

TypeError: choose_generation_strategy() got an unexpected keyword argument 'random_seed'

I suspect this is due to the fact that I am not using the latest version of Ax. However, when I updated to the latest version, I was getting an import error when I try and import AxClient

File "/mnt/nfs/home/ankit/.conda/envs/dstorch-ankit/lib/python3.6/site-packages/ax/models/torch/botorch_defaults.py", line 21, in <module> from botorch.optim.optimize import optimize_acqf ImportError: cannot import name 'optimize_acqf'

@lena-kashtelyan
Copy link
Contributor

@aagarwal1999, you're right that the argument was unexpected because you had a later version; the BoTorch defaults import error, however, is news to me. Did you try to update BoTorch also?

@aagarwal1999
Copy link
Author

That fixed it! Thanks

@lena-kashtelyan
Copy link
Contributor

@aagarwal1999, also, I didn't know this when I responded to your question, but setting the random seed this say in the long run is non-ideal as it sets the seed for torch globally, which may impact model performance. I will have a fix for this on master by tomorrow –– will add a random_seed top-level argument to AxClient instantiation, which should make the seed safer to use.

@aagarwal1999
Copy link
Author

Hi, has the fix been implemented for the AxClient seed?

@aagarwal1999 aagarwal1999 reopened this Aug 23, 2019
@lena-kashtelyan
Copy link
Contributor

lena-kashtelyan commented Aug 23, 2019

Hi, Ankit! Not yet, but a partial fix will be on master soon (possibly today; I will update this issue like I said I would). Partial, because there isn't a way to fully make the Bayesian optimization part of the process reproducible (that is safe; I learned that setting the torch.manual_seed is not safe for the model performance). When we fix the torch seed, it's fixed globally, which can have drastic negative effects on the performance of the BoTorch-backed models, which we use for Bayesian optimization (that's what we are doing through the ad-hoc solution you are using now).

Now, the partial fix will provide a random seed setting to AxClient, which will make the initial quasi-random trials fully reproducible and the subsequent trials somewhat reproducible (but as you generate more trials, they will start differing more and more).

Finally, if you want reproducibility because you want your Ax optimization to use data from previous optimization, you can attach those trials via attach_trial and the data will be used in optimization. However, do make sure that those trials are actually applicable to the new optimization (for example, if you evaluate the trials on some data that has non-stationarity, then attaching data from an old optimization will worsen your new optimization results).

Let me know if that helps / makes sense!

facebook-github-bot pushed a commit that referenced this issue Aug 27, 2019
Summary: Provide an ability to fix random seed for reproducibility, people have been asking for this in open-source (e.g. #151)

Reviewed By: ldworkin

Differential Revision: D16813373

fbshipit-source-id: 020f8f1d30820551e0fcc8c0d0178e5f46420c7b
@lena-kashtelyan
Copy link
Contributor

Closing this issue because the random_seed argument for AxClient is now included into the latest stable version –– 0.1.5. Note that it does not make optimization fully reproducible, as described above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixready Fix has landed on master. question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants