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

[Question] Is there a way to set a random state for reproducibility? #95

Closed
Irynei opened this issue May 21, 2019 · 5 comments
Closed
Assignees
Labels
question Further information is requested

Comments

@Irynei
Copy link

Irynei commented May 21, 2019

Hi!

I didn't find a possibility to set random seed in the docs, maybe I missed something.
Can you please tell if there is a way how to make results reproducible? Thanks.

@kkashin
Copy link
Contributor

kkashin commented May 21, 2019

@Irynei - what level are you looking for reproducibility at? The whole optimization loop or a specific generator?

You can set the seed for (quasi)-random generators, such as the Sobol generator (see https://ax.dev/api/models.html#ax.models.random.sobol.SobolGenerator.seed).

@kkashin kkashin added the question Further information is requested label May 21, 2019
@kkashin kkashin self-assigned this May 21, 2019
@Irynei
Copy link
Author

Irynei commented May 21, 2019

I was looking for the whole optimization loop, in the optimize method, ideally.

As far as I understand a (quasi)-random generator is chosen somehow under the hood?
So I can only set seed when I am using something similar to what explained here https://ax.dev/tutorials/gpei_hartmann_developer.html, right?

@bletham
Copy link
Contributor

bletham commented May 21, 2019

In that example (https://ax.dev/tutorials/gpei_hartmann_developer.html) there are two main sources of randomness: The scrambling in the Sobol generator used for the initialization, and the randomness in the (quasi) Monte Carlo approximation used in the acquisition function.

Like @kkashin says, the first can easily be handled by making the change to

sobol = Models.SOBOL(search_space=exp.search_space, seed=1000)

And yes, this will require using the more explicit API rather than optimize, whose purpose is to do a bunch of stuff under the hood for you.

Most of the randomness will come from that (the initialization). The actually Bayesian optimization phase will still have some randomness in that the acquisition function is evaluated with a Monte Carlo approximation. The seed for that is set here:

seed=torch.randint(1, 10000, (1,)).item(),

So, you can just run

torch.manual_seed(1000)

before every call to gpei.gen.

As a side note, for the purposes of benchmarking / performance evaluation I'd recommend setting the number of reps high enough that the seed doesn't matter. But of course there are other settings where reproducibility of a single run would be useful, and this should give that.

@Irynei
Copy link
Author

Irynei commented May 22, 2019

@bletham, thank you for a great explanation! It's clear to me now.

@kkashin
Copy link
Contributor

kkashin commented May 22, 2019

I'm going to close out this issue for now, given that you're unblocked. We will look into making it possible to pass a seed directly to the optimize function so that reproducibility is easier to achieve in the future, and will follow up with developments.

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

No branches or pull requests

3 participants