-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store state of stateful models, to add to kwargs when reinstantiating
Summary: Some of the Ax models (currently only `SobolGenerator`, but in the future Hyperband & others) have state, so it's not enough for those to record the kwargs, with which they've been instantiated. This diff introduces the logic used to store the state of those models, such that they can be reinstantiated from a generator run they produced. Reviewed By: stevemandala Differential Revision: D16993233 fbshipit-source-id: 5e96ec993535399e63446016c11cb2892b204b62
- Loading branch information
1 parent
4624478
commit 6298b14
Showing
10 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
|
||
from typing import Any, Dict | ||
|
||
|
||
class Model: | ||
"""Base class for an Ax model. | ||
Note: the core methods each model has: `fit`, `predict`, `gen`, | ||
`cross_validate`, and `best_point` are not present in this base class, | ||
because the signatures for those methods vary based on the type of the model. | ||
This class only contains the methods that all models have in common and for | ||
which they all share the signature. | ||
""" | ||
|
||
def _get_state(self) -> Dict[str, Any]: | ||
"""Obtain the state of this model, in order to be able to serialize it | ||
and restore it from the serialized version. | ||
While most models in Ax aren't stateful, some models, like `SobolGenerator`, | ||
are. For Sobol, the value of the `init_position` changes throughout the | ||
generation process as more arms are generated, and restoring the Sobol | ||
generator with all the same settings as it was initialized with, will not | ||
result in the same model, because the `init_position` setting changed | ||
throughout optimization. Stateful settings like that are returned from | ||
this method, so that a model can be reinstantiated and 'pick up where it | ||
left off' –– more arms can be generated as if the model just continued | ||
generation and was never interrupted and serialized. | ||
""" | ||
return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters