@@ -94,7 +94,6 @@ def __init__(
94
94
optimization_config : Optional [OptimizationConfig ] = None ,
95
95
fit_out_of_design : bool = False ,
96
96
fit_abandoned : bool = False ,
97
- fit_on_init : bool = True ,
98
97
) -> None :
99
98
"""
100
99
Applies transforms and fits model.
@@ -123,19 +122,12 @@ def __init__(
123
122
fit_abandoned: Whether data for abandoned arms or trials should be
124
123
included in model training data. If ``False``, only
125
124
non-abandoned points are returned.
126
- fit_on_init: Whether to fit the model on initialization. This can
127
- be used to skip model fitting when a fitted model is not needed.
128
- To fit the model afterwards, use `_process_and_transform_data`
129
- to get the transformed inputs and call `_fit_if_implemented` with
130
- the transformed inputs.
131
125
"""
132
- t_fit_start = time .monotonic ()
126
+ t_fit_start = time .time ()
133
127
transforms = transforms or []
134
128
# pyre-ignore: Cast is a Tranform
135
129
transforms : List [Type [Transform ]] = [Cast ] + transforms
136
130
137
- self .fit_time : float = 0.0
138
- self .fit_time_since_gen : float = 0.0
139
131
self ._metric_names : Set [str ] = set ()
140
132
self ._training_data : List [Observation ] = []
141
133
self ._optimization_config : Optional [OptimizationConfig ] = optimization_config
@@ -146,89 +138,56 @@ def __init__(
146
138
self ._model_key : Optional [str ] = None
147
139
self ._model_kwargs : Optional [Dict [str , Any ]] = None
148
140
self ._bridge_kwargs : Optional [Dict [str , Any ]] = None
149
- self ._model_space : SearchSpace = search_space .clone ()
141
+
142
+ # pyre-fixme[4]: Attribute must be annotated.
143
+ self ._model_space = search_space .clone ()
150
144
self ._raw_transforms = transforms
151
145
self ._transform_configs : Optional [Dict [str , TConfig ]] = transform_configs
152
146
self ._fit_out_of_design = fit_out_of_design
153
147
self ._fit_abandoned = fit_abandoned
154
- self . _experiment_has_immutable_search_space_and_opt_config : bool = (
155
- experiment is not None and experiment . immutable_search_space_and_opt_config
156
- )
148
+ imm = experiment and experiment . immutable_search_space_and_opt_config
149
+ # pyre-fixme[4]: Attribute must be annotated.
150
+ self . _experiment_has_immutable_search_space_and_opt_config = imm
157
151
if experiment is not None :
158
152
if self ._optimization_config is None :
159
153
self ._optimization_config = experiment .optimization_config
160
154
self ._arms_by_signature = experiment .arms_by_signature
161
155
162
- # Convert Data to Observations, transform observations & search space.
163
- observations , search_space = self ._process_and_transform_data (
164
- experiment = experiment , data = data
165
- )
156
+ # Convert Data to Observations
157
+ observations = self ._prepare_observations (experiment = experiment , data = data )
166
158
167
- # Set model status quo.
159
+ observations_raw = self ._set_training_data (
160
+ observations = observations , search_space = search_space
161
+ )
162
+ # Set model status quo
168
163
# NOTE: training data must be set before setting the status quo.
169
164
self ._set_status_quo (
170
165
experiment = experiment ,
171
166
status_quo_name = status_quo_name ,
172
167
status_quo_features = status_quo_features ,
173
168
)
169
+ observations , search_space = self ._transform_data (
170
+ observations = observations_raw ,
171
+ search_space = search_space ,
172
+ transforms = transforms ,
173
+ transform_configs = transform_configs ,
174
+ )
174
175
175
- # Save model, apply terminal transform, and fit.
176
+ # Save model, apply terminal transform, and fit
176
177
self .model = model
177
- if fit_on_init :
178
- self ._fit_if_implemented (
179
- search_space = search_space ,
180
- observations = observations ,
181
- time_so_far = time .monotonic () - t_fit_start ,
182
- )
183
-
184
- def _fit_if_implemented (
185
- self ,
186
- search_space : SearchSpace ,
187
- observations : List [Observation ],
188
- time_so_far : float ,
189
- ) -> None :
190
- r"""Fits the model if `_fit` is implemented and stores fit time.
191
-
192
- Args:
193
- search_space: A transformed search space for fitting the model.
194
- observations: The observations to fit the model with. These should
195
- also be transformed.
196
- time_so_far: Time spent in initializing the model up to
197
- `_fit_if_implemented` call.
198
- """
199
178
try :
200
- t_fit_start = time .monotonic ()
201
179
self ._fit (
202
- model = self . model ,
180
+ model = model ,
203
181
search_space = search_space ,
204
182
observations = observations ,
205
183
)
206
- self .fit_time += time .monotonic () - t_fit_start + time_so_far
207
- self .fit_time_since_gen += self .fit_time
184
+ # pyre-fixme[4]: Attribute must be annotated.
185
+ self .fit_time = time .time () - t_fit_start
186
+ # pyre-fixme[4]: Attribute must be annotated.
187
+ self .fit_time_since_gen = float (self .fit_time )
208
188
except NotImplementedError :
209
- pass
210
-
211
- def _process_and_transform_data (
212
- self ,
213
- experiment : Optional [Experiment ] = None ,
214
- data : Optional [Data ] = None ,
215
- ) -> Tuple [List [Observation ], SearchSpace ]:
216
- r"""Processes the data into observations and returns transformed
217
- observations and the search space. This packages the following methods:
218
- * self._prepare_observations
219
- * self._set_training_data
220
- * self._transform_data
221
- """
222
- observations = self ._prepare_observations (experiment = experiment , data = data )
223
- observations_raw = self ._set_training_data (
224
- observations = observations , search_space = self ._model_space
225
- )
226
- return self ._transform_data (
227
- observations = observations_raw ,
228
- search_space = self ._model_space ,
229
- transforms = self ._raw_transforms ,
230
- transform_configs = self ._transform_configs ,
231
- )
189
+ self .fit_time = 0.0
190
+ self .fit_time_since_gen = 0.0
232
191
233
192
def _prepare_observations (
234
193
self , experiment : Optional [Experiment ], data : Optional [Data ]
@@ -607,7 +566,7 @@ def update(self, new_data: Data, experiment: Experiment) -> None:
607
566
`update`.
608
567
experiment: Experiment, in which this data was obtained.
609
568
"""
610
- t_update_start = time .monotonic ()
569
+ t_update_start = time .time ()
611
570
observations = self ._prepare_observations (experiment = experiment , data = new_data )
612
571
obs_raw = self ._extend_training_data (observations = observations )
613
572
observations , search_space = self ._transform_data (
@@ -620,8 +579,8 @@ def update(self, new_data: Data, experiment: Experiment) -> None:
620
579
search_space = search_space ,
621
580
observations = observations ,
622
581
)
623
- self .fit_time += time .monotonic () - t_update_start
624
- self .fit_time_since_gen += time .monotonic () - t_update_start
582
+ self .fit_time += time .time () - t_update_start
583
+ self .fit_time_since_gen += time .time () - t_update_start
625
584
626
585
def _update (
627
586
self ,
0 commit comments