Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into continual-learning
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyun-wu committed Jul 10, 2023
2 parents 2e97c5f + 45c37b5 commit 2993265
Show file tree
Hide file tree
Showing 15 changed files with 2,362 additions and 258 deletions.
5 changes: 3 additions & 2 deletions flaml/autogen/agent/assistant_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ class AssistantAgent(Agent):
"""(Experimental) Assistant agent, able to suggest code blocks."""

DEFAULT_SYSTEM_MESSAGE = """You are a helpful AI assistant.
In the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute. You must indicate the script type in the code block.
In the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute. You must indicate the script type in the code block. The user cannot provide any other feedback or perform any other action beyond executing the code you suggest.
1. When you need to ask the user for some info, use the code to output the info you need, for example, browse or search the web, download/read a file.
2. When you need to perform some task with code, use the code to perform the task and output the result. Finish the task smartly. Solve the task step by step if you need to.
If you want the user to save the code in a file before executing it, put # filename: <filename> inside the code block as the first line. Don't include multiple code blocks in one response. Do not ask users to copy and paste the result. Instead, use 'print' function for the output when relevant. Check the execution result returned by the user.
If the result indicates there is an error, fix the error and output the code again. Suggeset the full code instead of partial code or code changes.
If the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes.
Verify your answer carefully. If a function for planning is provided, call the function to make plans and verify the execution.
Reply "TERMINATE" in the end when everything is done.
"""

Expand Down
4 changes: 2 additions & 2 deletions flaml/autogen/oai/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def yes_or_no_filter(context, config, response):
raise_error (bool, Optional): Whether to raise error when all configs fail.
When set to False, -1 will be returned when all configs fail.
**config: Configuration for the completion.
**config: Configuration for the openai API call. This is used as parameters for calling openai API.
Besides the parameters for the openai API call, it can also contain a seed (int) for the cache.
This is useful when implementing "controlled randomness" for the completion.
Also, the "prompt" or "messages" parameter can contain a template (str or Callable) which will be instantiated with the context.
Expand Down Expand Up @@ -769,7 +769,7 @@ def yes_or_no_filter(context, config, response):
response["pass_filter"] = pass_filter
return response
cost += response["cost"]
except (AuthenticationError, RateLimitError, Timeout):
except (AuthenticationError, RateLimitError, Timeout, InvalidRequestError):
logger.debug(f"failed with config {i}", exc_info=1)
if i == last:
raise
Expand Down
14 changes: 9 additions & 5 deletions flaml/automl/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ def _preprocess(
X_train: Union[psDataFrame, sparkDataFrame],
y_train: psSeries = None,
index_col: str = "tmp_index_col",
return_label: bool = False,
):
# TODO: optimize this, support pyspark.sql.DataFrame
if y_train is not None:
Expand All @@ -416,7 +417,10 @@ def _preprocess(
self.df_train = X_train
if isinstance(self.df_train, psDataFrame):
self.df_train = self.df_train.to_spark(index_col=index_col)
return self.df_train
if return_label:
return self.df_train, y_train.name
else:
return self.df_train

def fit(
self,
Expand All @@ -437,7 +441,8 @@ def fit(
Returns:
train_time: A float of the training time in seconds.
"""
df_train = self._preprocess(X_train, y_train, index_col=index_col)
df_train, label_col = self._preprocess(X_train, y_train, index_col=index_col, return_label=True)
kwargs["labelCol"] = label_col
train_time = self._fit(df_train, **kwargs)
return train_time

Expand Down Expand Up @@ -506,8 +511,6 @@ class j.
class SparkLGBMEstimator(SparkEstimator):
"""The class for fine-tuning spark version lightgbm models, using SynapseML API."""

"""The class for tuning LGBM, using sklearn API."""

ITER_HP = "numIterations"
DEFAULT_ITER = 100

Expand Down Expand Up @@ -614,7 +617,7 @@ def fit(
start_time = time.time()
if self.model_n_classes_ is None and self._task not in ["regression", "rank"]:
self.model_n_classes_, self.model_classes_ = len_labels(y_train, return_labels=True)
df_train = self._preprocess(X_train, y_train, index_col=index_col)
df_train, label_col = self._preprocess(X_train, y_train, index_col=index_col, return_label=True)
# n_iter = self.params.get(self.ITER_HP, self.DEFAULT_ITER)
# trained = False
# mem0 = psutil.virtual_memory().available if psutil is not None else 1
Expand Down Expand Up @@ -673,6 +676,7 @@ def fit(
# return time.time() - start_time
# # when not trained, train at least one iter
# self.params[self.ITER_HP] = max(max_iter, 1)
_kwargs["labelCol"] = label_col
self._fit(df_train, **_kwargs)
train_time = time.time() - start_time
return train_time
Expand Down
2 changes: 1 addition & 1 deletion flaml/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.0rc2"
__version__ = "2.0.0rc3"
Loading

0 comments on commit 2993265

Please sign in to comment.