forked from microsoft/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add PySparkOvertimeMonitor to avoid exceeding time budget (microsoft#923
) * merging * clean commit * Delete mylearner.py This file is not needed. * fix py4j import error * more tolerant cancelling time * fix problems following suggestions * Update flaml/tune/spark/utils.py Co-authored-by: Li Jiang <[email protected]> * remove redundant model * Update test/spark/custom_mylearner.py Co-authored-by: Chi Wang <[email protected]> * add docstr * reverse change in gitignore * Update test/spark/custom_mylearner.py Co-authored-by: Chi Wang <[email protected]> --------- Co-authored-by: Li Jiang <[email protected]> Co-authored-by: Chi Wang <[email protected]>
- Loading branch information
1 parent
4118c8e
commit c6a2440
Showing
6 changed files
with
246 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Project | ||
# Project | ||
/.vs | ||
.vscode | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import os | ||
import time | ||
|
||
import numpy as np | ||
import pyspark | ||
import pytest | ||
from sklearn.datasets import load_iris | ||
|
||
from flaml import AutoML | ||
from flaml.tune.spark.utils import check_spark | ||
|
||
try: | ||
from test.spark.custom_mylearner import * | ||
except ImportError: | ||
from custom_mylearner import * | ||
|
||
from flaml.tune.spark.mylearner import lazy_metric | ||
|
||
os.environ["FLAML_MAX_CONCURRENT"] = "10" | ||
|
||
spark = pyspark.sql.SparkSession.builder.appName("App4OvertimeTest").getOrCreate() | ||
spark_available, _ = check_spark() | ||
skip_spark = not spark_available | ||
|
||
pytestmark = pytest.mark.skipif( | ||
skip_spark, reason="Spark is not installed. Skip all spark tests." | ||
) | ||
|
||
|
||
def test_overtime(): | ||
time_budget = 15 | ||
df, y = load_iris(return_X_y=True, as_frame=True) | ||
df["label"] = y | ||
automl_experiment = AutoML() | ||
automl_settings = { | ||
"dataframe": df, | ||
"label": "label", | ||
"time_budget": time_budget, | ||
"eval_method": "cv", | ||
"metric": lazy_metric, | ||
"task": "classification", | ||
"log_file_name": "test/iris_custom.log", | ||
"log_training_metric": True, | ||
"log_type": "all", | ||
"n_jobs": 1, | ||
"model_history": True, | ||
"sample_weight": np.ones(len(y)), | ||
"pred_time_limit": 1e-5, | ||
"estimator_list": ["lgbm"], | ||
"n_concurrent_trials": 2, | ||
"use_spark": True, | ||
"force_cancel": True, | ||
} | ||
start_time = time.time() | ||
automl_experiment.fit(**automl_settings) | ||
elapsed_time = time.time() - start_time | ||
print( | ||
"time budget: {:.2f}s, actual elapsed time: {:.2f}s".format( | ||
time_budget, elapsed_time | ||
) | ||
) | ||
assert abs(elapsed_time - time_budget) < 2 | ||
print(automl_experiment.predict(df)) | ||
print(automl_experiment.model) | ||
print(automl_experiment.best_iteration) | ||
print(automl_experiment.best_estimator) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_overtime() |