A programming framework for agentic AI
adding catch for HTTP error (#432)
Xueqing Liu438ccaa0c941
diff --git a/test/nlp/test_autohf.py b/test/nlp/test_autohf.pyindex b31832717..e882a78da 100644--- a/test/nlp/test_autohf.py+++ b/test/nlp/test_autohf.py@@ -2,6 +2,7 @@ import sysimport pytestimport pickleimport shutil+import requests@pytest.mark.skipif(sys.platform == "darwin", reason="do not run on mac os")@@ -92,9 +93,16 @@ def test_hf_data():"fp16": False,}- automl.fit(- X_train=X_train, y_train=y_train, X_val=X_val, y_val=y_val, **automl_settings- )+ 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:+ returnautoml = AutoML()automl.retrain_from_log(@@ -132,8 +140,8 @@ def _test_custom_data():train_dataset = pd.read_csv("data/input/train.tsv", delimiter="\t", quoting=3)dev_dataset = pd.read_csv("data/input/dev.tsv", delimiter="\t", quoting=3)test_dataset = pd.read_csv("data/input/test.tsv", delimiter="\t", quoting=3)- except requests.exceptions.ConnectionError:- pass+ except requests.exceptions.HTTPError:+ returncustom_sent_keys = ["#1 String", "#2 String"]label_key = "Quality"diff --git a/test/nlp/test_autohf_classificationhead.py b/test/nlp/test_autohf_classificationhead.pyindex 1492f67a4..2a19e5129 100644--- a/test/nlp/test_autohf_classificationhead.py+++ b/test/nlp/test_autohf_classificationhead.py@@ -1,6 +1,7 @@def test_classification_head():from flaml import AutoMLimport pandas as pd+ import requeststrain_data = {"text": [@@ -54,10 +55,17 @@ def test_classification_head():automl_settings["custom_hpo_args"] = {"model_path": "google/electra-small-discriminator","output_dir": "test/data/output/",- "ckpt_per_epoch": 5,+ "ckpt_per_epoch": 1,"fp16": False,}- automl.fit(- X_train=X_train, y_train=y_train, X_val=X_val, y_val=y_val, **automl_settings- )+ 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:+ returndiff --git a/test/nlp/test_autohf_custom_metric.py b/test/nlp/test_autohf_custom_metric.pyindex 088b386e5..a3dee305b 100644--- a/test/nlp/test_autohf_custom_metric.py+++ b/test/nlp/test_autohf_custom_metric.py@@ -43,6 +43,7 @@ def custom_metric(def test_custom_metric():from flaml import AutoMLimport pandas as pd+ import requeststrain_data = {"sentence1": [@@ -105,13 +106,20 @@ def test_custom_metric():automl_settings["custom_hpo_args"] = {"model_path": "google/electra-small-discriminator","output_dir": "data/output/",- "ckpt_per_epoch": 5,+ "ckpt_per_epoch": 1,"fp16": False,}- automl.fit(- X_train=X_train, y_train=y_train, X_val=X_val, y_val=y_val, **automl_settings- )+ 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_namediff --git a/test/nlp/test_autohf_cv.py b/test/nlp/test_autohf_cv.pyindex bf90652da..06aeb2b70 100644--- a/test/nlp/test_autohf_cv.py+++ b/test/nlp/test_autohf_cv.py@@ -6,6 +6,7 @@ import pytestdef test_cv():from flaml import AutoMLimport pandas as pd+ import requeststrain_data = {"sentence1": [@@ -49,7 +50,10 @@ def test_cv():"fp16": False,}- automl.fit(X_train=X_train, y_train=y_train, **automl_settings)+ try:+ automl.fit(X_train=X_train, y_train=y_train, **automl_settings)+ except requests.exceptions.HTTPError:+ returnif __name__ == "__main__":diff --git a/test/nlp/test_autohf_multichoice_classification.py b/test/nlp/test_autohf_multichoice_classification.pyindex 83c35e9ac..5d49809b0 100644--- a/test/nlp/test_autohf_multichoice_classification.py+++ b/test/nlp/test_autohf_multichoice_classification.py@@ -5,7 +5,7 @@ import pytest@pytest.mark.skipif(sys.platform == "darwin", reason="do not run on mac os")def test_mcc():from flaml import AutoML-+ import requestsimport pandas as pdtrain_data = {@@ -219,13 +219,20 @@ def test_mcc():automl_settings["custom_hpo_args"] = {"model_path": "google/electra-small-discriminator","output_dir": "test/data/output/",- "ckpt_per_epoch": 5,+ "ckpt_per_epoch": 1,"fp16": False,}- automl.fit(- X_train=X_train, y_train=y_train, X_val=X_val, y_val=y_val, **automl_settings- )+ 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:+ returny_pred = automl.predict(X_test)proba = automl.predict_proba(X_test)diff --git a/test/nlp/test_autohf_regression.py b/test/nlp/test_autohf_regression.pyindex 2953317ea..1854f7214 100644--- a/test/nlp/test_autohf_regression.py+++ b/test/nlp/test_autohf_regression.py@@ -71,12 +71,12 @@ def test_regression():automl_settings["custom_hpo_args"] = {"model_path": "google/electra-small-discriminator","output_dir": "test/data/output/",- "ckpt_per_epoch": 5,+ "ckpt_per_epoch": 1,"fp16": False,}ray.shutdown()- ray.init()+automl.fit(X_train=X_train, y_train=y_train, X_val=X_val, y_val=y_val, **automl_settings)diff --git a/test/nlp/test_autohf_summarization.py b/test/nlp/test_autohf_summarization.pyindex 0a59474d0..690a85a62 100644--- a/test/nlp/test_autohf_summarization.py+++ b/test/nlp/test_autohf_summarization.py@@ -1,5 +1,6 @@import sysimport pytest+import requests@pytest.mark.skipif(sys.platform == "darwin", reason="do not run on mac os")@@ -60,13 +61,20 @@ def test_summarization():automl_settings["custom_hpo_args"] = {"model_path": "patrickvonplaten/t5-tiny-random","output_dir": "test/data/output/",- "ckpt_per_epoch": 5,+ "ckpt_per_epoch": 1,"fp16": False,}- automl.fit(- X_train=X_train, y_train=y_train, X_val=X_val, y_val=y_val, **automl_settings- )+ 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:+ returnautoml = AutoML()automl.retrain_from_log(X_train=X_train,diff --git a/test/nlp/test_autohf_tokenclassification.py b/test/nlp/test_autohf_tokenclassification.pyindex 154b95a3c..41d1bb6b1 100644--- a/test/nlp/test_autohf_tokenclassification.py+++ b/test/nlp/test_autohf_tokenclassification.py@@ -1,5 +1,6 @@import sysimport pytest+import requests@pytest.mark.skipif(sys.platform == "darwin", reason="do not run on mac os")@@ -728,13 +729,20 @@ def test_tokenclassification():automl_settings["custom_hpo_args"] = {"model_path": "bert-base-uncased","output_dir": "test/data/output/",- "ckpt_per_epoch": 5,+ "ckpt_per_epoch": 1,"fp16": False,}- automl.fit(- X_train=X_train, y_train=y_train, X_val=X_val, y_val=y_val, **automl_settings- )+ 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:+ returnif __name__ == "__main__":diff --git a/test/tune/test_tune.py b/test/tune/test_tune.pyindex ab7232a08..d923a8cc1 100644--- a/test/tune/test_tune.py+++ b/test/tune/test_tune.py@@ -64,7 +64,7 @@ def _test_xgboost(method="BlendSearch"):max_iter = 10for num_samples in [128]:time_budget_s = 60- for n_cpu in [4]:+ for n_cpu in [2]:start_time = time.time()ray.shutdown()ray.init(num_cpus=n_cpu, num_gpus=0)