weco 0.2.5__py3-none-any.whl → 0.2.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
weco/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # DO NOT EDIT
2
- __pkg_version__ = "0.2.5"
2
+ __pkg_version__ = "0.2.7"
3
3
  __api_version__ = "v1"
4
4
  __base_url__ = f"https://api.aide.weco.ai/{__api_version__}"
weco/cli.py CHANGED
@@ -50,6 +50,7 @@ def main() -> None:
50
50
  )
51
51
  parser.add_argument("--steps", type=int, required=True, help="Number of steps to run")
52
52
  parser.add_argument("--model", type=str, required=True, help="Model to use for optimization")
53
+ parser.add_argument("--log-dir", type=str, default=".runs", help="Directory to store logs and results")
53
54
  parser.add_argument(
54
55
  "--additional-instructions",
55
56
  default=None,
@@ -83,7 +84,9 @@ def main() -> None:
83
84
  timeout = 800
84
85
 
85
86
  # Initialize panels
86
- summary_panel = SummaryPanel(maximize=maximize, metric_name=metric_name, total_steps=steps, model=args.model)
87
+ summary_panel = SummaryPanel(
88
+ maximize=maximize, metric_name=metric_name, total_steps=steps, model=args.model, runs_dir=args.log_dir
89
+ )
87
90
  plan_panel = PlanPanel()
88
91
  solution_panels = SolutionPanels(metric_name=metric_name)
89
92
  eval_output_panel = EvaluationOutputPanel()
@@ -112,7 +115,7 @@ def main() -> None:
112
115
  with Live(layout, refresh_per_second=refresh_rate, screen=True) as live:
113
116
  # Define the runs directory (.runs/<session-id>)
114
117
  session_id = session_response["session_id"]
115
- runs_dir = pathlib.Path(".runs") / session_id
118
+ runs_dir = pathlib.Path(args.log_dir) / session_id
116
119
  runs_dir.mkdir(parents=True, exist_ok=True)
117
120
 
118
121
  # Save the original code (.runs/<session-id>/original.py)
@@ -321,7 +324,12 @@ def main() -> None:
321
324
  _, best_solution_panel = solution_panels.get_display(current_step=steps)
322
325
 
323
326
  # Update the end optimization layout
324
- end_optimization_layout["summary"].update(summary_panel.get_display())
327
+ final_message = (
328
+ f"{summary_panel.metric_name.capitalize()} {'maximized' if summary_panel.maximize else 'minimized'}! Best solution {summary_panel.metric_name.lower()} = [green]{status_response['best_result']['metric_value']}[/] 🏆"
329
+ if best_solution_node is not None
330
+ else "[red] No solution found.[/]"
331
+ )
332
+ end_optimization_layout["summary"].update(summary_panel.get_display(final_message=final_message))
325
333
  end_optimization_layout["tree"].update(tree_panel.get_display())
326
334
  end_optimization_layout["best_solution"].update(best_solution_panel)
327
335
 
weco/panels.py CHANGED
@@ -11,13 +11,16 @@ from .utils import format_number
11
11
  class SummaryPanel:
12
12
  """Holds a summary of the optimization session."""
13
13
 
14
- def __init__(self, maximize: bool, metric_name: str, total_steps: int, model: str, session_id: str = None):
15
- self.goal = ("Maximizing" if maximize else "Minimizing") + f" {metric_name}..."
14
+ def __init__(self, maximize: bool, metric_name: str, total_steps: int, model: str, runs_dir: str, session_id: str = None):
15
+ self.maximize = maximize
16
+ self.metric_name = metric_name
17
+ self.goal = ("Maximizing" if self.maximize else "Minimizing") + f" {self.metric_name}..."
16
18
  self.total_input_tokens = 0
17
19
  self.total_output_tokens = 0
18
20
  self.total_steps = total_steps
19
21
  self.model = model
20
- self.session_id = session_id or "N/A"
22
+ self.runs_dir = runs_dir
23
+ self.session_id = session_id if session_id is not None else "N/A"
21
24
  self.progress = Progress(
22
25
  TextColumn("[progress.description]{task.description}"),
23
26
  BarColumn(bar_width=20),
@@ -39,24 +42,27 @@ class SummaryPanel:
39
42
  self.total_input_tokens += usage["input_tokens"]
40
43
  self.total_output_tokens += usage["output_tokens"]
41
44
 
42
- def get_display(self) -> Panel:
45
+ def get_display(self, final_message: Optional[str] = None) -> Panel:
43
46
  """Create a summary panel with the relevant information."""
44
47
  layout = Layout(name="summary")
45
48
  summary_table = Table(show_header=False, box=None, padding=(0, 1))
46
49
  # Goal
47
- summary_table.add_row(f"[bold cyan]Goal:[/] {self.goal}")
48
- summary_table.add_row("")
49
- # Log directory
50
- runs_dir = f".runs/{self.session_id}"
51
- summary_table.add_row(f"[bold cyan]Logs:[/] [blue underline]{runs_dir}[/]")
50
+ if final_message is not None:
51
+ summary_table.add_row(f"[bold cyan]Result:[/] {final_message}")
52
+ else:
53
+ summary_table.add_row(f"[bold cyan]Goal:[/] {self.goal}")
52
54
  summary_table.add_row("")
53
55
  # Model used
54
- summary_table.add_row(f"[bold cyan]Model:[/] [yellow]{self.model}[/]")
56
+ summary_table.add_row(f"[bold cyan]Model:[/] {self.model}")
57
+ summary_table.add_row("")
58
+ # Log directory
59
+ summary_table.add_row(f"[bold cyan]Logs:[/] [blue underline]{self.runs_dir}/{self.session_id}[/]")
55
60
  summary_table.add_row("")
56
61
  # Token counts
57
62
  summary_table.add_row(
58
63
  f"[bold cyan]Tokens:[/] ↑[yellow]{format_number(self.total_input_tokens)}[/] ↓[yellow]{format_number(self.total_output_tokens)}[/] = [green]{format_number(self.total_input_tokens + self.total_output_tokens)}[/]"
59
64
  )
65
+ summary_table.add_row("")
60
66
  # Progress bar
61
67
  summary_table.add_row(self.progress)
62
68
 
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: weco
3
- Version: 0.2.5
3
+ Version: 0.2.7
4
4
  Summary: Documentation for `weco`, a CLI for using Weco AI's code optimizer.
5
- Author-email: Weco AI Team <dhruv@weco.ai>
5
+ Author-email: Weco AI Team <contact@weco.ai>
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://github.com/WecoAI/weco-cli
8
8
  Keywords: AI,Code Optimization,Code Generation
@@ -99,32 +99,111 @@ Here's how `weco` can be applied to common ML engineering tasks:
99
99
 
100
100
  ### Examples
101
101
 
102
- **Example 1: Optimizing PyTorch operations**
102
+ **Example 1: Optimizing PyTorch simple operations**
103
103
 
104
104
  ```bash
105
- weco --source examples/simple-torch/optimize.py \
106
- --eval-command "python examples/simple-torch/evaluate.py --solution-path examples/simple-torch/optimize.py --device mps" \
105
+ cd examples/hello-kernel-world
106
+ pip install torch
107
+ weco --source optimize.py \
108
+ --eval-command "python evaluate.py --solution-path optimize.py --device cpu" \
107
109
  --metric speedup \
108
110
  --maximize true \
109
111
  --steps 15 \
110
- --model o3-mini \
112
+ --model gemini-2.5-pro-exp-03-25 \
111
113
  --additional-instructions "Fuse operations in the forward method while ensuring the max float deviation remains small. Maintain the same format of the code."
112
114
  ```
113
115
 
116
+ Note that if you have an NVIDIA gpu, change the device to `cuda`. If you are running this on Apple Silicon, set it to `mps`.
117
+
114
118
  **Example 2: Optimizing MLX operations with instructions from a file**
115
119
 
116
- 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.
120
+ Lets optimize a 2D convolution operation in [`mlx`](https://github.com/ml-explore/mlx) using [Metal](https://developer.apple.com/documentation/metal/). 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.
117
121
 
118
122
  ```bash
119
- weco --source examples/simple-mlx/optimize.py \
120
- --eval-command "python examples/simple-mlx/evaluate.py --solution-path examples/simple-mlx/optimize.py" \
123
+ cd examples/metal
124
+ pip install mlx
125
+ weco --source optimize.py \
126
+ --eval-command "python evaluate.py --solution-path optimize.py" \
121
127
  --metric speedup \
122
128
  --maximize true \
123
129
  --steps 30 \
124
- --model o3-mini \
125
- --additional-instructions examples/simple-mlx/metal-examples.rst
130
+ --model gemini-2.5-pro-exp-03-25 \
131
+ --additional-instructions examples.rst
126
132
  ```
127
133
 
134
+ **Example 3: Level Agnostic Optimization: Causal Self Attention with Triton & CUDA**
135
+
136
+ Given how useful causal multihead self attention is to transformers, we've seen its wide adoption across ML engineering and AI research. Its great to keep things at a high-level (in PyTorch) when doing research, but when moving to production you often need to write highly customized low-level kernels to make things run as fast as they can. The `weco` CLI can optimize kernels across a variety of different abstraction levels and frameworks. Example 2 uses Metal but lets explore two more frameworks:
137
+
138
+ 1. [Triton](https://github.com/triton-lang/triton)
139
+ ```bash
140
+ cd examples/triton
141
+ pip install torch triton
142
+ weco --source optimize.py \
143
+ --eval-command "python evaluate.py --solution-path optimize.py" \
144
+ --metric speedup \
145
+ --maximize true \
146
+ --steps 30 \
147
+ --model gemini-2.5-pro-exp-03-25 \
148
+ --additional-instructions "Use triton to optimize the code while ensuring a small max float diff. Maintain the same code format."
149
+ ```
150
+
151
+ 2. [CUDA](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html)
152
+ ```bash
153
+ cd examples/cuda
154
+ pip install torch
155
+ weco --source optimize.py \
156
+ --eval-command "python evaluate.py --solution-path optimize.py" \
157
+ --metric speedup \
158
+ --maximize true \
159
+ --steps 30 \
160
+ --model gemini-2.5-pro-exp-03-25 \
161
+ --additional-instructions guide.md
162
+ ```
163
+
164
+ **Example 4: Optimizing a Classification Model**
165
+
166
+ This example demonstrates optimizing a script for a Kaggle competition ([Spaceship Titanic](https://www.kaggle.com/competitions/spaceship-titanic/overview)) to improve classification accuracy. The additional instructions are provided via a separate file (`examples/spaceship-titanic/README.md`).
167
+
168
+ First, install the requirements for the example environment:
169
+ ```bash
170
+ pip install -r examples/spaceship-titanic/requirements-test.txt
171
+ ```
172
+ And run utility function once to prepare the dataset
173
+ ```bash
174
+ python examples/spaceship-titanic/utils.py
175
+ ```
176
+
177
+ You should see the following structure at `examples/spaceship-titanic`. You need to prepare the kaggle credentials for downloading the dataset.
178
+ ```
179
+ .
180
+ ├── baseline.py
181
+ ├── evaluate.py
182
+ ├── optimize.py
183
+ ├── private
184
+ │ └── test.csv
185
+ ├── public
186
+ │ ├── sample_submission.csv
187
+ │ ├── test.csv
188
+ │ └── train.csv
189
+ ├── README.md
190
+ ├── requirements-test.txt
191
+ └── utils.py
192
+ ```
193
+
194
+ Then, execute the optimization command:
195
+ ```bash
196
+ weco --source examples/spaceship-titanic/optimize.py \
197
+ --eval-command "python examples/spaceship-titanic/optimize.py && python examples/spaceship-titanic/evaluate.py" \
198
+ --metric accuracy \
199
+ --maximize true \
200
+ --steps 10 \
201
+ --model gemini-2.5-pro-exp-03-25 \
202
+ --additional-instructions examples/spaceship-titanic/README.md
203
+ ```
204
+
205
+ *The [baseline.py](examples/spaceship-titanic/baseline.py) is provided as a start point for optimization*
206
+
128
207
  ---
129
208
 
130
209
  ### Command Line Arguments
@@ -132,16 +211,28 @@ weco --source examples/simple-mlx/optimize.py \
132
211
  | Argument | Description | Required |
133
212
  | :-------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- |
134
213
  | `--source` | Path to the source code file that will be optimized (e.g., `optimize.py`). | Yes |
135
- | `--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 |
136
- | `--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 |
214
+ | `--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 |
215
+ | `--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 |
137
216
  | `--maximize` | Whether to maximize (`true`) or minimize (`false`) the metric. | Yes |
138
217
  | `--steps` | Number of optimization steps (LLM iterations) to run. | Yes |
139
- | `--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-2.5-pro-exp-03-25`. | Yes |
140
- | `--additional-instructions` | (Optional) Natural language description of specific instructions OR path to a file containing detailed instructions to guide the LLM. | No |
218
+ | `--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-2.5-pro-exp-03-25`.| Yes |
219
+ | `--additional-instructions` | (Optional) Natural language description of specific instructions OR path to a file containing detailed instructions to guide the LLM. | No |
220
+ | `--log-dir` | (Optional) Path to the directory to log intermediate steps and final optimization result. Defaults to `.runs/`. | No |
141
221
 
142
222
  ---
143
223
 
224
+ ### Performance & Expectations
225
+
226
+ Weco, powered by the AIDE algorithm, optimizes code iteratively based on your evaluation results. Achieving significant improvements, especially on complex research-level tasks, often requires substantial exploration time.
227
+
228
+ The following plot from the independent [Research Engineering Benchmark (RE-Bench)](https://metr.org/AI_R_D_Evaluation_Report.pdf) report shows the performance of AIDE (the algorithm behind Weco) on challenging ML research engineering tasks over different time budgets.
229
+ <p align="center">
230
+ <img src="https://github.com/user-attachments/assets/ff0e471d-2f50-4e2d-b718-874862f533df" alt="RE-Bench Performance Across Time" width="60%"/>
231
+ </p>
144
232
 
233
+ As shown, AIDE demonstrates strong performance gains over time, surpassing lower human expert percentiles within hours and continuing to improve. This highlights the potential of evaluation-driven optimization but also indicates that reaching high levels of performance comparable to human experts on difficult benchmarks can take considerable time (tens of hours in this specific benchmark, corresponding to many `--steps` in the Weco CLI). Factor this into your planning when setting the number of `--steps` for your optimization runs.
234
+
235
+ ---
145
236
 
146
237
  ### Important Note on Evaluation
147
238
 
@@ -0,0 +1,11 @@
1
+ weco/__init__.py,sha256=6ZYuD51wx6bytYdLFMvzihYrpBlSxiFbmuiEl0z_AFo,124
2
+ weco/api.py,sha256=8rIf2Fy3tN6GW7BG1CaggtfE9pW56I1erzwLCgawcVE,3511
3
+ weco/cli.py,sha256=h8FevpztBob7OziDTIKh4y9CSnehkHJp2ydts6V6DhM,17317
4
+ weco/panels.py,sha256=HHWmrnc2EJBJ8AEHb8mxlq30m-3q0j_4axc0r17sTnE,12349
5
+ weco/utils.py,sha256=hhIebUPnetFMfNSFfcsKVw1TSpeu_Zw3rBPPnxDie0U,3911
6
+ weco-0.2.7.dist-info/licenses/LICENSE,sha256=p_GQqJBvuZgkLNboYKyH-5dhpTDlKs2wq2TVM55WrWE,1065
7
+ weco-0.2.7.dist-info/METADATA,sha256=AlBfVky2jZ6C2MnB8k_WkSMyucTeTE1Ias3y3_4bVsE,14577
8
+ weco-0.2.7.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
9
+ weco-0.2.7.dist-info/entry_points.txt,sha256=ixJ2uClALbCpBvnIR6BXMNck8SHAab8eVkM9pIUowcs,39
10
+ weco-0.2.7.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
11
+ weco-0.2.7.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- weco/__init__.py,sha256=uqfsknG6Jxky4ddpuNn9SYN2lWNJloPDykqCjcmU1UQ,124
2
- weco/api.py,sha256=8rIf2Fy3tN6GW7BG1CaggtfE9pW56I1erzwLCgawcVE,3511
3
- weco/cli.py,sha256=rb01pl0Q8sLKBpZ9Qtlz044pEppJAa8CJkv2XM9zzFo,16753
4
- weco/panels.py,sha256=5HrDrYzx_vDjV41mlZmOOZYxdJIXD5RzBBNKXxUOLEY,12022
5
- weco/utils.py,sha256=hhIebUPnetFMfNSFfcsKVw1TSpeu_Zw3rBPPnxDie0U,3911
6
- weco-0.2.5.dist-info/licenses/LICENSE,sha256=p_GQqJBvuZgkLNboYKyH-5dhpTDlKs2wq2TVM55WrWE,1065
7
- weco-0.2.5.dist-info/METADATA,sha256=bjW2DWItTu3y_lmLllZIRz43hh5vMCi_u4FXW5eKz5E,9863
8
- weco-0.2.5.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
9
- weco-0.2.5.dist-info/entry_points.txt,sha256=ixJ2uClALbCpBvnIR6BXMNck8SHAab8eVkM9pIUowcs,39
10
- weco-0.2.5.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
11
- weco-0.2.5.dist-info/RECORD,,
File without changes