weco 0.2.3__py3-none-any.whl → 0.2.5__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 +1 -1
- weco/api.py +8 -2
- weco/cli.py +61 -47
- weco/panels.py +9 -7
- weco/utils.py +8 -4
- weco-0.2.5.dist-info/METADATA +189 -0
- weco-0.2.5.dist-info/RECORD +11 -0
- weco-0.2.3.dist-info/METADATA +0 -141
- weco-0.2.3.dist-info/RECORD +0 -11
- {weco-0.2.3.dist-info → weco-0.2.5.dist-info}/WHEEL +0 -0
- {weco-0.2.3.dist-info → weco-0.2.5.dist-info}/entry_points.txt +0 -0
- {weco-0.2.3.dist-info → weco-0.2.5.dist-info}/licenses/LICENSE +0 -0
- {weco-0.2.3.dist-info → weco-0.2.5.dist-info}/top_level.txt +0 -0
weco/__init__.py
CHANGED
weco/api.py
CHANGED
|
@@ -29,6 +29,7 @@ def start_optimization_session(
|
|
|
29
29
|
search_policy_config: Dict[str, Any],
|
|
30
30
|
additional_instructions: str = None,
|
|
31
31
|
api_keys: Dict[str, Any] = {},
|
|
32
|
+
timeout: int = 800,
|
|
32
33
|
) -> Dict[str, Any]:
|
|
33
34
|
"""Start the optimization session."""
|
|
34
35
|
with console.status("[bold green]Starting Optimization..."):
|
|
@@ -47,6 +48,7 @@ def start_optimization_session(
|
|
|
47
48
|
},
|
|
48
49
|
"metadata": {"client_name": "cli", "client_version": __pkg_version__, **api_keys},
|
|
49
50
|
},
|
|
51
|
+
timeout=timeout,
|
|
50
52
|
)
|
|
51
53
|
response.raise_for_status()
|
|
52
54
|
return response.json()
|
|
@@ -60,6 +62,7 @@ def evaluate_feedback_then_suggest_next_solution(
|
|
|
60
62
|
execution_output: str,
|
|
61
63
|
additional_instructions: str = None,
|
|
62
64
|
api_keys: Dict[str, Any] = {},
|
|
65
|
+
timeout: int = 800,
|
|
63
66
|
) -> Dict[str, Any]:
|
|
64
67
|
"""Evaluate the feedback and suggest the next solution."""
|
|
65
68
|
try:
|
|
@@ -70,6 +73,7 @@ def evaluate_feedback_then_suggest_next_solution(
|
|
|
70
73
|
"additional_instructions": additional_instructions,
|
|
71
74
|
"metadata": {**api_keys},
|
|
72
75
|
},
|
|
76
|
+
timeout=timeout,
|
|
73
77
|
)
|
|
74
78
|
response.raise_for_status()
|
|
75
79
|
return response.json()
|
|
@@ -78,11 +82,13 @@ def evaluate_feedback_then_suggest_next_solution(
|
|
|
78
82
|
|
|
79
83
|
|
|
80
84
|
def get_optimization_session_status(
|
|
81
|
-
console: rich.console.Console, session_id: str, include_history: bool = False
|
|
85
|
+
console: rich.console.Console, session_id: str, include_history: bool = False, timeout: int = 800
|
|
82
86
|
) -> Dict[str, Any]:
|
|
83
87
|
"""Get the current status of the optimization session."""
|
|
84
88
|
try:
|
|
85
|
-
response = requests.get(
|
|
89
|
+
response = requests.get(
|
|
90
|
+
f"{__base_url__}/sessions/{session_id}", params={"include_history": include_history}, timeout=timeout
|
|
91
|
+
)
|
|
86
92
|
response.raise_for_status()
|
|
87
93
|
return response.json()
|
|
88
94
|
except requests.exceptions.HTTPError as e:
|
weco/cli.py
CHANGED
|
@@ -79,6 +79,8 @@ def main() -> None:
|
|
|
79
79
|
source_code = read_from_path(fp=source_fp, is_json=False)
|
|
80
80
|
# Read API keys
|
|
81
81
|
api_keys = read_api_keys_from_env()
|
|
82
|
+
# API request timeout
|
|
83
|
+
timeout = 800
|
|
82
84
|
|
|
83
85
|
# Initialize panels
|
|
84
86
|
summary_panel = SummaryPanel(maximize=maximize, metric_name=metric_name, total_steps=steps, model=args.model)
|
|
@@ -102,56 +104,62 @@ def main() -> None:
|
|
|
102
104
|
search_policy_config=search_policy_config,
|
|
103
105
|
additional_instructions=additional_instructions,
|
|
104
106
|
api_keys=api_keys,
|
|
107
|
+
timeout=timeout,
|
|
105
108
|
)
|
|
106
109
|
|
|
107
|
-
# Define the runs directory (.runs/<session-id>)
|
|
108
|
-
session_id = session_response["session_id"]
|
|
109
|
-
runs_dir = pathlib.Path(".runs") / session_id
|
|
110
|
-
runs_dir.mkdir(parents=True, exist_ok=True)
|
|
111
|
-
|
|
112
|
-
# Save the original code (.runs/<session-id>/original.py)
|
|
113
|
-
runs_copy_source_fp = runs_dir / "original.py"
|
|
114
|
-
write_to_path(fp=runs_copy_source_fp, content=source_code)
|
|
115
|
-
|
|
116
|
-
# Write the code string to the source file path
|
|
117
|
-
# Do this after the original code is saved
|
|
118
|
-
write_to_path(fp=source_fp, content=session_response["code"])
|
|
119
|
-
|
|
120
|
-
# Update the panels with the initial solution
|
|
121
|
-
# Add session id now that we have it
|
|
122
|
-
summary_panel.session_id = session_id
|
|
123
|
-
# Set the step of the progress bar
|
|
124
|
-
summary_panel.set_step(step=0)
|
|
125
|
-
# Update the token counts
|
|
126
|
-
summary_panel.update_token_counts(usage=session_response["usage"])
|
|
127
|
-
# Update the plan
|
|
128
|
-
plan_panel.update(plan=session_response["plan"])
|
|
129
|
-
# Build the metric tree
|
|
130
|
-
tree_panel.build_metric_tree(
|
|
131
|
-
nodes=[
|
|
132
|
-
{
|
|
133
|
-
"solution_id": session_response["solution_id"],
|
|
134
|
-
"parent_id": None,
|
|
135
|
-
"code": session_response["code"],
|
|
136
|
-
"step": 0,
|
|
137
|
-
"metric_value": None,
|
|
138
|
-
"is_buggy": False,
|
|
139
|
-
}
|
|
140
|
-
]
|
|
141
|
-
)
|
|
142
|
-
# Set the current solution as unevaluated since we haven't run the evaluation function and fed it back to the model yet
|
|
143
|
-
tree_panel.set_unevaluated_node(node_id=session_response["solution_id"])
|
|
144
|
-
# Update the solution panels with the initial solution and get the panel displays
|
|
145
|
-
solution_panels.update(
|
|
146
|
-
current_node=Node(
|
|
147
|
-
id=session_response["solution_id"], parent_id=None, code=session_response["code"], metric=None, is_buggy=False
|
|
148
|
-
),
|
|
149
|
-
best_node=None,
|
|
150
|
-
)
|
|
151
|
-
current_solution_panel, best_solution_panel = solution_panels.get_display(current_step=0)
|
|
152
110
|
# Define the refresh rate
|
|
153
111
|
refresh_rate = 4
|
|
154
112
|
with Live(layout, refresh_per_second=refresh_rate, screen=True) as live:
|
|
113
|
+
# Define the runs directory (.runs/<session-id>)
|
|
114
|
+
session_id = session_response["session_id"]
|
|
115
|
+
runs_dir = pathlib.Path(".runs") / session_id
|
|
116
|
+
runs_dir.mkdir(parents=True, exist_ok=True)
|
|
117
|
+
|
|
118
|
+
# Save the original code (.runs/<session-id>/original.py)
|
|
119
|
+
runs_copy_source_fp = runs_dir / "original.py"
|
|
120
|
+
write_to_path(fp=runs_copy_source_fp, content=source_code)
|
|
121
|
+
|
|
122
|
+
# Write the code string to the source file path
|
|
123
|
+
# Do this after the original code is saved
|
|
124
|
+
write_to_path(fp=source_fp, content=session_response["code"])
|
|
125
|
+
|
|
126
|
+
# Update the panels with the initial solution
|
|
127
|
+
# Add session id now that we have it
|
|
128
|
+
summary_panel.session_id = session_id
|
|
129
|
+
# Set the step of the progress bar
|
|
130
|
+
summary_panel.set_step(step=0)
|
|
131
|
+
# Update the token counts
|
|
132
|
+
summary_panel.update_token_counts(usage=session_response["usage"])
|
|
133
|
+
# Update the plan
|
|
134
|
+
plan_panel.update(plan=session_response["plan"])
|
|
135
|
+
# Build the metric tree
|
|
136
|
+
tree_panel.build_metric_tree(
|
|
137
|
+
nodes=[
|
|
138
|
+
{
|
|
139
|
+
"solution_id": session_response["solution_id"],
|
|
140
|
+
"parent_id": None,
|
|
141
|
+
"code": session_response["code"],
|
|
142
|
+
"step": 0,
|
|
143
|
+
"metric_value": None,
|
|
144
|
+
"is_buggy": False,
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
)
|
|
148
|
+
# Set the current solution as unevaluated since we haven't run the evaluation function and fed it back to the model yet
|
|
149
|
+
tree_panel.set_unevaluated_node(node_id=session_response["solution_id"])
|
|
150
|
+
# Update the solution panels with the initial solution and get the panel displays
|
|
151
|
+
solution_panels.update(
|
|
152
|
+
current_node=Node(
|
|
153
|
+
id=session_response["solution_id"],
|
|
154
|
+
parent_id=None,
|
|
155
|
+
code=session_response["code"],
|
|
156
|
+
metric=None,
|
|
157
|
+
is_buggy=False,
|
|
158
|
+
),
|
|
159
|
+
best_node=None,
|
|
160
|
+
)
|
|
161
|
+
current_solution_panel, best_solution_panel = solution_panels.get_display(current_step=0)
|
|
162
|
+
|
|
155
163
|
# Update the entire layout
|
|
156
164
|
smooth_update(
|
|
157
165
|
live=live,
|
|
@@ -187,6 +195,7 @@ def main() -> None:
|
|
|
187
195
|
execution_output=term_out,
|
|
188
196
|
additional_instructions=additional_instructions,
|
|
189
197
|
api_keys=api_keys,
|
|
198
|
+
timeout=timeout,
|
|
190
199
|
)
|
|
191
200
|
# Save next solution (.runs/<session-id>/step_<step>.py)
|
|
192
201
|
write_to_path(fp=runs_dir / f"step_{step}.py", content=eval_and_next_solution_response["code"])
|
|
@@ -196,7 +205,9 @@ def main() -> None:
|
|
|
196
205
|
|
|
197
206
|
# Get the optimization session status for
|
|
198
207
|
# the best solution, its score, and the history to plot the tree
|
|
199
|
-
status_response = get_optimization_session_status(
|
|
208
|
+
status_response = get_optimization_session_status(
|
|
209
|
+
console=console, session_id=session_id, include_history=True, timeout=timeout
|
|
210
|
+
)
|
|
200
211
|
|
|
201
212
|
# Update the step of the progress bar
|
|
202
213
|
summary_panel.set_step(step=step)
|
|
@@ -276,6 +287,7 @@ def main() -> None:
|
|
|
276
287
|
execution_output=term_out,
|
|
277
288
|
additional_instructions=additional_instructions,
|
|
278
289
|
api_keys=api_keys,
|
|
290
|
+
timeout=timeout,
|
|
279
291
|
)
|
|
280
292
|
|
|
281
293
|
# Update the progress bar
|
|
@@ -285,7 +297,9 @@ def main() -> None:
|
|
|
285
297
|
# No need to update the plan panel since we have finished the optimization
|
|
286
298
|
# Get the optimization session status for
|
|
287
299
|
# the best solution, its score, and the history to plot the tree
|
|
288
|
-
status_response = get_optimization_session_status(
|
|
300
|
+
status_response = get_optimization_session_status(
|
|
301
|
+
console=console, session_id=session_id, include_history=True, timeout=timeout
|
|
302
|
+
)
|
|
289
303
|
# Build the metric tree
|
|
290
304
|
tree_panel.build_metric_tree(nodes=status_response["history"])
|
|
291
305
|
# No need to set any solution to unevaluated since we have finished the optimization
|
weco/panels.py
CHANGED
|
@@ -12,7 +12,7 @@ class SummaryPanel:
|
|
|
12
12
|
"""Holds a summary of the optimization session."""
|
|
13
13
|
|
|
14
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}"
|
|
15
|
+
self.goal = ("Maximizing" if maximize else "Minimizing") + f" {metric_name}..."
|
|
16
16
|
self.total_input_tokens = 0
|
|
17
17
|
self.total_output_tokens = 0
|
|
18
18
|
self.total_steps = total_steps
|
|
@@ -48,10 +48,10 @@ class SummaryPanel:
|
|
|
48
48
|
summary_table.add_row("")
|
|
49
49
|
# Log directory
|
|
50
50
|
runs_dir = f".runs/{self.session_id}"
|
|
51
|
-
summary_table.add_row(f"[bold cyan]Logs:[/] [blue]{runs_dir}[/]")
|
|
51
|
+
summary_table.add_row(f"[bold cyan]Logs:[/] [blue underline]{runs_dir}[/]")
|
|
52
52
|
summary_table.add_row("")
|
|
53
53
|
# Model used
|
|
54
|
-
summary_table.add_row(f"[bold cyan]Model:[/] {self.model}")
|
|
54
|
+
summary_table.add_row(f"[bold cyan]Model:[/] [yellow]{self.model}[/]")
|
|
55
55
|
summary_table.add_row("")
|
|
56
56
|
# Token counts
|
|
57
57
|
summary_table.add_row(
|
|
@@ -197,7 +197,7 @@ class MetricTreePanel:
|
|
|
197
197
|
# best node
|
|
198
198
|
color = "green"
|
|
199
199
|
style = "bold"
|
|
200
|
-
text = f"
|
|
200
|
+
text = f"{node.metric:.3f} 🏆"
|
|
201
201
|
elif node.metric is None:
|
|
202
202
|
# metric not extracted from evaluated solution
|
|
203
203
|
color = "yellow"
|
|
@@ -214,7 +214,7 @@ class MetricTreePanel:
|
|
|
214
214
|
for child in node.children:
|
|
215
215
|
append_rec(child, subtree)
|
|
216
216
|
|
|
217
|
-
tree = Tree("
|
|
217
|
+
tree = Tree("🌳")
|
|
218
218
|
for n in self.metric_tree.get_draft_nodes():
|
|
219
219
|
append_rec(n, tree)
|
|
220
220
|
|
|
@@ -223,7 +223,9 @@ class MetricTreePanel:
|
|
|
223
223
|
def get_display(self) -> Panel:
|
|
224
224
|
"""Get a panel displaying the solution tree."""
|
|
225
225
|
# Make sure the metric tree is built before calling build_rich_tree
|
|
226
|
-
return Panel(
|
|
226
|
+
return Panel(
|
|
227
|
+
self._build_rich_tree(), title="[bold]🔎 Exploring Solutions...", border_style="green", expand=True, padding=(0, 1)
|
|
228
|
+
)
|
|
227
229
|
|
|
228
230
|
|
|
229
231
|
class EvaluationOutputPanel:
|
|
@@ -242,7 +244,7 @@ class EvaluationOutputPanel:
|
|
|
242
244
|
|
|
243
245
|
def get_display(self) -> Panel:
|
|
244
246
|
"""Create a panel displaying the evaluation output with truncation if needed."""
|
|
245
|
-
return Panel(self.output, title="[bold]📋 Evaluation Output", border_style="
|
|
247
|
+
return Panel(self.output, title="[bold]📋 Evaluation Output", border_style="blue", expand=True, padding=(0, 1))
|
|
246
248
|
|
|
247
249
|
|
|
248
250
|
class SolutionPanels:
|
weco/utils.py
CHANGED
|
@@ -28,10 +28,14 @@ def read_additional_instructions(additional_instructions: str | None) -> str | N
|
|
|
28
28
|
|
|
29
29
|
# Try interpreting as a path first
|
|
30
30
|
potential_path = pathlib.Path(additional_instructions)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
try:
|
|
32
|
+
if potential_path.exists() and potential_path.is_file():
|
|
33
|
+
return read_from_path(potential_path, is_json=False) # type: ignore # read_from_path returns str when is_json=False
|
|
34
|
+
else:
|
|
35
|
+
# If it's not a valid file path, return the string itself
|
|
36
|
+
return additional_instructions
|
|
37
|
+
except OSError:
|
|
38
|
+
# If the path can't be read, return the string itself
|
|
35
39
|
return additional_instructions
|
|
36
40
|
|
|
37
41
|
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: weco
|
|
3
|
+
Version: 0.2.5
|
|
4
|
+
Summary: Documentation for `weco`, a CLI for using Weco AI's code optimizer.
|
|
5
|
+
Author-email: Weco AI Team <dhruv@weco.ai>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/WecoAI/weco-cli
|
|
8
|
+
Keywords: AI,Code Optimization,Code Generation
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Requires-Dist: rich
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: ruff; extra == "dev"
|
|
19
|
+
Requires-Dist: build; extra == "dev"
|
|
20
|
+
Requires-Dist: setuptools_scm; extra == "dev"
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# Weco CLI – Code Optimizer for Machine Learning Engineers
|
|
24
|
+
|
|
25
|
+
[](https://www.python.org)
|
|
26
|
+
[](LICENSE)
|
|
27
|
+
[](https://badge.fury.io/py/weco)
|
|
28
|
+
|
|
29
|
+
`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.
|
|
30
|
+
|
|
31
|
+
https://github.com/user-attachments/assets/cb724ef1-bff6-4757-b457-d3b2201ede81
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Overview
|
|
36
|
+
|
|
37
|
+
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.
|
|
38
|
+
|
|
39
|
+

|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Example Use Cases
|
|
44
|
+
|
|
45
|
+
Here's how `weco` can be applied to common ML engineering tasks:
|
|
46
|
+
|
|
47
|
+
* **GPU Kernel Optimization:**
|
|
48
|
+
* **Goal:** Improve the speed or efficiency of low-level GPU code.
|
|
49
|
+
* **How:** `weco` iteratively refines CUDA, Triton, Metal, or other kernel code specified in your `--source` file.
|
|
50
|
+
* **`--eval-command`:** Typically runs a script that compiles the kernel, executes it, and benchmarks performance (e.g., latency, throughput).
|
|
51
|
+
* **`--metric`:** Examples include `latency`, `throughput`, `TFLOPS`, `memory_bandwidth`. Optimize to `minimize` latency or `maximize` throughput.
|
|
52
|
+
|
|
53
|
+
* **Feature Engineering:**
|
|
54
|
+
* **Goal:** Discover better data transformations or feature combinations for your machine learning models.
|
|
55
|
+
* **How:** `weco` explores different processing steps or parameters within your feature transformation code (`--source`).
|
|
56
|
+
* **`--eval-command`:** Executes a script that applies the features, trains/validates a model using those features, and prints a performance score.
|
|
57
|
+
* **`--metric`:** Examples include `accuracy`, `AUC`, `F1-score`, `validation_loss`. Usually optimized to `maximize` accuracy/AUC/F1 or `minimize` loss.
|
|
58
|
+
|
|
59
|
+
* **Model Development:**
|
|
60
|
+
* **Goal:** Tune hyperparameters or experiment with small architectural changes directly within your model's code.
|
|
61
|
+
* **How:** `weco` modifies hyperparameter values (like learning rate, layer sizes if defined in the code) or structural elements in your model definition (`--source`).
|
|
62
|
+
* **`--eval-command`:** Runs your model training and evaluation script, printing the key performance indicator.
|
|
63
|
+
* **`--metric`:** Examples include `validation_accuracy`, `test_loss`, `inference_time`, `perplexity`. Optimize according to the metric's nature (e.g., `maximize` accuracy, `minimize` loss).
|
|
64
|
+
|
|
65
|
+
* **Prompt Engineering:**
|
|
66
|
+
* **Goal:** Refine prompts used within larger systems (e.g., for LLM interactions) to achieve better or more consistent outputs.
|
|
67
|
+
* **How:** `weco` modifies prompt templates, examples, or instructions stored in the `--source` file.
|
|
68
|
+
* **`--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.
|
|
69
|
+
* **`--metric`:** Examples include `quality_score`, `relevance`, `task_success_rate`, `format_adherence`. Usually optimized to `maximize`.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## Setup
|
|
75
|
+
|
|
76
|
+
1. **Install the Package:**
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install weco
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
2. **Configure API Keys:**
|
|
83
|
+
|
|
84
|
+
Set the appropriate environment variables for your desired language model provider:
|
|
85
|
+
|
|
86
|
+
- **OpenAI:** `export OPENAI_API_KEY="your_key_here"`
|
|
87
|
+
- **Anthropic:** `export ANTHROPIC_API_KEY="your_key_here"`
|
|
88
|
+
- **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.)
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Usage
|
|
93
|
+
<div style="background-color: #fff3cd; border: 1px solid #ffeeba; padding: 15px; border-radius: 4px; margin-bottom: 15px;">
|
|
94
|
+
<strong>⚠️ Warning: Code Modification</strong><br>
|
|
95
|
+
<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.
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### Examples
|
|
101
|
+
|
|
102
|
+
**Example 1: Optimizing PyTorch operations**
|
|
103
|
+
|
|
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" \
|
|
107
|
+
--metric speedup \
|
|
108
|
+
--maximize true \
|
|
109
|
+
--steps 15 \
|
|
110
|
+
--model o3-mini \
|
|
111
|
+
--additional-instructions "Fuse operations in the forward method while ensuring the max float deviation remains small. Maintain the same format of the code."
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Example 2: Optimizing MLX operations with instructions from a file**
|
|
115
|
+
|
|
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.
|
|
117
|
+
|
|
118
|
+
```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" \
|
|
121
|
+
--metric speedup \
|
|
122
|
+
--maximize true \
|
|
123
|
+
--steps 30 \
|
|
124
|
+
--model o3-mini \
|
|
125
|
+
--additional-instructions examples/simple-mlx/metal-examples.rst
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### Command Line Arguments
|
|
131
|
+
|
|
132
|
+
| Argument | Description | Required |
|
|
133
|
+
| :-------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- |
|
|
134
|
+
| `--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 |
|
|
137
|
+
| `--maximize` | Whether to maximize (`true`) or minimize (`false`) the metric. | Yes |
|
|
138
|
+
| `--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 |
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
### Important Note on Evaluation
|
|
147
|
+
|
|
148
|
+
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.
|
|
149
|
+
|
|
150
|
+
For example, if you set `--metric speedup`, your evaluation script (`eval.py` in the examples) should output a line like:
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
speedup: 1.5
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
or
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
Final speedup value = 1.5
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Weco will parse this output to extract the numerical value (1.5 in this case) associated with the metric name ('speedup').
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
We welcome contributions! To get started:
|
|
168
|
+
|
|
169
|
+
1. **Fork and Clone the Repository:**
|
|
170
|
+
```bash
|
|
171
|
+
git clone https://github.com/WecoAI/weco-cli.git
|
|
172
|
+
cd weco-cli
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
2. **Install Development Dependencies:**
|
|
176
|
+
```bash
|
|
177
|
+
pip install -e ".[dev]"
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
3. **Create a Feature Branch:**
|
|
181
|
+
```bash
|
|
182
|
+
git checkout -b feature/your-feature-name
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
4. **Make Your Changes:** Ensure your code adheres to our style guidelines and includes relevant tests.
|
|
186
|
+
|
|
187
|
+
5. **Commit and Push** your changes, then open a pull request with a clear description of your enhancements.
|
|
188
|
+
|
|
189
|
+
---
|
|
@@ -0,0 +1,11 @@
|
|
|
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,,
|
weco-0.2.3.dist-info/METADATA
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: weco
|
|
3
|
-
Version: 0.2.3
|
|
4
|
-
Summary: Documentation for `weco`, a CLI for using Weco AI's code optimizer.
|
|
5
|
-
Author-email: Weco AI Team <dhruv@weco.ai>
|
|
6
|
-
License: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/WecoAI/weco-cli
|
|
8
|
-
Keywords: AI,Code Optimization,Code Generation
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
-
Requires-Python: >=3.12
|
|
13
|
-
Description-Content-Type: text/markdown
|
|
14
|
-
License-File: LICENSE
|
|
15
|
-
Requires-Dist: requests
|
|
16
|
-
Requires-Dist: rich
|
|
17
|
-
Provides-Extra: dev
|
|
18
|
-
Requires-Dist: ruff; extra == "dev"
|
|
19
|
-
Requires-Dist: build; extra == "dev"
|
|
20
|
-
Requires-Dist: setuptools_scm; extra == "dev"
|
|
21
|
-
Dynamic: license-file
|
|
22
|
-
|
|
23
|
-
# Weco CLI – Code Optimizer for Machine Learning Engineers
|
|
24
|
-
|
|
25
|
-
[](https://www.python.org)
|
|
26
|
-
[](LICENSE)
|
|
27
|
-
|
|
28
|
-
`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).
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
https://github.com/user-attachments/assets/cb724ef1-bff6-4757-b457-d3b2201ede81
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
## Overview
|
|
39
|
-
|
|
40
|
-
The weco CLI leverages a tree search approach with LLMs to iteratively improve your code.
|
|
41
|
-
|
|
42
|
-

|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## Setup
|
|
49
|
-
|
|
50
|
-
1. **Install the Package:**
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
pip install weco
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
2. **Configure API Keys:**
|
|
57
|
-
|
|
58
|
-
Set the appropriate environment variables for your language model provider:
|
|
59
|
-
|
|
60
|
-
- **OpenAI:** `export OPENAI_API_KEY="your_key_here"`
|
|
61
|
-
- **Anthropic:** `export ANTHROPIC_API_KEY="your_key_here"`
|
|
62
|
-
- **Google DeepMind:** `export GEMINI_API_KEY="your_key_here"`
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
## Usage
|
|
67
|
-
|
|
68
|
-
### Command Line Arguments
|
|
69
|
-
|
|
70
|
-
| Argument | Description | Required |
|
|
71
|
-
|-----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|----------|
|
|
72
|
-
| `--source` | Path to the Python source code that will be optimized (e.g. optimize.py). | Yes |
|
|
73
|
-
| `--eval-command` | Command to run for evaluation (e.g. 'python eval.py --arg1=val1'). | Yes |
|
|
74
|
-
| `--metric` | Metric to optimize. | Yes |
|
|
75
|
-
| `--maximize` | Whether to maximize ('true') or minimize ('false') the metric. | Yes |
|
|
76
|
-
| `--steps` | Number of optimization steps to run. | Yes |
|
|
77
|
-
| `--model` | Model to use for optimization. | Yes |
|
|
78
|
-
| `--additional-instructions` | (Optional) Description of additional instructions OR path to a file containing additional instructions. | No |
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
### Example
|
|
83
|
-
|
|
84
|
-
Optimizing common operations in pytorch:
|
|
85
|
-
```bash
|
|
86
|
-
weco --source examples/simple-torch/optimize.py \
|
|
87
|
-
--eval-command "python examples/simple-torch/evaluate.py --solution-path examples/simple-torch/optimize.py --device mps" \
|
|
88
|
-
--metric speedup \
|
|
89
|
-
--maximize true \
|
|
90
|
-
--steps 15 \
|
|
91
|
-
--model "o3-mini" \
|
|
92
|
-
--additional-instructions "Fuse operations in the forward method while ensuring the max float deviation remains small. Maintain the same format of the code."
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Optimizing these same using mlx and metal:
|
|
96
|
-
```bash
|
|
97
|
-
weco --source examples/simple-mlx/optimize.py \
|
|
98
|
-
--eval-command "python examples/simple-mlx/evaluate.py --solution-path examples/simple-mlx/optimize.py" \
|
|
99
|
-
--metric speedup \
|
|
100
|
-
--maximize true \
|
|
101
|
-
--steps 30 \
|
|
102
|
-
--model "o3-mini" \
|
|
103
|
-
--additional-instructions "examples/simple-mlx/metal-examples.rst"
|
|
104
|
-
```
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
## Supported Providers
|
|
108
|
-
|
|
109
|
-
The CLI supports the following model providers:
|
|
110
|
-
|
|
111
|
-
- **OpenAI:** Set your API key using `OPENAI_API_KEY`.
|
|
112
|
-
- **Anthropic:** Set your API key using `ANTHROPIC_API_KEY`.
|
|
113
|
-
- **Google DeepMind:** Set your API key using `GEMINI_API_KEY`.
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## Contributing
|
|
118
|
-
|
|
119
|
-
We welcome contributions! To get started:
|
|
120
|
-
|
|
121
|
-
1. **Fork and Clone the Repository:**
|
|
122
|
-
```bash
|
|
123
|
-
git clone https://github.com/WecoAI/weco-cli.git
|
|
124
|
-
cd weco-cli
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
2. **Install Development Dependencies:**
|
|
128
|
-
```bash
|
|
129
|
-
pip install -e ".[dev]"
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
3. **Create a Feature Branch:**
|
|
133
|
-
```bash
|
|
134
|
-
git checkout -b feature/your-feature-name
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
4. **Make Your Changes:** Ensure your code adheres to our style guidelines and includes relevant tests.
|
|
138
|
-
|
|
139
|
-
5. **Commit and Push** your changes, then open a pull request with a clear description of your enhancements.
|
|
140
|
-
|
|
141
|
-
---
|
weco-0.2.3.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
weco/__init__.py,sha256=bR_VMLdj9CKuS7r20P1w045efBJ-Jndx8NFtQVc3_78,124
|
|
2
|
-
weco/api.py,sha256=JHAm60sO51Y2tzLnyAAFv9OLm75o_RNWeoK-gYF4VHE,3342
|
|
3
|
-
weco/cli.py,sha256=Raq6X5ZSalPe0BV18UA_arC_jrNkQkJ4gDqWNTMlfsI,16242
|
|
4
|
-
weco/panels.py,sha256=Y0K6Nx4uCBREdVL1c3ee7a3ZNjyhXJFThZBCToG3xO0,11970
|
|
5
|
-
weco/utils.py,sha256=g1Lchd3_L-eGRNkqr2IyRZ5FJfZTrFf9aTmmpMtdhko,3761
|
|
6
|
-
weco-0.2.3.dist-info/licenses/LICENSE,sha256=p_GQqJBvuZgkLNboYKyH-5dhpTDlKs2wq2TVM55WrWE,1065
|
|
7
|
-
weco-0.2.3.dist-info/METADATA,sha256=GXFnAZjqNTXZGq8NC_zWvuq243ZZSsW0zYGrVEP8K0Y,5229
|
|
8
|
-
weco-0.2.3.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
9
|
-
weco-0.2.3.dist-info/entry_points.txt,sha256=ixJ2uClALbCpBvnIR6BXMNck8SHAab8eVkM9pIUowcs,39
|
|
10
|
-
weco-0.2.3.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
|
|
11
|
-
weco-0.2.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|