mirror of
https://github.com/microsoft/autogen.git
synced 2025-09-20 13:43:58 +00:00

* Refactor into automl subpackage Moved some of the packages into an automl subpackage to tidy before the task-based refactor. This is in response to discussions with the group and a comment on the first task-based PR. Only changes here are moving subpackages and modules into the new automl, fixing imports to work with this structure and fixing some dependencies in setup.py. * Fix doc building post automl subpackage refactor * Fix broken links in website post automl subpackage refactor * Fix broken links in website post automl subpackage refactor * Remove vw from test deps as this is breaking the build * Move default back to the top-level I'd moved this to automl as that's where it's used internally, but had missed that this is actually part of the public interface so makes sense to live where it was. * Re-add top level modules with deprecation warnings flaml.data, flaml.ml and flaml.model are re-added to the top level, being re-exported from flaml.automl for backwards compatability. Adding a deprecation warning so that we can have a planned removal later. * Fix model.py line-endings * Pin pytorch-lightning to less than 1.8.0 We're seeing strange lightning related bugs from pytorch-forecasting since the release of lightning 1.8.0. Going to try constraining this to see if we have a fix. * Fix the lightning version pin Was optimistic with setting it in the 1.7.x range, but that isn't compatible with python 3.6 * Remove lightning version pin * Revert dependency version changes * Minor change to retrigger the build * Fix line endings in ml.py and model.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: EgorKraevTransferwise <egor.kraev@transferwise.com>
94 lines
2.3 KiB
Python
94 lines
2.3 KiB
Python
import sys
|
|
import pytest
|
|
from utils import get_toy_data_seqclassification, get_automl_settings
|
|
import os
|
|
import shutil
|
|
|
|
|
|
def custom_metric(
|
|
X_test,
|
|
y_test,
|
|
estimator,
|
|
labels,
|
|
X_train,
|
|
y_train,
|
|
weight_test=None,
|
|
weight_train=None,
|
|
config=None,
|
|
groups_test=None,
|
|
groups_train=None,
|
|
):
|
|
from datasets import Dataset
|
|
|
|
if estimator._trainer is None:
|
|
trainer = estimator._init_model_for_predict()
|
|
estimator._trainer = None
|
|
else:
|
|
trainer = estimator._trainer
|
|
X_test, y_test = estimator._tokenize_text(X_test)
|
|
|
|
if y_test is not None:
|
|
eval_dataset = Dataset.from_pandas(X_test.join(y_test))
|
|
else:
|
|
eval_dataset = Dataset.from_pandas(X_test)
|
|
|
|
estimator_metric_backup = estimator._metric
|
|
estimator._metric = "rmse"
|
|
metrics = trainer.evaluate(eval_dataset)
|
|
estimator._metric = estimator_metric_backup
|
|
|
|
return metrics.pop("eval_automl_metric"), metrics
|
|
|
|
|
|
@pytest.mark.skipif(sys.platform == "darwin", reason="do not run on mac os")
|
|
def test_custom_metric():
|
|
from flaml import AutoML
|
|
import requests
|
|
|
|
X_train, y_train, X_val, y_val, X_test = get_toy_data_seqclassification()
|
|
automl = AutoML()
|
|
|
|
try:
|
|
import ray
|
|
|
|
if not ray.is_initialized():
|
|
ray.init()
|
|
except ImportError:
|
|
return
|
|
|
|
automl_settings = get_automl_settings()
|
|
automl_settings["metric"] = custom_metric
|
|
automl_settings["use_ray"] = {"local_dir": "data/output/"}
|
|
|
|
try:
|
|
automl.fit(
|
|
X_train=X_train,
|
|
y_train=y_train,
|
|
X_val=X_val,
|
|
y_val=y_val,
|
|
**automl_settings
|
|
)
|
|
except requests.exceptions.HTTPError:
|
|
return
|
|
|
|
# testing calling custom metric in TransformersEstimator._compute_metrics_by_dataset_name
|
|
|
|
automl_settings["max_iter"] = 3
|
|
automl.fit(
|
|
X_train=X_train, y_train=y_train, X_val=X_val, y_val=y_val, **automl_settings
|
|
)
|
|
automl.score(X_val, y_val, **{"metric": custom_metric})
|
|
automl.pickle("automl.pkl")
|
|
|
|
del automl
|
|
|
|
if os.path.exists("test/data/output/"):
|
|
try:
|
|
shutil.rmtree("test/data/output/")
|
|
except PermissionError:
|
|
print("PermissionError when deleting test/data/output/")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_custom_metric()
|