Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SELA #1514

Merged
merged 196 commits into from
Oct 31, 2024
Merged

SELA #1514

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
95d7160
add expo
cyzus Aug 30, 2024
fab1293
ignore expo/results
cyzus Aug 30, 2024
211f758
add openml to requirement
cyzus Aug 30, 2024
d14f07f
1. change data.yaml to more generalized path
cyzus Aug 30, 2024
32759f0
add experimenter
cyzus Aug 30, 2024
ae6a195
fix bug - make rollout more consistent
cyzus Aug 30, 2024
16d1bf0
Rename insight generate to instruction generator
cyzus Sep 2, 2024
27bbc92
1. Rewrite logger message
cyzus Sep 2, 2024
0b30866
fix prompt's json format
cyzus Sep 2, 2024
0e5db1c
1. add ml module
cyzus Sep 2, 2024
f28908e
1. role.py - 如果已经有plan,便不再重复生成
cyzus Sep 2, 2024
f2603a9
remove deprecated comments
cyzus Sep 2, 2024
ab8be7a
update readme
cyzus Sep 2, 2024
a1668a1
add custom experimenter
cyzus Sep 2, 2024
6aafe68
1. 暂时在expo文件夹里单独放一个requirements.txt
cyzus Sep 2, 2024
3ec6dcd
update readme
cyzus Sep 3, 2024
1a833dc
Merge branch 'experimenter' into 'expo'
garylin2099 Sep 3, 2024
df877c9
update readme
cyzus Sep 3, 2024
6972afb
update prompt (specify whether each set has target label)
cyzus Sep 3, 2024
f23d2a7
add autogluon
cyzus Sep 4, 2024
72bd166
ensure experimenter not evaluating csv from other experiments
cyzus Sep 4, 2024
aea524b
1. update readme
cyzus Sep 4, 2024
fcd1ba6
增加try catch
cyzus Sep 4, 2024
ab8a1d6
format code
cyzus Sep 4, 2024
697deb9
Merge branch 'experimenter' into 'expo'
garylin2099 Sep 4, 2024
2c43944
fix import
cyzus Sep 4, 2024
58d7b14
fix import
cyzus Sep 4, 2024
d9bce92
Merge branch 'experimenter' into 'expo'
garylin2099 Sep 4, 2024
c16286a
Refactor MCTS class to handle role running errors and improve error l…
cyzus Sep 5, 2024
45d176b
remove deprecated scripts
cyzus Sep 5, 2024
d27a48a
update prompt to include dataset info path
cyzus Sep 5, 2024
96ffcd2
更新Prompt相关readme
cyzus Sep 5, 2024
3583e2a
Merge branch 'experimenter' into 'expo'
garylin2099 Sep 5, 2024
defca81
fix time calculation
cyzus Sep 6, 2024
0e27e3d
使用code block做reflection
cyzus Sep 6, 2024
e07ed0d
fix mcts bug
cyzus Sep 6, 2024
a6f71f4
1. avoid circular reference
cyzus Sep 6, 2024
6d40ec4
update result key
cyzus Sep 6, 2024
376d1b7
allow new instruction even if there's no insights
cyzus Sep 6, 2024
c0262bc
1. add support to hf dataset
cyzus Sep 6, 2024
df6fe98
fix dataset bug
cyzus Sep 6, 2024
9728b3a
add greedy to run_experiment; add save_notebook to experimenter.py
cyzus Sep 9, 2024
72dd44a
add ds agent's datasets
cyzus Sep 9, 2024
93ff1f8
update datasets.yaml
cyzus Sep 9, 2024
401ca97
update dataset.py
cyzus Sep 9, 2024
e3fccce
Merge branch 'experimenter' into 'expo'
garylin2099 Sep 9, 2024
9ba0d21
update mcts logic
cyzus Sep 9, 2024
294d0fe
fix nbclient
cyzus Sep 9, 2024
af41f1f
Update README.md add aide setup and run
limafang Sep 9, 2024
60e8e3e
fix hfdataset; make dirs when save notebook
cyzus Sep 10, 2024
d34a482
give dev label
cyzus Sep 10, 2024
e3663f2
implement autuglu exp
rayhao6 Sep 10, 2024
b776c73
add random tree search
cyzus Sep 10, 2024
a373e68
update di instruction
cyzus Sep 10, 2024
923109e
add aide.py update README
limafang Sep 10, 2024
a8ee208
autogluon small fix
rayhao6 Sep 11, 2024
35b9ea0
update di instruction
cyzus Sep 11, 2024
c91b2ad
remove unnecessary prompt instruction
cyzus Sep 11, 2024
322617d
Merge branch 'autogluon' into 'expo'
garylin2099 Sep 11, 2024
edb7be2
Merge branch 'aide' into 'expo'
garylin2099 Sep 11, 2024
4dfa012
Merge remote-tracking branch 'origin/expo' into improve_mcts
cyzus Sep 11, 2024
eaf1b62
add timeout to client
cyzus Sep 11, 2024
6353909
Merge branch 'improve_mcts' into 'expo'
garylin2099 Sep 11, 2024
318db07
add: ds-agent setup
Sep 11, 2024
9ba9371
add autosklearn setup run
limafang Sep 12, 2024
562af8c
update text dataset
cyzus Sep 13, 2024
9f04278
comment
cyzus Sep 13, 2024
c54e412
update di prompt
cyzus Sep 13, 2024
a6b066a
support image dataset
limafang Sep 13, 2024
cfa21ba
change img path from abs to rel
cyzus Sep 13, 2024
7d8cb9a
add image datasets config
cyzus Sep 13, 2024
09b1a2e
Merge branch 'text-dataset' into improve_mcts
cyzus Sep 13, 2024
7458e43
Merge branch 'text-dataset' into 'expo'
garylin2099 Sep 13, 2024
b49334b
fix import and update readme
limafang Sep 13, 2024
5d2de4d
add random seed
limafang Sep 14, 2024
b32b28e
修复预测结果没有target列名。
orange-crow Sep 14, 2024
63bb972
Merge branch 'fix_evaluate_prediction' into 'expo'
garylin2099 Sep 14, 2024
9c3adbe
Merge remote-tracking branch 'origin/expo' into improve_mcts
cyzus Sep 14, 2024
c4fe056
fix import error delete seed
limafang Sep 14, 2024
8beca0f
1. add special instruction
cyzus Sep 14, 2024
9089ecf
update readme
cyzus Sep 14, 2024
ed6ce14
update fixed insights
cyzus Sep 14, 2024
8a5b6d6
update recommendation prompt
cyzus Sep 14, 2024
743c67a
change task type prompt to prevent unwanted label transformation
cyzus Sep 14, 2024
5e7cac7
fix fixed_insights bug
cyzus Sep 14, 2024
f856d76
remove recommendation from di initial prompt, add recommendation to t…
cyzus Sep 14, 2024
c64153f
Merge branch 'ds-agent' into 'expo'
garylin2099 Sep 14, 2024
9d2c81a
fix evaluation bug
cyzus Sep 14, 2024
9ff9d27
include load tree
cyzus Sep 14, 2024
24db19f
fix start task id consistency
cyzus Sep 14, 2024
1cdffc3
FE prompt: FE通常不会make changes而是加新的特征
cyzus Sep 14, 2024
8c6dd48
remove pdb
cyzus Sep 14, 2024
3c50575
make dir at start
cyzus Sep 14, 2024
3cba031
Merge branch 'improve_mcts' into 'expo'
garylin2099 Sep 14, 2024
ce73f4c
lazy import autogluon
cyzus Sep 14, 2024
1c29c0a
Merge branch 'improve_mcts' into 'expo'
garylin2099 Sep 14, 2024
e1cd6b4
Merge remote-tracking branch 'origin/expo' into improve_mcts
cyzus Sep 14, 2024
9665ebd
autosklearn delete per_run_time_limit and change time_limit
limafang Sep 14, 2024
c007d0b
change import way
limafang Sep 14, 2024
574f1b0
change import way
limafang Sep 14, 2024
0bf2d60
rm lgb
garylin2099 Sep 15, 2024
f7733ad
Merge branch 'yzlin-expo-patch-57610' into 'expo'
garylin2099 Sep 15, 2024
d95c1cb
fix import error
limafang Sep 16, 2024
32fc96c
Merge remote-tracking branch 'origin/expo' into improve_mcts
cyzus Sep 18, 2024
2d62317
Merge branch 'autosklearn' into 'expo'
garylin2099 Sep 20, 2024
8dbcd46
copy notebook to result after mcts
cyzus Sep 20, 2024
2f78d57
fix random search
cyzus Sep 23, 2024
0a9ab5c
Merge branch 'ss-improve' into 'expo'
garylin2099 Sep 23, 2024
6344046
update aug result summarization
cyzus Sep 24, 2024
31adaee
add special instruction for img/text dataset
cyzus Sep 24, 2024
68c672d
use transformers lib instead of torchvision
cyzus Sep 25, 2024
e2cee39
add autogluon multimodal support
rayhao6 Sep 26, 2024
1a1855f
add input param for autogluon
rayhao6 Sep 26, 2024
3c39738
add tuning data for tabular mode
rayhao6 Sep 26, 2024
2b67355
add step score
cyzus Sep 26, 2024
e2c8224
import issue
rayhao6 Sep 27, 2024
98ef44a
Merge branch 'ray_multilmodal_0925' into 'expo'
garylin2099 Sep 27, 2024
24536df
update_save_order
cyzus Sep 27, 2024
1654174
Merge branch 'expo' into improve-multimodal
cyzus Sep 27, 2024
af84469
change label column
cyzus Sep 27, 2024
bd26e90
update target label
cyzus Sep 28, 2024
06702db
update pet
cyzus Sep 28, 2024
db247d9
save result order
cyzus Sep 28, 2024
1589a04
clarify prediction saving prompt
cyzus Sep 28, 2024
788e42e
update model list
cyzus Sep 30, 2024
573e9b6
Merge branch 'improve-multimodal' into 'expo'
garylin2099 Oct 10, 2024
f80ebc4
1. add role level timeout 限制是1000s
cyzus Oct 10, 2024
2fc8f20
can change timeout through data.yaml
cyzus Oct 10, 2024
eb460d3
make timeout as argument
cyzus Oct 10, 2024
9f4eba7
add scripts
cyzus Oct 10, 2024
e1c2683
删除图片
cyzus Oct 11, 2024
cdfb413
去掉role装饰器
cyzus Oct 11, 2024
9c54113
make sure image task starting from datapreprocessing
cyzus Oct 11, 2024
ae12d73
remove dependency
cyzus Oct 11, 2024
56e7a08
insight pool is now able to dynamically increase
cyzus Oct 11, 2024
f7374c0
rename analysis pool to insight pool
cyzus Oct 11, 2024
eda9322
1. dynamically add insight
cyzus Oct 11, 2024
3a57060
1. add eval_func for sela and compatibility to others
cyzus Oct 12, 2024
a91003a
disable submission
cyzus Oct 14, 2024
1d4a845
支持跑通mle bench
cyzus Oct 14, 2024
7cb307a
Merge branch 'prepare-for-opensource' into 'expo'
garylin2099 Oct 15, 2024
07800be
allow datasets to be prepared by users
cyzus Oct 15, 2024
d179982
allow special-instruction for mle-bench
cyzus Oct 15, 2024
0166834
fix special instruction bug
cyzus Oct 15, 2024
02b4f0a
add timout to mlebench readme instruction
cyzus Oct 15, 2024
541f8a1
fix path bug
cyzus Oct 15, 2024
7794b99
fix: role timeout not passing in
cyzus Oct 16, 2024
989a3b4
allow max depth passing in
cyzus Oct 16, 2024
df7a04d
output dev set score
cyzus Oct 16, 2024
38daf24
rename task if custom_data_dir is used
cyzus Oct 17, 2024
a46f575
clean up input argument
cyzus Oct 17, 2024
0f01c07
add tree visualization script and function
cyzus Oct 17, 2024
1d22466
change dir for tree fig
cyzus Oct 17, 2024
6646983
fix visualization bug
cyzus Oct 17, 2024
510136a
allowing whether to show instructions
cyzus Oct 17, 2024
06710fb
fix typo in readme.md
cyzus Oct 17, 2024
852fbc5
automatically update args.low_is_better for mle-bench
cyzus Oct 17, 2024
6f437bb
automatically change low_is_better for rmse
cyzus Oct 17, 2024
de42e32
automatically update low_is_better for our task
cyzus Oct 17, 2024
1915d19
update aide readme
limafang Oct 17, 2024
2762c12
Merge branch 'fix-aide-readme' into 'expo'
garylin2099 Oct 17, 2024
358a97e
modify prompt
cyzus Oct 18, 2024
7a38165
add seed
cyzus Oct 18, 2024
3646feb
Merge remote-tracking branch 'origin/expo' into insight-pool-improve
cyzus Oct 18, 2024
f97ad72
add task arg for tree visualization
cyzus Oct 18, 2024
2ce186c
Merge branch 'insight-pool-improve' into 'expo'
garylin2099 Oct 18, 2024
345d799
Merge remote-tracking branch 'origin/expo' into optimize-mle-bench-pr…
cyzus Oct 18, 2024
5eaa072
add an instruction to avoid splitting instruction being replaced
cyzus Oct 18, 2024
f070455
Merge branch 'expo' into 'sela'
garylin2099 Oct 18, 2024
d304fc3
Merge branch 'optimize-mle-bench-prompt' into 'sela'
garylin2099 Oct 21, 2024
3a8fdc6
add visit order
garylin2099 Oct 21, 2024
4bed19b
Merge pull request #1526 from garylin2099/sela-lyz
garylin2099 Oct 21, 2024
7c5b29d
rename expo folder to sela
cyzus Oct 22, 2024
eb3d49d
move to ext/sela
cyzus Oct 25, 2024
a62ae88
update readme.md
cyzus Oct 25, 2024
7602978
rename aug to rs
cyzus Oct 25, 2024
4d1a6f4
rename classes and functions
cyzus Oct 25, 2024
61492d9
add data type; fix instruction generation
cyzus Oct 28, 2024
9abb8db
edit-baseline-experimenter
cyzus Oct 28, 2024
e41f934
update readme
cyzus Oct 28, 2024
4c541c2
reorder import
cyzus Oct 28, 2024
6321b79
reoreder
cyzus Oct 28, 2024
cf03c5d
Merge pull request #1543 from cyzus/sela
garylin2099 Oct 28, 2024
1aac79c
identation on readme
cyzus Oct 28, 2024
e0cbbf8
rename research assistant to experimenter
cyzus Oct 28, 2024
25299e1
change research assistant to experimenter
cyzus Oct 29, 2024
37698b3
update readme - put baseline readme in /runner
cyzus Oct 29, 2024
df51f45
Merge pull request #1545 from cyzus/sela-readme
garylin2099 Oct 29, 2024
74041bd
update readme intro
cyzus Oct 30, 2024
73d2358
update intro and citation
cyzus Oct 30, 2024
0a215a9
update readme
cyzus Oct 30, 2024
261a39d
remove autogluon models in gitignore
cyzus Oct 30, 2024
776ee44
remove mlebench
cyzus Oct 30, 2024
b710365
use google drive link
cyzus Oct 30, 2024
39027b6
Merge pull request #1556 from cyzus/sela-readme-intro
garylin2099 Oct 30, 2024
db19c88
Merge branch 'main' into sela
garylin2099 Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,4 @@ cov.xml
*.dot
.python-version
*.csv
metagpt/ext/sela/results/*
9 changes: 4 additions & 5 deletions metagpt/actions/di/write_analysis_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"""
from __future__ import annotations

import json

from metagpt.actions import Action
from metagpt.prompts.di.write_analysis_code import (
CHECK_DATA_PROMPT,
Expand All @@ -30,9 +28,10 @@ async def _debug_with_reflection(self, context: list[Message], working_memory: l
)

rsp = await self._aask(reflection_prompt, system_msgs=[REFLECTION_SYSTEM_MSG])
reflection = json.loads(CodeParser.parse_code(block=None, text=rsp))

return reflection["improved_impl"]
# reflection = json.loads(CodeParser.parse_code(block=None, text=rsp))
# return reflection["improved_impl"]
reflection = CodeParser.parse_code(block=None, text=rsp)
return reflection

async def run(
self,
Expand Down
106 changes: 106 additions & 0 deletions metagpt/ext/sela/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# SELA: Tree-Search Enhanced LLM Agents for Automated Machine Learning

garylin2099 marked this conversation as resolved.
Show resolved Hide resolved

Official implementation for paper [SELA: Tree-Search Enhanced LLM Agents for Automated Machine Learning](https://arxiv.org/abs/2410.17238).


SELA is an innovative system that enhances Automated Machine Learning (AutoML) by integrating Monte Carlo Tree Search (MCTS) with LLM-based agents. Traditional AutoML methods often generate low-diversity and suboptimal code, limiting their effectiveness in model selection and ensembling. SELA addresses these challenges by representing pipeline configurations as trees, enabling agents to intelligently explore the solution space and iteratively refine their strategies based on experimental feedback.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solution space -> search space?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solution space in paper abstract, i think it's okay if we are talking at a high level that the agent is searching for a solution or pipeline


## 1. Data Preparation

You can either download the datasets from the link or prepare the datasets from scratch.
- **Download Datasets:** [Dataset Link](https://drive.google.com/drive/folders/151FIZoLygkRfeJgSI9fNMiLsixh1mK0r?usp=sharing)
- **Download and prepare datasets from scratch:**
```bash
cd data
python dataset.py --save_analysis_pool
python hf_data.py --save_analysis_pool
```

## 2. Configurations

### Data Config

- **`datasets.yaml`:** Provide base prompts, metrics, and target columns for respective datasets.
- **`data.yaml`:** Modify `datasets_dir` to the base directory of all prepared datasets.

### LLM Config

```yaml
llm:
api_type: 'openai'
model: deepseek-coder
base_url: "https://your_base_url"
api_key: sk-xxx
temperature: 0.5
```


## 3. SELA

### Run SELA

#### Setup

```bash
pip install -e .

cd metagpt/ext/sela

pip install -r requirements.txt
```

#### Running Experiments

- **Examples:**
```bash
python run_experiment.py --exp_mode mcts --task titanic --rollouts 10
python run_experiment.py --exp_mode mcts --task house-prices --rollouts 10 --low_is_better
```

#### Parameters

- **`--rollouts`:** The number of rollouts.
- **`--use_fixed_insights`:** Include fixed insights saved in `expo/insights/fixed_insights.json`.
- **`--low_is_better`:** Use this if the dataset has a regression metric.
- **`--from_scratch`:** Generate a new insight pool based on the dataset before running MCTS.
- **`--role_timeout`:** Limits the duration of a single simulation (e.g., `10 rollouts with timeout 1,000` = max 10,000s).
- **`--max_depth`:** Set the maximum depth of MCTS (default is 4).
- **`--load_tree`:** Load an existing MCTS tree if the previous experiment was interrupted.
- Example:
```bash
python run_experiment.py --exp_mode mcts --task titanic --rollouts 10
```
- To resume:
```bash
python run_experiment.py --exp_mode mcts --task titanic --rollouts 7 --load_tree
```

### Ablation Study

**RandomSearch**

- **Use a single insight:**
```bash
python run_experiment.py --exp_mode rs --task titanic --rs_mode single
```

- **Use a set of insights:**
```bash
python run_experiment.py --exp_mode rs --task titanic --rs_mode set
```

## 4. Citation
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also added to the outermost README of MetaGPT

Please cite our paper if you use SELA or find it cool or useful!

```bibtex
@misc{chi2024selatreesearchenhancedllm,
title={SELA: Tree-Search Enhanced LLM Agents for Automated Machine Learning},
author={Yizhou Chi and Yizhang Lin and Sirui Hong and Duyi Pan and Yaying Fei and Guanghao Mei and Bangbang Liu and Tianqi Pang and Jacky Kwok and Ceyao Zhang and Bang Liu and Chenglin Wu},
year={2024},
eprint={2410.17238},
archivePrefix={arXiv},
primaryClass={cs.AI},
url={https://arxiv.org/abs/2410.17238},
}
```
3 changes: 3 additions & 0 deletions metagpt/ext/sela/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
datasets_dir: "path/to/datasets" # path to the datasets directory
work_dir: ../../../workspace # path to the workspace directory
role_dir: storage/SELA # path to the role directory
74 changes: 74 additions & 0 deletions metagpt/ext/sela/data/custom_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import os

from metagpt.ext.sela.data.dataset import SPECIAL_INSTRUCTIONS
from metagpt.ext.sela.runner.mle_bench.instructions import (
ADDITIONAL_NOTES,
INSTRUCTIONS,
INSTRUCTIONS_OBFUSCATED,
)

MLE_BENCH_FILES = ["description.md", "description_obfuscated.md"]


MLE_REQUIREMENTS = """
{instructions}

{additonal_notes}

COMPETITION INSTRUCTIONS
------

{task_description}

## More Instructions
- You should split the training data into train and dev set with a seed of 42.
- You should use the dev set to improve your model. Print the final dev set score after training.
- output_dir: {output_dir}
- Besides `submission.csv`, you should also save your `test_predictions.csv` and `dev_predictions.csv` in the output directory.
- Note that `test_predictions.csv` should be identical to `submission.csv`.
- Perform data analysis, data preprocessing, feature engineering, and modeling to predict the target. {special_instruction}
**Do not make any plots or visualizations.**
"""


def get_mle_task_id(dataset_dir):
return dataset_dir.split("/")[-3]


def get_mle_is_lower_better(task):
from mlebench.data import get_leaderboard
from mlebench.registry import registry

competition = registry.get_competition(task)
competition_leaderboard = get_leaderboard(competition)
return competition.grader.is_lower_better(competition_leaderboard)


def get_mle_bench_requirements(dataset_dir, data_config, special_instruction, obfuscated=False):
work_dir = data_config["work_dir"]
task = get_mle_task_id(dataset_dir)
output_dir = f"{work_dir}/{task}"
final_output_dir = f"{work_dir}/submission"
os.makedirs(output_dir, exist_ok=True)
if special_instruction:
special_instruction = SPECIAL_INSTRUCTIONS[special_instruction]
else:
special_instruction = ""
if obfuscated:
instructions = INSTRUCTIONS_OBFUSCATED.format(dataset_dir=dataset_dir, output_dir=final_output_dir)
task_file = "description_obfuscated.md"
else:
instructions = INSTRUCTIONS.format(dataset_dir=dataset_dir, output_dir=output_dir)
task_file = "description.md"

with open(os.path.join(dataset_dir, task_file), encoding="utf-8") as f:
task_description = f.read()
mle_requirement = MLE_REQUIREMENTS.format(
instructions=instructions,
additonal_notes=ADDITIONAL_NOTES,
task_description=task_description,
output_dir=output_dir,
special_instruction=special_instruction,
)
print(mle_requirement)
return mle_requirement
Loading
Loading