Weco systematically optimizes your code, guided directly by your evaluation metrics.
Example applications include:
- GPU Kernel Optimization: Reimplement PyTorch functions using CUDA or Triton, optimizing for
latency
,throughput
, ormemory_bandwidth
. - Model Development: Tune feature transformations, architectures or the whole training pipeline, optimizing for
validation_accuracy
,AUC
, orSharpe Ratio
. - Prompt Engineering: Refine prompts for LLMs (e.g., for math problems), optimizing for
win_rate
,relevance
, orformat_adherence
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.
-
Install the Package:
pip install weco
-
Set Up LLM API Keys (Required):
weco
requires API keys for the Large Language Models (LLMs) it uses internally. You must provide these keys via environment variables:- OpenAI:
export OPENAI_API_KEY="your_key_here"
- Anthropic:
export ANTHROPIC_API_KEY="your_key_here"
- Google DeepMind:
export GEMINI_API_KEY="your_key_here"
(Google AI Studio has a free API usage quota. Create a key here to useweco
for free.)
- OpenAI:
weco
directly modifies the file specified by --source
during the optimization process. It is strongly recommended 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.
Example: Optimizing Simple PyTorch Operations
This basic example shows how to optimize a simple PyTorch function for speedup.
For more advanced examples, including Triton, CUDA kernel optimization, ML model optimization, and prompt engineering for math problems, please see the README.md
files within the corresponding subdirectories under the examples/
folder.
# Navigate to the example directory
cd examples/hello-kernel-world
# Install dependencies
pip install torch
# Run Weco
weco run --source optimize.py \
--eval-command "python evaluate.py --solution-path optimize.py --device cpu" \
--metric speedup \
--goal maximize \
--steps 15 \
--additional-instructions "Fuse operations in the forward method while ensuring the max float deviation remains small. Maintain the same format of the code."
Note: If you have an NVIDIA GPU, change the device in the --eval-command
to cuda
. If you are running this on Apple Silicon, set it to mps
.
Required:
Argument | Description |
---|---|
-s, --source |
Path to the source code file that will be optimized (e.g., optimize.py ). |
-c, --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. |
-m, --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 . |
-g, --goal |
maximize /max to maximize the --metric or minimize /min to minimize it. |
Optional:
Argument | Description | Default |
---|---|---|
-n, --steps |
Number of optimization steps (LLM iterations) to run. | 100 |
-M, --model |
Model identifier for the LLM to use (e.g., gpt-4o , claude-3.5-sonnet ). |
o4-mini when OPENAI_API_KEY is set; claude-3-7-sonnet-20250219 when ANTHROPIC_API_KEY is set; gemini-2.5-pro-exp-03-25 when GEMINI_API_KEY is set (priority: OPENAI_API_KEY > ANTHROPIC_API_KEY > GEMINI_API_KEY ). |
-i, --additional-instructions |
Natural language description of specific instructions or path to a file containing detailed instructions to guide the LLM. | None |
-l, --log-dir |
Path to the directory to log intermediate steps and final optimization result. | .runs/ |
To associate your optimization runs with your Weco account and view them on the Weco dashboard, you can log in. weco
uses a device authentication flow
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.
The following plot from the independent Research Engineering Benchmark (RE-Bench) report shows the performance of AIDE (the algorithm behind Weco) on challenging ML research engineering tasks over different time budgets.
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.
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.
For example, if you set --metric speedup
, your evaluation script (eval.py
in the examples) should output a line like:
speedup: 1.5
or
Final speedup value = 1.5
Weco will parse this output to extract the numerical value (1.5 in this case) associated with the metric name ('speedup').
We welcome contributions! To get started:
-
Fork and Clone the Repository:
git clone https://github.com/WecoAI/weco-cli.git cd weco-cli
-
Install Development Dependencies:
pip install -e ".[dev]"
-
Create a Feature Branch:
git checkout -b feature/your-feature-name
-
Make Your Changes: Ensure your code adheres to our style guidelines and includes relevant tests.
-
Commit and Push your changes, then open a pull request with a clear description of your enhancements.