2021-12-03 12:45:16 -05:00
|
|
|
import sys
|
2021-11-18 09:39:45 -08:00
|
|
|
import pytest
|
2022-01-30 01:53:32 -05:00
|
|
|
import requests
|
2022-04-28 14:06:29 -04:00
|
|
|
from utils import get_toy_data_seqclassification, get_automl_settings
|
2022-10-12 20:04:42 -04:00
|
|
|
import os
|
|
|
|
import shutil
|
2021-11-18 09:39:45 -08:00
|
|
|
|
|
|
|
|
2021-12-03 12:45:16 -05:00
|
|
|
@pytest.mark.skipif(sys.platform == "darwin", reason="do not run on mac os")
|
2021-11-16 14:06:20 -05:00
|
|
|
def test_hf_data():
|
|
|
|
from flaml import AutoML
|
2022-01-24 17:24:14 -05:00
|
|
|
|
2022-04-28 14:06:29 -04:00
|
|
|
X_train, y_train, X_val, y_val, X_test = get_toy_data_seqclassification()
|
2021-11-16 14:06:20 -05:00
|
|
|
|
|
|
|
automl = AutoML()
|
|
|
|
|
2022-04-28 14:06:29 -04:00
|
|
|
automl_settings = get_automl_settings()
|
2022-08-20 18:17:10 -04:00
|
|
|
automl_settings["preserve_checkpoint"] = False
|
2021-11-16 14:06:20 -05:00
|
|
|
|
2022-01-30 01:53:32 -05:00
|
|
|
try:
|
|
|
|
automl.fit(
|
|
|
|
X_train=X_train,
|
|
|
|
y_train=y_train,
|
|
|
|
X_val=X_val,
|
|
|
|
y_val=y_val,
|
|
|
|
**automl_settings
|
|
|
|
)
|
2022-03-25 17:00:08 -04:00
|
|
|
automl.score(X_val, y_val, **{"metric": "accuracy"})
|
|
|
|
automl.pickle("automl.pkl")
|
2022-01-30 01:53:32 -05:00
|
|
|
except requests.exceptions.HTTPError:
|
|
|
|
return
|
2022-01-06 10:28:19 -08:00
|
|
|
|
2022-07-28 23:08:42 -04:00
|
|
|
import json
|
|
|
|
|
|
|
|
with open("seqclass.log", "r") as fin:
|
|
|
|
for line in fin:
|
|
|
|
each_log = json.loads(line.strip("\n"))
|
|
|
|
if "validation_loss" in each_log:
|
|
|
|
val_loss = each_log["validation_loss"]
|
|
|
|
min_inter_result = min(
|
|
|
|
each_dict.get("eval_automl_metric", sys.maxsize)
|
|
|
|
for each_dict in each_log["logged_metric"]["intermediate_results"]
|
|
|
|
)
|
|
|
|
|
|
|
|
if min_inter_result != sys.maxsize:
|
|
|
|
assert val_loss == min_inter_result
|
|
|
|
|
2021-11-16 14:06:20 -05:00
|
|
|
automl = AutoML()
|
2022-04-28 14:06:29 -04:00
|
|
|
|
|
|
|
automl_settings.pop("max_iter", None)
|
|
|
|
automl_settings.pop("use_ray", None)
|
|
|
|
automl_settings.pop("estimator_list", None)
|
|
|
|
|
2021-11-16 14:06:20 -05:00
|
|
|
automl.retrain_from_log(
|
|
|
|
X_train=X_train,
|
|
|
|
y_train=y_train,
|
|
|
|
train_full=True,
|
|
|
|
record_id=0,
|
|
|
|
**automl_settings
|
|
|
|
)
|
2022-10-04 10:51:12 -04:00
|
|
|
automl.predict(X_test, **{"per_device_eval_batch_size": 2})
|
2021-11-16 14:06:20 -05:00
|
|
|
automl.predict(["test test", "test test"])
|
|
|
|
automl.predict(
|
|
|
|
[
|
|
|
|
["test test", "test test"],
|
|
|
|
["test test", "test test"],
|
|
|
|
["test test", "test test"],
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2021-11-23 14:26:39 -05:00
|
|
|
automl.predict_proba(X_test)
|
|
|
|
print(automl.classes_)
|
|
|
|
|
2022-08-20 18:17:10 -04:00
|
|
|
del automl
|
|
|
|
|
2022-10-12 20:04:42 -04:00
|
|
|
if os.path.exists("test/data/output/"):
|
2022-11-27 11:22:54 -08:00
|
|
|
try:
|
|
|
|
shutil.rmtree("test/data/output/")
|
|
|
|
except PermissionError:
|
|
|
|
print("PermissionError when deleting test/data/output/")
|
2022-10-12 20:04:42 -04:00
|
|
|
|
2021-11-16 14:06:20 -05:00
|
|
|
|
2021-11-23 14:26:39 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
test_hf_data()
|