Skip to content

Commit 2a1ad2a

Browse files
Update README.md: expand use cases and clarify code modification
1 parent eb17474 commit 2a1ad2a

File tree

1 file changed

+95
-47
lines changed

1 file changed

+95
-47
lines changed

README.md

Lines changed: 95 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,90 @@
22

33
[![Python](https://img.shields.io/badge/Python-3.12.0-blue)](https://www.python.org)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
5+
[![PyPI version](https://badge.fury.io/py/weco.svg)](https://badge.fury.io/py/weco)
56

6-
`weco` is a command-line interface for interacting with Weco AI's code optimizer, powerred by [AI-Driven Exploration](https://arxiv.org/abs/2502.13138).
7+
`weco` is a command-line interface for interacting with Weco AI's code optimizer, powered by [AI-Driven Exploration](https://arxiv.org/abs/2502.13138). It helps you automate the improvement of your code for tasks like GPU kernel optimization, feature engineering, model development, and prompt engineering.
78

9+
https://github.com/user-attachments/assets/cb724ef1-bff6-4757-b457-d3b2201ede81
810

11+
---
912

10-
https://github.com/user-attachments/assets/cb724ef1-bff6-4757-b457-d3b2201ede81
13+
## Overview
1114

15+
The `weco` CLI leverages a tree search approach guided by Large Language Models (LLMs) to iteratively explore and refine your code. It automatically applies changes, runs your evaluation script, parses the results, and proposes further improvements based on the specified goal.
1216

17+
![image](https://github.com/user-attachments/assets/a6ed63fa-9c40-498e-aa98-a873e5786509)
1318

1419
---
1520

16-
## Overview
21+
## Example Use Cases
1722

18-
The weco CLI leverages a tree search approach with LLMs to iteratively improve your code.
23+
Here's how `weco` can be applied to common ML engineering tasks:
1924

20-
![image](https://github.com/user-attachments/assets/a6ed63fa-9c40-498e-aa98-a873e5786509)
25+
* **GPU Kernel Optimization:**
26+
* **Goal:** Improve the speed or efficiency of low-level GPU code.
27+
* **How:** `weco` iteratively refines CUDA, Triton, Metal, or other kernel code specified in your `--source` file.
28+
* **`--eval-command`:** Typically runs a script that compiles the kernel, executes it, and benchmarks performance (e.g., latency, throughput).
29+
* **`--metric`:** Examples include `latency`, `throughput`, `TFLOPS`, `memory_bandwidth`. Optimize to `minimize` latency or `maximize` throughput.
2130

31+
* **Feature Engineering:**
32+
* **Goal:** Discover better data transformations or feature combinations for your machine learning models.
33+
* **How:** `weco` explores different processing steps or parameters within your feature transformation code (`--source`).
34+
* **`--eval-command`:** Executes a script that applies the features, trains/validates a model using those features, and prints a performance score.
35+
* **`--metric`:** Examples include `accuracy`, `AUC`, `F1-score`, `validation_loss`. Usually optimized to `maximize` accuracy/AUC/F1 or `minimize` loss.
2236

37+
* **Model Development:**
38+
* **Goal:** Tune hyperparameters or experiment with small architectural changes directly within your model's code.
39+
* **How:** `weco` modifies hyperparameter values (like learning rate, layer sizes if defined in the code) or structural elements in your model definition (`--source`).
40+
* **`--eval-command`:** Runs your model training and evaluation script, printing the key performance indicator.
41+
* **`--metric`:** Examples include `validation_accuracy`, `test_loss`, `inference_time`, `perplexity`. Optimize according to the metric's nature (e.g., `maximize` accuracy, `minimize` loss).
42+
43+
* **Prompt Engineering:**
44+
* **Goal:** Refine prompts used within larger systems (e.g., for LLM interactions) to achieve better or more consistent outputs.
45+
* **How:** `weco` modifies prompt templates, examples, or instructions stored in the `--source` file.
46+
* **`--eval-command`:** Executes a script that uses the prompt, generates an output, evaluates that output against desired criteria (e.g., using another LLM, checking for keywords, format validation), and prints a score.
47+
* **`--metric`:** Examples include `quality_score`, `relevance`, `task_success_rate`, `format_adherence`. Usually optimized to `maximize`.
2348

2449
---
2550

51+
2652
## Setup
2753

28-
1. **Install the Package:**
54+
1. **Install the Package:**
55+
56+
```bash
57+
pip install weco
58+
```
2959

30-
```bash
31-
pip install weco
32-
```
60+
2. **Configure API Keys:**
3361

34-
2. **Configure API Keys:**
62+
Set the appropriate environment variables for your desired language model provider:
3563

36-
Set the appropriate environment variables for your language model provider:
37-
38-
- **OpenAI:** `export OPENAI_API_KEY="your_key_here"`
39-
- **Anthropic:** `export ANTHROPIC_API_KEY="your_key_here"`
40-
- **Google DeepMind:** `export GEMINI_API_KEY="your_key_here"`
64+
- **OpenAI:** `export OPENAI_API_KEY="your_key_here"`
65+
- **Anthropic:** `export ANTHROPIC_API_KEY="your_key_here"`
66+
- **Google DeepMind:** `export GEMINI_API_KEY="your_key_here"` (Google AI Studio has a free API usage quota. Create a key [here](https://aistudio.google.com/apikey) to use weco for free.)
4167

4268
---
4369

4470
## Usage
4571

4672
### Command Line Arguments
4773

48-
| Argument | Description | Required |
49-
|-----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|----------|
50-
| `--source` | Path to the Python source code that will be optimized (e.g. optimize.py). | Yes |
51-
| `--eval-command` | Command to run for evaluation (e.g. 'python eval.py --arg1=val1'). | Yes |
52-
| `--metric` | Metric to optimize. | Yes |
53-
| `--maximize` | Whether to maximize ('true') or minimize ('false') the metric. | Yes |
54-
| `--steps` | Number of optimization steps to run. | Yes |
55-
| `--model` | Model to use for optimization. | Yes |
56-
| `--additional-instructions` | (Optional) Description of additional instructions OR path to a file containing additional instructions. | No |
74+
| Argument | Description | Required |
75+
| :-------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- |
76+
| `--source` | Path to the source code file that will be optimized (e.g., `optimize.py`). | Yes |
77+
| `--eval-command` | Command to run for evaluating the code in `--source`. This command should print the target `--metric` and its value to the terminal (stdout/stderr). See note below. | Yes |
78+
| `--metric` | The name of the metric you want to optimize (e.g., 'accuracy', 'speedup', 'loss'). This metric name should match what's printed by your `--eval-command`. | Yes |
79+
| `--maximize` | Whether to maximize (`true`) or minimize (`false`) the metric. | Yes |
80+
| `--steps` | Number of optimization steps (LLM iterations) to run. | Yes |
81+
| `--model` | Model identifier for the LLM to use (e.g., `gpt-4o`, `claude-3.5-sonnet`). Recommended models to try include `o3-mini`, `claude-3-haiku`, and `gemini-1.5-flash`. | Yes |
82+
| `--additional-instructions` | (Optional) Natural language description of specific instructions OR path to a file containing detailed instructions to guide the LLM. | No |
5783
5884
---
85+
### Examples
5986
60-
### Example
87+
**Example 1: Optimizing PyTorch operations**
6188
62-
Optimizing common operations in pytorch:
6389
```bash
6490
weco --source examples/simple-torch/optimize.py \
6591
--eval-command "python examples/simple-torch/evaluate.py --solution-path examples/simple-torch/optimize.py --device mps" \
@@ -70,7 +96,10 @@ weco --source examples/simple-torch/optimize.py \
7096
--additional-instructions "Fuse operations in the forward method while ensuring the max float deviation remains small. Maintain the same format of the code."
7197
```
7298
73-
Sometimes we have a bit more context we'd like to provide. Its not easy to fit all of this in a string like shown above with `additional-instructions`. Thats why you can also provide a path to any file you'd like to me read as in context. In this example, we optimize the same operations using mlx and metal with additional instructions:
99+
**Example 2: Optimizing MLX operations with instructions from a file**
100+
101+
Sometimes, additional context or instructions are too complex for a single command-line string. You can provide a path to a file containing these instructions.
102+
74103
```bash
75104
weco --source examples/simple-mlx/optimize.py \
76105
--eval-command "python examples/simple-mlx/evaluate.py --solution-path examples/simple-mlx/optimize.py" \
@@ -80,40 +109,59 @@ weco --source examples/simple-mlx/optimize.py \
80109
--model o3-mini \
81110
--additional-instructions examples/simple-mlx/metal-examples.rst
82111
```
112+
83113
---
84114
85-
## Supported Providers
86115
87-
The CLI supports the following model providers:
116+
### Important Note on Evaluation
88117
89-
- **OpenAI:** Set your API key using `OPENAI_API_KEY`.
90-
- **Anthropic:** Set your API key using `ANTHROPIC_API_KEY`.
91-
- **Google DeepMind:** Set your API key using `GEMINI_API_KEY`.
118+
The command specified by `--eval-command` is crucial. It's responsible for executing the potentially modified code from `--source` and assessing its performance. **This command MUST print the metric you specified with `--metric` along with its numerical value to the terminal (standard output or standard error).** Weco reads this output to understand how well each code version performs and guide the optimization process.
119+
120+
For example, if you set `--metric speedup`, your evaluation script (`eval.py` in the examples) should output a line like:
121+
122+
```
123+
speedup: 1.5
124+
```
125+
126+
or
127+
128+
```
129+
Final speedup value = 1.5
130+
```
131+
132+
Weco will parse this output to extract the numerical value (1.5 in this case) associated with the metric name ('speedup').
92133

93134
---
94135

136+
137+
138+
<div style="background-color: #fff3cd; border: 1px solid #ffeeba; padding: 15px; border-radius: 4px; margin-bottom: 15px;">
139+
<strong>⚠️ Warning: Code Modification</strong><br>
140+
<code>weco</code> directly modifies the file specified by <code>--source</code> during the optimization process. It is <strong>strongly recommended</strong> to use version control (like Git) to track changes and revert if needed. Alternatively, ensure you have a backup of your original file before running the command. Upon completion, the file will contain the best-performing version of the code found during the run.
141+
</div>
142+
95143
## Contributing
96144

97145
We welcome contributions! To get started:
98146

99-
1. **Fork and Clone the Repository:**
100-
```bash
101-
git clone https://github.com/WecoAI/weco-cli.git
102-
cd weco-cli
103-
```
147+
1. **Fork and Clone the Repository:**
148+
```bash
149+
git clone https://github.com/WecoAI/weco-cli.git
150+
cd weco-cli
151+
```
104152

105-
2. **Install Development Dependencies:**
106-
```bash
107-
pip install -e ".[dev]"
108-
```
153+
2. **Install Development Dependencies:**
154+
```bash
155+
pip install -e ".[dev]"
156+
```
109157

110-
3. **Create a Feature Branch:**
111-
```bash
112-
git checkout -b feature/your-feature-name
113-
```
158+
3. **Create a Feature Branch:**
159+
```bash
160+
git checkout -b feature/your-feature-name
161+
```
114162

115-
4. **Make Your Changes:** Ensure your code adheres to our style guidelines and includes relevant tests.
163+
4. **Make Your Changes:** Ensure your code adheres to our style guidelines and includes relevant tests.
116164

117-
5. **Commit and Push** your changes, then open a pull request with a clear description of your enhancements.
165+
5. **Commit and Push** your changes, then open a pull request with a clear description of your enhancements.
118166

119167
---

0 commit comments

Comments
 (0)