Skip to content

Commit b73c992

Browse files
committed
[FIX] Tests after rebase of reg_cocktails (#359)
* update requirements * update requirements * resolve remaining conflicts and fix flake and mypy * Fix remaining tests and examples * fix failing checks * fix flake
1 parent 0d475fc commit b73c992

38 files changed

+297
-1032
lines changed

autoPyTorch/api/base_task.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -902,18 +902,15 @@ def run_traditional_ml(
902902
learning algorithm runs over the time limit.
903903
"""
904904
assert self._logger is not None # for mypy compliancy
905-
if STRING_TO_TASK_TYPES[self.task_type] in REGRESSION_TASKS:
906-
self._logger.warning("Traditional Pipeline is not enabled for regression. Skipping...")
907-
else:
908-
traditional_task_name = 'runTraditional'
909-
self._stopwatch.start_task(traditional_task_name)
910-
elapsed_time = self._stopwatch.wall_elapsed(current_task_name)
911-
time_for_traditional = int(runtime_limit - elapsed_time)
912-
self._do_traditional_prediction(
913-
func_eval_time_limit_secs=func_eval_time_limit_secs,
914-
time_left=time_for_traditional,
915-
)
916-
self._stopwatch.stop_task(traditional_task_name)
905+
traditional_task_name = 'runTraditional'
906+
self._stopwatch.start_task(traditional_task_name)
907+
elapsed_time = self._stopwatch.wall_elapsed(current_task_name)
908+
time_for_traditional = int(runtime_limit - elapsed_time)
909+
self._do_traditional_prediction(
910+
func_eval_time_limit_secs=func_eval_time_limit_secs,
911+
time_left=time_for_traditional,
912+
)
913+
self._stopwatch.stop_task(traditional_task_name)
917914

918915
def _search(
919916
self,
@@ -1283,22 +1280,7 @@ def _search(
12831280
self._logger.info("Starting Shutdown")
12841281

12851282
if proc_ensemble is not None:
1286-
self._results_manager.ensemble_performance_history = list(proc_ensemble.history)
1287-
1288-
if len(proc_ensemble.futures) > 0:
1289-
# Also add ensemble runs that did not finish within smac time
1290-
# and add them into the ensemble history
1291-
self._logger.info("Ensemble script still running, waiting for it to finish.")
1292-
result = proc_ensemble.futures.pop().result()
1293-
if result:
1294-
ensemble_history, _, _, _ = result
1295-
self._results_manager.ensemble_performance_history.extend(ensemble_history)
1296-
self._logger.info("Ensemble script finished, continue shutdown.")
1297-
1298-
# save the ensemble performance history file
1299-
if len(self.ensemble_performance_history) > 0:
1300-
pd.DataFrame(self.ensemble_performance_history).to_json(
1301-
os.path.join(self._backend.internals_directory, 'ensemble_history.json'))
1283+
self._collect_results_ensemble(proc_ensemble)
13021284

13031285
if load_models:
13041286
self._logger.info("Loading models...")
@@ -1566,7 +1548,7 @@ def fit_pipeline(
15661548
exclude=self.exclude_components,
15671549
search_space_updates=self.search_space_updates)
15681550
dataset_properties = dataset.get_dataset_properties(dataset_requirements)
1569-
self._backend.replace_datamanager(dataset)
1551+
self._backend.save_datamanager(dataset)
15701552

15711553
if self._logger is None:
15721554
self._logger = self._get_logger(dataset.dataset_name)
@@ -1757,7 +1739,7 @@ def fit_ensemble(
17571739
ensemble_fit_task_name = 'EnsembleFit'
17581740
self._stopwatch.start_task(ensemble_fit_task_name)
17591741
if enable_traditional_pipeline:
1760-
if func_eval_time_limit_secs is None or func_eval_time_limit_secs > time_for_task:
1742+
if func_eval_time_limit_secs > time_for_task:
17611743
self._logger.warning(
17621744
'Time limit for a single run is higher than total time '
17631745
'limit. Capping the limit for a single run to the total '
@@ -1798,12 +1780,8 @@ def fit_ensemble(
17981780
)
17991781

18001782
manager.build_ensemble(self._dask_client)
1801-
future = manager.futures.pop()
1802-
result = future.result()
1803-
if result is None:
1804-
raise ValueError("Errors occurred while building the ensemble - please"
1805-
" check the log file and command line output for error messages.")
1806-
self.ensemble_performance_history, _, _, _ = result
1783+
if manager is not None:
1784+
self._collect_results_ensemble(manager)
18071785

18081786
if load_models:
18091787
self._load_models()
@@ -1881,6 +1859,31 @@ def _init_ensemble_builder(
18811859

18821860
return proc_ensemble
18831861

1862+
def _collect_results_ensemble(
1863+
self,
1864+
manager: EnsembleBuilderManager
1865+
) -> None:
1866+
1867+
if self._logger is None:
1868+
raise ValueError("logger should be initialized to fit ensemble")
1869+
1870+
self._results_manager.ensemble_performance_history = list(manager.history)
1871+
1872+
if len(manager.futures) > 0:
1873+
# Also add ensemble runs that did not finish within smac time
1874+
# and add them into the ensemble history
1875+
self._logger.info("Ensemble script still running, waiting for it to finish.")
1876+
result = manager.futures.pop().result()
1877+
if result:
1878+
ensemble_history, _, _, _ = result
1879+
self._results_manager.ensemble_performance_history.extend(ensemble_history)
1880+
self._logger.info("Ensemble script finished, continue shutdown.")
1881+
1882+
# save the ensemble performance history file
1883+
if len(self.ensemble_performance_history) > 0:
1884+
pd.DataFrame(self.ensemble_performance_history).to_json(
1885+
os.path.join(self._backend.internals_directory, 'ensemble_history.json'))
1886+
18841887
def predict(
18851888
self,
18861889
X_test: np.ndarray,

autoPyTorch/api/tabular_classification.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from autoPyTorch.datasets.base_dataset import BaseDatasetPropertiesType
1818
from autoPyTorch.datasets.resampling_strategy import (
1919
HoldoutValTypes,
20+
CrossValTypes,
2021
ResamplingStrategies,
2122
)
2223
from autoPyTorch.datasets.tabular_dataset import TabularDataset
@@ -423,6 +424,7 @@ def search(
423424

424425
if self.dataset is None:
425426
raise ValueError("`dataset` in {} must be initialized, but got None".format(self.__class__.__name__))
427+
426428
return self._search(
427429
dataset=self.dataset,
428430
optimize_metric=optimize_metric,
@@ -462,23 +464,23 @@ def predict(
462464
raise ValueError("predict() is only supported after calling search. Kindly call first "
463465
"the estimator search() method.")
464466

465-
X_test = self.input_validator.feature_validator.transform(X_test)
467+
X_test = self.InputValidator.feature_validator.transform(X_test)
466468
predicted_probabilities = super().predict(X_test, batch_size=batch_size,
467469
n_jobs=n_jobs)
468470

469-
if self.input_validator.target_validator.is_single_column_target():
471+
if self.InputValidator.target_validator.is_single_column_target():
470472
predicted_indexes = np.argmax(predicted_probabilities, axis=1)
471473
else:
472474
predicted_indexes = (predicted_probabilities > 0.5).astype(int)
473475

474476
# Allow to predict in the original domain -- that is, the user is not interested
475477
# in our encoded values
476-
return self.input_validator.target_validator.inverse_transform(predicted_indexes)
478+
return self.InputValidator.target_validator.inverse_transform(predicted_indexes)
477479

478480
def predict_proba(self,
479481
X_test: Union[np.ndarray, pd.DataFrame, List],
480482
batch_size: Optional[int] = None, n_jobs: int = 1) -> np.ndarray:
481-
if self.input_validator is None or not self.input_validator._is_fitted:
483+
if self.InputValidator is None or not self.InputValidator._is_fitted:
482484
raise ValueError("predict() is only supported after calling search. Kindly call first "
483485
"the estimator search() method.")
484486
X_test = self.input_validator.feature_validator.transform(X_test)

autoPyTorch/api/tabular_regression.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from autoPyTorch.datasets.base_dataset import BaseDatasetPropertiesType
1818
from autoPyTorch.datasets.resampling_strategy import (
1919
HoldoutValTypes,
20+
CrossValTypes,
2021
ResamplingStrategies,
2122
)
2223
from autoPyTorch.datasets.tabular_dataset import TabularDataset
@@ -424,6 +425,7 @@ def search(
424425

425426
if self.dataset is None:
426427
raise ValueError("`dataset` in {} must be initialized, but got None".format(self.__class__.__name__))
428+
427429
return self._search(
428430
dataset=self.dataset,
429431
optimize_metric=optimize_metric,
@@ -449,14 +451,14 @@ def predict(
449451
batch_size: Optional[int] = None,
450452
n_jobs: int = 1
451453
) -> np.ndarray:
452-
if self.input_validator is None or not self.input_validator._is_fitted:
454+
if self.InputValidator is None or not self.InputValidator._is_fitted:
453455
raise ValueError("predict() is only supported after calling search. Kindly call first "
454456
"the estimator search() method.")
455457

456-
X_test = self.input_validator.feature_validator.transform(X_test)
458+
X_test = self.InputValidator.feature_validator.transform(X_test)
457459
predicted_values = super().predict(X_test, batch_size=batch_size,
458460
n_jobs=n_jobs)
459461

460462
# Allow to predict in the original domain -- that is, the user is not interested
461463
# in our encoded values
462-
return self.input_validator.target_validator.inverse_transform(predicted_values)
464+
return self.InputValidator.target_validator.inverse_transform(predicted_values)

autoPyTorch/data/base_target_validator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def fit(
8585
np.shape(y_test)
8686
))
8787
if isinstance(y_train, pd.DataFrame):
88-
y_train = cast(pd.DataFrame, y_train)
8988
y_test = cast(pd.DataFrame, y_test)
9089
if y_train.columns.tolist() != y_test.columns.tolist():
9190
raise ValueError(

autoPyTorch/data/tabular_feature_validator.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import functools
2+
<<<<<<< HEAD
23
from logging import Logger
34
from typing import Any, Dict, List, Mapping, Optional, Tuple, Union, cast
5+
=======
6+
from typing import Dict, List, Optional, Tuple, Type, Union, cast
7+
>>>>>>> [FIX] Tests after rebase of `reg_cocktails` (#359)
48

59
import numpy as np
610

@@ -277,8 +281,13 @@ def transform(
277281
if isinstance(X, np.ndarray):
278282
X = self.numpy_to_pandas(X)
279283

284+
<<<<<<< HEAD
280285
if hasattr(X, "iloc") and not issparse(X):
281286
X = cast(pd.DataFrame, X)
287+
=======
288+
if hasattr(X, "iloc") and not scipy.sparse.issparse(X):
289+
X = cast(Type[pd.DataFrame], X)
290+
>>>>>>> [FIX] Tests after rebase of `reg_cocktails` (#359)
282291

283292
# Check the data here so we catch problems on new test data
284293
self._check_data(X)
@@ -437,9 +446,6 @@ def _get_columns_info(
437446
Type of each column numerical/categorical
438447
"""
439448

440-
if len(self.transformed_columns) > 0 and self.feat_type is not None:
441-
return self.transformed_columns, self.feat_type
442-
443449
# Register if a column needs encoding
444450
numerical_columns = []
445451
categorical_columns = []

autoPyTorch/data/tabular_target_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional, Union, cast
1+
from typing import List, Optional, cast
22

33
import numpy as np
44

autoPyTorch/evaluation/fit_evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
from smac.tae import StatusType
1212

13+
from autoPyTorch.automl_common.common.utils.backend import Backend
1314
from autoPyTorch.datasets.resampling_strategy import NoResamplingStrategyTypes
1415
from autoPyTorch.evaluation.abstract_evaluator import (
1516
AbstractEvaluator,
1617
fit_and_suppress_warnings
1718
)
1819
from autoPyTorch.pipeline.components.training.metrics.base import autoPyTorchMetric
19-
from autoPyTorch.utils.backend import Backend
2020
from autoPyTorch.utils.common import subsampler
2121
from autoPyTorch.utils.hyperparameter_search_space_update import HyperparameterSearchSpaceUpdates
2222

autoPyTorch/optimizer/smbo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(self,
104104
resampling_strategy_args: Optional[Dict[str, Any]] = None,
105105
include: Optional[Dict[str, Any]] = None,
106106
exclude: Optional[Dict[str, Any]] = None,
107-
disable_file_output: List = [],
107+
disable_file_output: Union[bool, List[str]] = False,
108108
smac_scenario_args: Optional[Dict[str, Any]] = None,
109109
get_smac_object_callback: Optional[Callable] = None,
110110
all_supported_metrics: bool = True,

autoPyTorch/pipeline/components/setup/network_backbone/utils.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ class ShakeDropFunction(Function):
8383
Github URL: https://github.com/owruby/shake-drop_pytorch/blob/master/models/shakedrop.py
8484
"""
8585
@staticmethod
86-
<<<<<<< HEAD
8786
def forward(ctx: Any,
88-
=======
89-
def forward(ctx: typing.Any,
90-
>>>>>>> Bug fixes (#249)
9187
x: torch.Tensor,
9288
alpha: torch.Tensor,
9389
beta: torch.Tensor,
@@ -114,31 +110,20 @@ def backward(ctx: Any,
114110
shake_drop = ShakeDropFunction.apply
115111

116112

117-
<<<<<<< HEAD
118-
def shake_get_alpha_beta(is_training: bool, is_cuda: bool
119-
) -> Tuple[torch.Tensor, torch.Tensor]:
120-
"""
121-
The methods used in this function have been introduced in 'ShakeShake Regularisation'
122-
Currently, this function supports `shake-shake`.
123-
=======
124113
def shake_get_alpha_beta(
125114
is_training: bool,
126115
is_cuda: bool,
127116
method: str
128-
) -> typing.Tuple[torch.Tensor, torch.Tensor]:
117+
) -> Tuple[torch.Tensor, torch.Tensor]:
129118
"""
130119
The methods used in this function have been introduced in 'ShakeShake Regularisation'
131120
Each method name is available in the referred paper.
132121
Currently, this function supports `even-even`, `shake-even`, `shake-shake` and `M3`.
133-
>>>>>>> Bug fixes (#249)
134122
135123
Args:
136124
is_training (bool): Whether the computation for the training
137125
is_cuda (bool): Whether the tensor is on CUDA
138-
<<<<<<< HEAD
139-
=======
140126
method (str): The shake method either `even-even`, `shake-even`, `shake-shake` or `M3`
141-
>>>>>>> Bug fixes (#249)
142127
143128
Returns:
144129
alpha, beta (Tuple[float, float]):
@@ -150,14 +135,8 @@ def shake_get_alpha_beta(
150135
Author: Xavier Gastaldi
151136
URL: https://arxiv.org/abs/1705.07485
152137
153-
<<<<<<< HEAD
154-
Note:
155-
The names have been taken from the paper as well.
156-
Currently, this function supports `shake-shake`.
157-
=======
158138
The names have been taken from the paper as well.
159139
Currently, this function supports `even-even`, `shake-even`, `shake-shake` and `M3`.
160-
>>>>>>> Bug fixes (#249)
161140
"""
162141
if not is_training:
163142
result = (torch.FloatTensor([0.5]), torch.FloatTensor([0.5]))
@@ -187,27 +166,15 @@ def shake_get_alpha_beta(
187166

188167

189168
def shake_drop_get_bl(
190-
<<<<<<< HEAD
191-
block_index: int,
192-
min_prob_no_shake: float,
193-
num_blocks: int,
194-
is_training: bool,
195-
is_cuda: bool
196-
=======
197169
block_index: int,
198170
min_prob_no_shake: float,
199171
num_blocks: int,
200172
is_training: bool,
201173
is_cuda: bool
202-
>>>>>>> Bug fixes (#249)
203174
) -> torch.Tensor:
204175
"""
205176
The sampling of Bernoulli random variable
206177
based on Eq. (4) in the paper
207-
<<<<<<< HEAD
208-
209-
=======
210-
>>>>>>> Bug fixes (#249)
211178
Args:
212179
block_index (int): The index of the block from the input layer
213180
min_prob_no_shake (float): The initial shake probability
@@ -217,28 +184,16 @@ def shake_drop_get_bl(
217184
218185
Returns:
219186
bl (torch.Tensor): a Bernoulli random variable in {0, 1}
220-
<<<<<<< HEAD
221-
222-
=======
223-
>>>>>>> Bug fixes (#249)
224187
Reference:
225188
ShakeDrop Regularization for Deep Residual Learning
226189
Yoshihiro Yamada et. al. (2020)
227190
paper: https://arxiv.org/pdf/1802.02375.pdf
228191
implementation: https://github.com/imenurok/ShakeDrop
229192
"""
230-
<<<<<<< HEAD
231-
232-
pl = 1 - ((block_index + 1) / num_blocks) * (1 - min_prob_no_shake)
233-
234-
if is_training:
235-
# Move to torch.rand(1) for reproducibility
236-
=======
237193
pl = 1 - ((block_index + 1) / num_blocks) * (1 - min_prob_no_shake)
238194

239195
if is_training:
240196
# Move to torch.randn(1) for reproducibility
241-
>>>>>>> Bug fixes (#249)
242197
bl = torch.as_tensor(1.0) if torch.rand(1) <= pl else torch.as_tensor(0.0)
243198
else:
244199
bl = torch.as_tensor(pl)

0 commit comments

Comments
 (0)