Skip to content

Commit 6ff0ed4

Browse files
authored
v0.2.5 (#30)
* test distillbert * import check * complete partial config * None check * init config is not suggested by bo * badge * notebook for lightgbm
1 parent 2d3bd84 commit 6ff0ed4

17 files changed

+2045
-1444
lines changed

.github/workflows/python-package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33

4-
name: Python package
4+
name: Build
55

66
on:
77
push:

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ dmypy.json
146146

147147
# Cython debug symbols
148148
cython_debug/
149-
/catboost_info
149+
150+
catboost_info
150151
notebook/*.pkl
151152
notebook/.azureml
153+
mlruns

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[![PyPI version](https://badge.fury.io/py/FLAML.svg)](https://badge.fury.io/py/FLAML)
2+
[![Build](https://github.com/microsoft/FLAML/actions/workflows/python-package.yml/badge.svg)](https://github.com/microsoft/FLAML/actions/workflows/python-package.yml)
3+
![Python Version](https://img.shields.io/badge/3.6%20%7C%203.7%20%7C%203.8-blue)
4+
[![Downloads](https://pepy.tech/badge/flaml/month)](https://pepy.tech/project/flaml)
5+
16
# FLAML - Fast and Lightweight AutoML
27

38
<p align="center">

flaml/__init__.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
from flaml.searcher import CFO, BlendSearch, FLOW2
2-
from flaml.automl import AutoML
2+
from flaml.automl import AutoML, logger_formatter
33
from flaml.version import __version__
44
import logging
55

66
# Set the root logger.
77
logger = logging.getLogger(__name__)
88
logger.setLevel(logging.INFO)
99

10-
# Add the console handler.
11-
_ch = logging.StreamHandler()
12-
logger_formatter = logging.Formatter(
13-
'[%(name)s: %(asctime)s] {%(lineno)d} %(levelname)s - %(message)s',
14-
'%m-%d %H:%M:%S')
15-
_ch.setFormatter(logger_formatter)
16-
logger.addHandler(_ch)

flaml/automl.py

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
import logging
2727
logger = logging.getLogger(__name__)
28+
logger_formatter = logging.Formatter(
29+
'[%(name)s: %(asctime)s] {%(lineno)d} %(levelname)s - %(message)s',
30+
'%m-%d %H:%M:%S')
31+
2832
try:
2933
import mlflow
3034
except:
@@ -326,6 +330,10 @@ def predict(self, X_test):
326330
A numpy array of shape n * 1 - - each element is a predicted class
327331
label for an instance.
328332
'''
333+
if self._trained_estimator is None:
334+
warnings.warn(
335+
"No estimator is trained. Please run fit with enough budget.")
336+
return None
329337
X_test = self._preprocess(X_test)
330338
y_pred = self._trained_estimator.predict(X_test)
331339
if y_pred.ndim > 1: y_pred = y_pred.flatten()
@@ -837,6 +845,11 @@ def custom_metric(X_test, y_test, estimator, labels,
837845
if eval_method == 'auto' or self._state.X_val is not None:
838846
eval_method = self._decide_eval_method(time_budget)
839847
self._state.eval_method = eval_method
848+
if not mlflow or not mlflow.active_run() and not logger.handler:
849+
# Add the console handler.
850+
_ch = logging.StreamHandler()
851+
_ch.setFormatter(logger_formatter)
852+
logger.addHandler(_ch)
840853
logger.info("Evaluation method: {}".format(eval_method))
841854

842855
self._retrain_full = retrain_full and (eval_method == 'holdout' and

flaml/searcher/blendsearch.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ def set_search_properties(self,
113113
self._deadline = config.get('time_budget_s') + time.time()
114114
if 'metric_target' in config:
115115
self._metric_target = config.get('metric_target')
116-
else:
117-
self._metric, self._mode = metric, mode
116+
else:
117+
if metric: self._metric = metric
118+
if mode: self._mode = mode
118119
self._ls.set_search_properties(metric, mode, config)
119120
if self._gs is not None:
120121
self._gs.set_search_properties(metric, mode, config)
@@ -300,11 +301,9 @@ def suggest(self, trial_id: str) -> Optional[Dict]:
300301
else: # use init config
301302
init_config = self._points_to_evaluate.pop(
302303
0) if self._points_to_evaluate else self._ls.init_config
303-
if init_config==self._ls.init_config:
304-
config = self._ls.complete_config(init_config,
304+
config = self._ls.complete_config(init_config,
305305
self._admissible_min, self._admissible_max)
306306
# logger.info(f"reset config to {config}")
307-
else: config = init_config
308307
config_signature = self._ls.config_signature(config)
309308
result = self._result.get(config_signature)
310309
if result: # tried before
@@ -314,7 +313,6 @@ def suggest(self, trial_id: str) -> Optional[Dict]:
314313
self._result[config_signature] = {}
315314
else: return None # running but no result yet
316315
self._init_used = True
317-
self._trial_proposed_by[trial_id] = 0
318316
# logger.info(f"config={config}")
319317
return config
320318

flaml/searcher/flow2.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ def _init_search(self):
190190
self._K = 0
191191
self._iter_best_config = self.trial_count = 1
192192
self._reset_times = 0
193+
# record intermediate trial cost
194+
self._trial_cost = {}
193195

194196
@property
195197
def step_lower_bound(self) -> float:
@@ -237,7 +239,8 @@ def complete_config(self, partial_config: Dict,
237239
''' generate a complete config from the partial config input
238240
add minimal resource to config if available
239241
'''
240-
if self._reset_times: # not the first time, use random gaussian
242+
if self._reset_times and partial_config==self.init_config:
243+
# not the first time to complete init_config, use random gaussian
241244
normalized = self.normalize(partial_config)
242245
for key in normalized:
243246
# don't change unordered cat choice
@@ -258,21 +261,22 @@ def complete_config(self, partial_config: Dict,
258261
normalized[key] = max(l, min(u, normalized[key] + delta))
259262
# use best config for unordered cat choice
260263
config = self.denormalize(normalized)
264+
self._reset_times += 1
261265
else:
266+
# first time init_config, or other configs, take as is
262267
config = partial_config.copy()
263268

264269
for key, value in self.space.items():
265270
if key not in config:
266271
config[key] = value
267-
logger.debug(f'before random {config}')
272+
# logger.debug(f'before random {config}')
268273
for _, generated in generate_variants({'config': config}):
269274
config = generated['config']
270275
break
271-
logger.debug(f'after random {config}')
276+
# logger.debug(f'after random {config}')
272277

273278
if self._resource:
274279
config[self.prune_attr] = self.min_resource
275-
self._reset_times += 1
276280
return config
277281

278282
def create(self, init_config: Dict, obj: float, cost: float) -> Searcher:
@@ -442,7 +446,8 @@ def on_trial_complete(self, trial_id: str, result: Optional[Dict] = None,
442446
if proposed_by == self.incumbent:
443447
# proposed by current incumbent and no better
444448
self._num_complete4incumbent += 1
445-
cost = result.get(self.cost_attr)
449+
cost = result.get(
450+
self.cost_attr) if result else self._trial_cost.get(trial_id)
446451
if cost: self._cost_complete4incumbent += cost
447452
if self._num_complete4incumbent >= 2*self.dim and \
448453
self._num_allowed4incumbent == 0:
@@ -483,6 +488,9 @@ def on_trial_result(self, trial_id: str, result: Dict):
483488
self._num_allowed4incumbent = 2 * self.dim
484489
self._proposed_by.clear()
485490
self._iter_best_config = self.trial_count
491+
cost = result.get(self.cost_attr)
492+
# record the cost in case it is pruned and cost info is lost
493+
self._trial_cost[trial_id] = cost
486494

487495
def rand_vector_unit_sphere(self, dim) -> np.ndarray:
488496
vec = self._random.normal(0, 1, dim)

flaml/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.4"
1+
__version__ = "0.2.5"

0 commit comments

Comments
 (0)