-
Notifications
You must be signed in to change notification settings - Fork 312
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
Make sure random seed persists beyond storage #2671
Conversation
This pull request was exported from Phabricator. Differential Revision: D61479553 |
This pull request was exported from Phabricator. Differential Revision: D61479553 |
Summary: Pull Request resolved: facebook#2671 When the random seed is not specified in `model_kwargs`, it is set to a fixed value in `__init__`. If we do not store this generated `seed` and reload the experiment / GS, we end up continuing the random generation using a different seed. Storing `seed` in `model_state` will ensure it is stored (in last GR) and reused when the GS is reloaded. Model state is extracted from last GR in `GS._fit_current_model`: https://www.internalfb.com/code/fbsource/[4d9fa225216d]/fbcode/ax/modelbridge/generation_strategy.py?lines=856 This gets passed down to `ModelSpec.fit` as `**model_kwargs`, which takes precedence over `ModelSpec.model_kwargs`: https://www.internalfb.com/code/fbsource/[4d9fa225216d]/fbcode/ax/modelbridge/model_spec.py?lines=131, which will ensure any `"seed": None` kwarg will get overwritten by the generated seed from last GR. Also removed the `if not self.deduplicate` block from `_get_state`. Whether we save the state should not depend on `deduplicate`, as it is taken into account during sampling. Not saving the seed would just lead to additional unpredictability in the generator behavior. Reviewed By: bernardbeckerman Differential Revision: D61479553
fc90c42
to
f464ceb
Compare
Summary: Pull Request resolved: facebook#2671 When the random seed is not specified in `model_kwargs`, it is set to a fixed value in `__init__`. If we do not store this generated `seed` and reload the experiment / GS, we end up continuing the random generation using a different seed. Storing `seed` in `model_state` will ensure it is stored (in last GR) and reused when the GS is reloaded. Model state is extracted from last GR in `GS._fit_current_model`: https://www.internalfb.com/code/fbsource/[4d9fa225216d]/fbcode/ax/modelbridge/generation_strategy.py?lines=856 This gets passed down to `ModelSpec.fit` as `**model_kwargs`, which takes precedence over `ModelSpec.model_kwargs`: https://www.internalfb.com/code/fbsource/[4d9fa225216d]/fbcode/ax/modelbridge/model_spec.py?lines=131, which will ensure any `"seed": None` kwarg will get overwritten by the generated seed from last GR. Also removed the `if not self.deduplicate` block from `_get_state`. Whether we save the state should not depend on `deduplicate`, as it is taken into account during sampling. Not saving the seed would just lead to additional unpredictability in the generator behavior. Reviewed By: bernardbeckerman Differential Revision: D61479553
This pull request was exported from Phabricator. Differential Revision: D61479553 |
f464ceb
to
2a9ef9c
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2671 +/- ##
==========================================
- Coverage 95.29% 95.29% -0.01%
==========================================
Files 495 495
Lines 47766 47773 +7
==========================================
+ Hits 45517 45523 +6
- Misses 2249 2250 +1 ☔ View full report in Codecov by Sentry. |
This pull request has been merged in 40c8417. |
Summary:
When the random seed is not specified in
model_kwargs
, it is set to a fixed value in__init__
. If we do not store this generatedseed
and reload the experiment / GS, we end up continuing the random generation using a different seed. Storingseed
inmodel_state
will ensure it is stored (in last GR) and reused when the GS is reloaded.Model state is extracted from last GR in
GS._fit_current_model
: https://www.internalfb.com/code/fbsource/[4d9fa225216d]/fbcode/ax/modelbridge/generation_strategy.py?lines=856This gets passed down to
ModelSpec.fit
as**model_kwargs
, which takes precedence overModelSpec.model_kwargs
: https://www.internalfb.com/code/fbsource/[4d9fa225216d]/fbcode/ax/modelbridge/model_spec.py?lines=131, which will ensure any"seed": None
kwarg will get overwritten by the generated seed from last GR.Differential Revision: D61479553