You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`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.
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.
***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.
21
30
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.
22
36
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`.
23
48
24
49
---
25
50
51
+
26
52
## Setup
27
53
28
-
1.**Install the Package:**
54
+
1.**Install the Package:**
55
+
56
+
```bash
57
+
pip install weco
58
+
```
29
59
30
-
```bash
31
-
pip install weco
32
-
```
60
+
2. **Configure API Keys:**
33
61
34
-
2.**Configure API Keys:**
62
+
Set the appropriate environment variables for your desired language model provider:
35
63
36
-
Set the appropriate environment variables for your language model provider:
- **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.)
|`--source`| Path to the source code file that will be optimized (e.g., `optimize.py`). | Yes |
77
+
|`--eval-command`| Command to run forevaluating the codein`--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 |
--additional-instructions "Fuse operations in the forward method while ensuring the max float deviation remains small. Maintain the same format of the code."
71
97
```
72
98
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.
-**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').
<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
+
95
143
## Contributing
96
144
97
145
We welcome contributions! To get started:
98
146
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
+
```
104
152
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
+
```
109
157
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
+
```
114
162
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.
116
164
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.
0 commit comments