Skip to content

Commit 43d4639

Browse files
ArlindKadraravinkohlinabenabe0928
authored
Bug fixes (#249)
* Update implementation * Coding style fixes * Implementation update * Style fix * Turn weighted loss into a constant again, implementation update * Cocktail branch inconsistencies (#275) * To nemo * Revert change in T_curr as results conclusively prove it should be 0 * Revert cutmix change after data from run * Final conclusion after results * FIX bug in shake alpha beta * Updated if is_training condition for shake drop * Remove temp fix in row cutmic * Cocktail fixes time debug (#286) * preprocess inside data validator * add time debug statements * Add fixes for categorical data * add fit_ensemble * add arlind fix for swa and se * fix bug in trainer choice fit * fix ensemble bug * Correct bug in cleanup * Cleanup for removing time debug statements * ablation for adversarial * shuffle false in dataloader * drop last false in dataloader * fix bug for validation set, and cutout and cutmix * shuffle = False * Shake Shake updates (#287) * To test locally * fix bug in trainer choice fit * fix ensemble bug * Correct bug in cleanup * To test locally * Cleanup for removing time debug statements * ablation for adversarial * shuffle false in dataloader * drop last false in dataloader * fix bug for validation set, and cutout and cutmix * To test locally * shuffle = False * To test locally * updates to search space * updates to search space * update branch with search space * undo search space update * fix bug in shake shake flag * limit to shake-even * restrict to even even * Add even even and others for shake-drop also * fix bug in passing alpha beta method * restrict to only even even * fix silly bug: * remove imputer and ordinal encoder for categorical transformer in feature validator * Address comments from shuhei * fix issues with ensemble fitting post hoc * Address comments on the PR * Fix flake and mypy errors * Address comments from PR #286 * fix bug in embedding * Update autoPyTorch/api/tabular_classification.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Update autoPyTorch/datasets/base_dataset.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Update autoPyTorch/datasets/base_dataset.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Update autoPyTorch/pipeline/components/training/trainer/base_trainer.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Address comments from shuhei * adress comments from shuhei * fix flake and mypy * Update autoPyTorch/pipeline/components/training/trainer/RowCutMixTrainer.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Update autoPyTorch/pipeline/tabular_classification.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Update autoPyTorch/pipeline/components/setup/network_backbone/utils.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Update autoPyTorch/pipeline/components/setup/network_backbone/utils.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Update autoPyTorch/pipeline/components/setup/network_backbone/utils.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * increase threads_per_worker * fix bug in rowcutmix * Enhancement for the tabular validator. (#291) * Initial try at an enhancement for the tabular validator * Adding a few type annotations * Fixing bugs in implementation * Adding wrongly deleted code part during rebase * Fix bug in _get_args * Fix bug in _get_args * Addressing Shuhei's comments * Address Shuhei's comments * Refactoring code * Refactoring code * Typos fix and additional comments * Replace nan in categoricals with simple imputer * Remove unused function * add comment * Update autoPyTorch/data/tabular_feature_validator.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Update autoPyTorch/data/tabular_feature_validator.py Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Adding unit test for only nall columns in the tabular feature categorical evaluator * fix bug in remove all nan columns * Bug fix for making tests run by arlind * fix flake errors in feature validator * made typing code uniform * Apply suggestions from code review Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * address comments from shuhei * address comments from shuhei (2) Co-authored-by: Ravin Kohli <kohliravin7@gmail.com> Co-authored-by: Ravin Kohli <13005107+ravinkohli@users.noreply.github.com> Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * resolve code issues with new versions * Address comments from shuhei * make run_traditional_ml function * implement suggestion from shuhei and fix bug in rowcutmixtrainer * fix return type docstring * add better documentation and fix bug in shake_drop_get_bl * Apply suggestions from code review Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * add test for comparator and other improvements based on PR comments * fix bug in test * [fix] Fix the condition in the raising error of all_nan_columns * [refactor] Unite name conventions of numpy array and pandas dataframe * [doc] Add the description about the tabular feature transformation * [doc] Add the description of the tabular feature transformation * address comments from arlind * address comments from arlind * change to as_tensor and address comments from arlind * correct description for functions in data module Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> Co-authored-by: Arlind Kadra <arlindkadra@gmail.com> Co-authored-by: nabenabe0928 <shuhei.watanabe.utokyo@gmail.com> * Addressing Shuhei's comments * flake8 problems fix * Update autoPyTorch/api/base_task.py Add indent. Co-authored-by: Ravin Kohli <13005107+ravinkohli@users.noreply.github.com> * Update autoPyTorch/api/base_task.py Add indent. Co-authored-by: Ravin Kohli <13005107+ravinkohli@users.noreply.github.com> * Update autoPyTorch/data/tabular_feature_validator.py Add indentation. Co-authored-by: Ravin Kohli <13005107+ravinkohli@users.noreply.github.com> * Update autoPyTorch/pipeline/components/setup/network_backbone/utils.py Add line indentation. Co-authored-by: Ravin Kohli <13005107+ravinkohli@users.noreply.github.com> * Update autoPyTorch/data/tabular_feature_validator.py Validate if there is a column transformer since for sparse matrices we will not have one. Co-authored-by: Ravin Kohli <13005107+ravinkohli@users.noreply.github.com> * Update autoPyTorch/utils/implementations.py Delete uncommented line. Co-authored-by: Ravin Kohli <13005107+ravinkohli@users.noreply.github.com> * Allow the number of threads to be given by the user * Removing unnecessary argument and refactoring the attribute. * Addressing Ravin's comments * Update autoPyTorch/pipeline/components/setup/network_backbone/utils.py Updating the function documentation according to the agreed style. Co-authored-by: Ravin Kohli <13005107+ravinkohli@users.noreply.github.com> * Update autoPyTorch/pipeline/components/setup/network_backbone/utils.py Providing information on the wrong method provided for shake-shake regularization. Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * add todo for backend and accept changes from shuhei * Addressing Shuhei's and Ravin's comments * Addressing Shuhei's and Ravin's comments, bug fix * Update autoPyTorch/pipeline/components/setup/network_backbone/ResNetBackbone.py Improving code readibility. Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * Update autoPyTorch/pipeline/components/setup/network_backbone/ResNetBackbone.py Improving consistency. Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> * bug fix Co-authored-by: Ravin Kohli <13005107+ravinkohli@users.noreply.github.com> Co-authored-by: nabenabe0928 <47781922+nabenabe0928@users.noreply.github.com> Co-authored-by: nabenabe0928 <shuhei.watanabe.utokyo@gmail.com> Co-authored-by: Ravin Kohli <kohliravin7@gmail.com>
1 parent 42a7676 commit 43d4639

41 files changed

Lines changed: 1279 additions & 611 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

autoPyTorch/api/base_task.py

Lines changed: 290 additions & 58 deletions
Large diffs are not rendered by default.

autoPyTorch/api/tabular_classification.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
class TabularClassificationTask(BaseTask):
2828
"""
2929
Tabular Classification API to the pipelines.
30+
3031
Args:
3132
seed (int):
3233
seed to be used for reproducibility.
3334
n_jobs (int), (default=1):
3435
number of consecutive processes to spawn.
36+
n_threads (int), (default=1):
37+
number of threads to use for each process.
3538
logging_config (Optional[Dict]):
3639
specifies configuration for logging, if None, it is loaded from the logging.yaml
3740
ensemble_size (int), (default=50):
@@ -63,6 +66,7 @@ def __init__(
6366
self,
6467
seed: int = 1,
6568
n_jobs: int = 1,
69+
n_threads: int = 1,
6670
logging_config: Optional[Dict] = None,
6771
ensemble_size: int = 50,
6872
ensemble_nbest: int = 50,
@@ -83,6 +87,7 @@ def __init__(
8387
super().__init__(
8488
seed=seed,
8589
n_jobs=n_jobs,
90+
n_threads=n_threads,
8691
logging_config=logging_config,
8792
ensemble_size=ensemble_size,
8893
ensemble_nbest=ensemble_nbest,
@@ -277,6 +282,8 @@ def search(
277282
y_test=y_test,
278283
dataset_name=dataset_name)
279284

285+
if self.dataset is None:
286+
raise ValueError("`dataset` in {} must be initialized, but got None".format(self.__class__.__name__))
280287
return self._search(
281288
dataset=self.dataset,
282289
optimize_metric=optimize_metric,

autoPyTorch/api/tabular_regression.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
class TabularRegressionTask(BaseTask):
2828
"""
2929
Tabular Regression API to the pipelines.
30+
3031
Args:
3132
seed (int): seed to be used for reproducibility.
32-
n_jobs (int), (default=1): number of consecutive processes to spawn.
33+
n_jobs (int), (default=1):
34+
number of consecutive processes to spawn.
35+
n_threads (int), (default=1):
36+
number of threads to use for each process.
3337
logging_config (Optional[Dict]): specifies configuration
3438
for logging, if None, it is loaded from the logging.yaml
3539
ensemble_size (int), (default=50): Number of models added to the ensemble built by
@@ -50,11 +54,11 @@ class TabularRegressionTask(BaseTask):
5054
Otherwise specifies set of components not to use. Incompatible with include
5155
components
5256
"""
53-
5457
def __init__(
5558
self,
5659
seed: int = 1,
5760
n_jobs: int = 1,
61+
n_threads: int = 1,
5862
logging_config: Optional[Dict] = None,
5963
ensemble_size: int = 50,
6064
ensemble_nbest: int = 50,
@@ -75,6 +79,7 @@ def __init__(
7579
super().__init__(
7680
seed=seed,
7781
n_jobs=n_jobs,
82+
n_threads=n_threads,
7883
logging_config=logging_config,
7984
ensemble_size=ensemble_size,
8085
ensemble_nbest=ensemble_nbest,
@@ -263,6 +268,8 @@ def search(
263268
y_test=y_test,
264269
dataset_name=dataset_name)
265270

271+
if self.dataset is None:
272+
raise ValueError("`dataset` in {} must be initialized, but got None".format(self.__class__.__name__))
266273
return self._search(
267274
dataset=self.dataset,
268275
optimize_metric=optimize_metric,

autoPyTorch/data/base_feature_validator.py

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
import typing
2+
from typing import List, Optional, Set, Tuple, Union
33

44
import numpy as np
55

@@ -12,8 +12,8 @@
1212
from autoPyTorch.utils.logging_ import PicklableClientLogger
1313

1414

15-
SUPPORTED_FEAT_TYPES = typing.Union[
16-
typing.List,
15+
SUPPORTED_FEAT_TYPES = Union[
16+
List,
1717
pd.DataFrame,
1818
np.ndarray,
1919
scipy.sparse.bsr_matrix,
@@ -29,66 +29,64 @@
2929
class BaseFeatureValidator(BaseEstimator):
3030
"""
3131
A class to pre-process features. In this regards, the format of the data is checked,
32-
and if applicable, features are encoded
32+
and if applicable, features are encoded.
33+
3334
Attributes:
3435
feat_type (List[str]):
3536
List of the column types found by this estimator during fit.
3637
data_type (str):
3738
Class name of the data type provided during fit.
38-
encoder (typing.Optional[BaseEstimator])
39+
encoder (Optional[BaseEstimator])
3940
Host a encoder object if the data requires transformation (for example,
40-
if provided a categorical column in a pandas DataFrame)
41-
enc_columns (typing.List[str])
42-
List of columns that were encoded.
41+
if provided a categorical column in a pandas DataFrame).
4342
"""
44-
def __init__(self,
45-
logger: typing.Optional[typing.Union[PicklableClientLogger, logging.Logger
46-
]] = None,
47-
) -> None:
43+
def __init__(
44+
self,
45+
logger: Optional[Union[PicklableClientLogger, logging.Logger]] = None,
46+
) -> None:
4847
# Register types to detect unsupported data format changes
49-
self.feat_type = None # type: typing.Optional[typing.List[str]]
50-
self.data_type = None # type: typing.Optional[type]
51-
self.dtypes = [] # type: typing.List[str]
52-
self.column_order = [] # type: typing.List[str]
48+
self.feat_type: Optional[List[str]] = None
49+
self.data_type: Optional[type] = None
50+
self.dtypes: List[str] = []
51+
self.column_order: List[str] = []
5352

54-
self.encoder = None # type: typing.Optional[BaseEstimator]
55-
self.enc_columns = [] # type: typing.List[str]
53+
self.column_transformer: Optional[BaseEstimator] = None
5654

57-
self.logger: typing.Union[
55+
self.logger: Union[
5856
PicklableClientLogger, logging.Logger
5957
] = logger if logger is not None else logging.getLogger(__name__)
6058

6159
# Required for dataset properties
62-
self.num_features = None # type: typing.Optional[int]
63-
self.categories = [] # type: typing.List[typing.List[int]]
64-
self.categorical_columns: typing.List[int] = []
65-
self.numerical_columns: typing.List[int] = []
66-
# column identifiers may be integers or strings
67-
self.null_columns: typing.Set[str] = set()
60+
self.num_features: Optional[int] = None
61+
self.categories: List[List[int]] = []
62+
self.categorical_columns: List[int] = []
63+
self.numerical_columns: List[int] = []
64+
65+
self.all_nan_columns: Optional[Set[Union[int, str]]] = None
6866

6967
self._is_fitted = False
7068

7169
def fit(
7270
self,
7371
X_train: SUPPORTED_FEAT_TYPES,
74-
X_test: typing.Optional[SUPPORTED_FEAT_TYPES] = None,
72+
X_test: Optional[SUPPORTED_FEAT_TYPES] = None,
7573
) -> BaseEstimator:
7674
"""
7775
Validates and fit a categorical encoder (if needed) to the features.
7876
The supported data types are List, numpy arrays and pandas DataFrames.
7977
CSR sparse data types are also supported
8078
81-
Arguments:
79+
Args:
8280
X_train (SUPPORTED_FEAT_TYPES):
8381
A set of features that are going to be validated (type and dimensionality
8482
checks) and a encoder fitted in the case the data needs encoding
85-
X_test (typing.Optional[SUPPORTED_FEAT_TYPES]):
83+
X_test (Optional[SUPPORTED_FEAT_TYPES]):
8684
A hold out set of data used for checking
8785
"""
8886

8987
# If a list was provided, it will be converted to pandas
9088
if isinstance(X_train, list):
91-
X_train, X_test = self.list_to_dataframe(X_train, X_test)
89+
X_train, X_test = self.list_to_pandas(X_train, X_test)
9290

9391
self._check_data(X_train)
9492

@@ -114,14 +112,15 @@ def _fit(
114112
X: SUPPORTED_FEAT_TYPES,
115113
) -> BaseEstimator:
116114
"""
117-
Arguments:
115+
Args:
118116
X (SUPPORTED_FEAT_TYPES):
119117
A set of features that are going to be validated (type and dimensionality
120118
checks) and a encoder fitted in the case the data needs encoding
121119
Returns:
122120
self:
123121
The fitted base estimator
124122
"""
123+
125124
raise NotImplementedError()
126125

127126
def _check_data(
@@ -131,19 +130,20 @@ def _check_data(
131130
"""
132131
Feature dimensionality and data type checks
133132
134-
Arguments:
133+
Args:
135134
X (SUPPORTED_FEAT_TYPES):
136135
A set of features that are going to be validated (type and dimensionality
137136
checks) and a encoder fitted in the case the data needs encoding
138137
"""
138+
139139
raise NotImplementedError()
140140

141141
def transform(
142142
self,
143143
X: SUPPORTED_FEAT_TYPES,
144144
) -> np.ndarray:
145145
"""
146-
Arguments:
146+
Args:
147147
X_train (SUPPORTED_FEAT_TYPES):
148148
A set of features, whose categorical features are going to be
149149
transformed
@@ -152,4 +152,30 @@ def transform(
152152
np.ndarray:
153153
The transformed array
154154
"""
155+
156+
raise NotImplementedError()
157+
158+
def list_to_pandas(
159+
self,
160+
X_train: SUPPORTED_FEAT_TYPES,
161+
X_test: Optional[SUPPORTED_FEAT_TYPES] = None,
162+
) -> Tuple[pd.DataFrame, Optional[pd.DataFrame]]:
163+
"""
164+
Converts a list to a pandas DataFrame. In this process, column types are inferred.
165+
166+
If test data is provided, we proactively match it to train data
167+
168+
Args:
169+
X_train (SUPPORTED_FEAT_TYPES):
170+
A set of features that are going to be validated (type and dimensionality
171+
checks) and a encoder fitted in the case the data needs encoding
172+
X_test (Optional[SUPPORTED_FEAT_TYPES]):
173+
A hold out set of data used for checking
174+
Returns:
175+
pd.DataFrame:
176+
transformed train data from list to pandas DataFrame
177+
pd.DataFrame:
178+
transformed test data from list to pandas DataFrame
179+
"""
180+
155181
raise NotImplementedError()

autoPyTorch/data/base_target_validator.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
import typing
2+
from typing import List, Optional, Union, cast
33

44
import numpy as np
55

@@ -12,8 +12,8 @@
1212
from autoPyTorch.utils.logging_ import PicklableClientLogger
1313

1414

15-
SUPPORTED_TARGET_TYPES = typing.Union[
16-
typing.List,
15+
SUPPORTED_TARGET_TYPES = Union[
16+
List,
1717
pd.Series,
1818
pd.DataFrame,
1919
np.ndarray,
@@ -35,48 +35,50 @@ class BaseTargetValidator(BaseEstimator):
3535
is_classification (bool):
3636
A bool that indicates if the validator should operate in classification mode.
3737
During classification, the targets are encoded.
38-
encoder (typing.Optional[BaseEstimator]):
38+
encoder (Optional[BaseEstimator]):
3939
Host a encoder object if the data requires transformation (for example,
4040
if provided a categorical column in a pandas DataFrame)
41-
enc_columns (typing.List[str])
41+
enc_columns (List[str])
4242
List of columns that where encoded
4343
"""
4444
def __init__(self,
4545
is_classification: bool = False,
46-
logger: typing.Optional[typing.Union[PicklableClientLogger, logging.Logger
47-
]] = None,
46+
logger: Optional[Union[PicklableClientLogger,
47+
logging.Logger
48+
]
49+
] = None,
4850
) -> None:
4951
self.is_classification = is_classification
5052

51-
self.data_type = None # type: typing.Optional[type]
53+
self.data_type: Optional[type] = None
5254

53-
self.encoder = None # type: typing.Optional[BaseEstimator]
55+
self.encoder: Optional[BaseEstimator] = None
5456

55-
self.out_dimensionality = None # type: typing.Optional[int]
56-
self.type_of_target = None # type: typing.Optional[str]
57+
self.out_dimensionality: Optional[int] = None
58+
self.type_of_target: Optional[str] = None
5759

58-
self.logger: typing.Union[
60+
self.logger: Union[
5961
PicklableClientLogger, logging.Logger
6062
] = logger if logger is not None else logging.getLogger(__name__)
6163

6264
# Store the dtype for remapping to correct type
63-
self.dtype = None # type: typing.Optional[type]
65+
self.dtype: Optional[type] = None
6466

6567
self._is_fitted = False
6668

6769
def fit(
6870
self,
6971
y_train: SUPPORTED_TARGET_TYPES,
70-
y_test: typing.Optional[SUPPORTED_TARGET_TYPES] = None,
72+
y_test: Optional[SUPPORTED_TARGET_TYPES] = None,
7173
) -> BaseEstimator:
7274
"""
7375
Validates and fit a categorical encoder (if needed) to the targets
7476
The supported data types are List, numpy arrays and pandas DataFrames.
7577
76-
Arguments:
78+
Args:
7779
y_train (SUPPORTED_TARGET_TYPES)
7880
A set of targets set aside for training
79-
y_test (typing.Union[SUPPORTED_TARGET_TYPES])
81+
y_test (Union[SUPPORTED_TARGET_TYPES])
8082
A hold out set of data used of the targets. It is also used to fit the
8183
categories of the encoder.
8284
"""
@@ -95,8 +97,8 @@ def fit(
9597
np.shape(y_test)
9698
))
9799
if isinstance(y_train, pd.DataFrame):
98-
y_train = typing.cast(pd.DataFrame, y_train)
99-
y_test = typing.cast(pd.DataFrame, y_test)
100+
y_train = cast(pd.DataFrame, y_train)
101+
y_test = cast(pd.DataFrame, y_test)
100102
if y_train.columns.tolist() != y_test.columns.tolist():
101103
raise ValueError(
102104
"Train and test targets must both have the same columns, yet "
@@ -127,24 +129,24 @@ def fit(
127129
def _fit(
128130
self,
129131
y_train: SUPPORTED_TARGET_TYPES,
130-
y_test: typing.Optional[SUPPORTED_TARGET_TYPES] = None,
132+
y_test: Optional[SUPPORTED_TARGET_TYPES] = None,
131133
) -> BaseEstimator:
132134
"""
133-
Arguments:
135+
Args:
134136
y_train (SUPPORTED_TARGET_TYPES)
135137
The labels of the current task. They are going to be encoded in case
136138
of classification
137-
y_test (typing.Optional[SUPPORTED_TARGET_TYPES])
139+
y_test (Optional[SUPPORTED_TARGET_TYPES])
138140
A holdout set of labels
139141
"""
140142
raise NotImplementedError()
141143

142144
def transform(
143145
self,
144-
y: typing.Union[SUPPORTED_TARGET_TYPES],
146+
y: Union[SUPPORTED_TARGET_TYPES],
145147
) -> np.ndarray:
146148
"""
147-
Arguments:
149+
Args:
148150
y (SUPPORTED_TARGET_TYPES)
149151
A set of targets that are going to be encoded if the current task
150152
is classification
@@ -161,8 +163,8 @@ def inverse_transform(
161163
"""
162164
Revert any encoding transformation done on a target array
163165
164-
Arguments:
165-
y (typing.Union[np.ndarray, pd.DataFrame, pd.Series]):
166+
Args:
167+
y (Union[np.ndarray, pd.DataFrame, pd.Series]):
166168
Target array to be transformed back to original form before encoding
167169
Returns:
168170
np.ndarray:

0 commit comments

Comments
 (0)