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
[](https://colab.research.google.com/github/WecoAI/weco-cli/blob/main/examples/hello-kernel-world/colab_notebook_walkthrough.ipynb)
--additional-instructions "Fuse operations in the forward method while ensuring the max float deviation remains small. Maintain the same format of the code."
82
84
```
83
85
84
86
**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`.
|`--source`| Path to the source code file that will be optimized (e.g., `optimize.py`). | Yes |
93
-
|`--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 |
94
-
|`--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 |
95
-
| `--maximize` | Whether to maximize (`true`) or minimize (`false`) the metric. | Yes |
96
-
| `--steps` | Number of optimization steps (LLM iterations) to run. | Yes |
97
-
| `--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 |
98
-
| `--additional-instructions` | (Optional) Natural language description of specific instructions OR path to a file containing detailed instructions to guide the LLM. | No |
99
-
| `--log-dir` | (Optional) Path to the directory to log intermediate steps and final optimization result. Defaults to `.runs/`. | No |
|`-s, --source`| Path to the source code file that will be optimized (e.g., `optimize.py`). |
97
+
|`-c, --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. |
98
+
|`-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`. |
99
+
| `-g, --goal` | `maximize`/`max` to maximize the `--metric` or `minimize`/`min` to minimize it. |
| `-n, --steps` | Number of optimization steps (LLM iterations) to run. | 100 |
108
+
| `-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`). |
109
+
| `-i, --additional-instructions`| Natural language description of specific instructions **or** path to a file containing detailed instructions to guide the LLM. | `None` |
110
+
| `-l, --log-dir` | Path to the directory to log intermediate steps and final optimization result. | `.runs/` |
*`--source optimize.py`: The initial PyTorch self-attention code to be optimized with CUDA.
33
33
*`--eval-command "python evaluate.py --solution-path optimize.py"`: Runs the evaluation script, which compiles (if necessary) and benchmarks the CUDA-enhanced code in`optimize.py` against a baseline, printing the `speedup`.
34
34
*`--metric speedup`: The optimization target metric.
35
-
*`--maximize true`: Weco aims to increase the speedup.
35
+
*`--goal maximize`: Weco aims to increase the speedup.
36
36
*`--steps 30`: The number of optimization iterations.
37
37
*`--model gemini-2.5-pro-exp-03-25`: The LLM used for code generation.
38
38
*`--additional-instructions guide.md`: Points Weco to a file containing detailed instructions for the LLM on how to write the CUDA kernels, handle compilation (e.g., using `torch.utils.cpp_extension`), manage data types, and ensure correctness.
"Real-world code is often more complex but this is a good place to start. You can find more advanced examples [here](https://docs.weco.ai/examples), however, we'd recommend starting with this notebook as the optimization setup is the exact same, no matter the complexity!"
213
+
],
214
+
"metadata": {
215
+
"id": "5C5dvasXdmNw"
216
+
}
217
+
},
218
+
{
219
+
"cell_type": "markdown",
220
+
"source": [
221
+
"It's simple to start optimizing any piece of code! You just need to set:\n",
222
+
"1. Path to source code - we can point this to our `optimize.py`\n",
223
+
"2. Command to run evaluation - notice how we are using the `DEVICE` we setup earlier\n",
224
+
"3. The metric we are optimizing for - in this case, the evaluation script (`evaluate.py`) prints the `'speedup'` achieved to the terminal\n",
225
+
"4. Whether you want to maximize or minimize the metric you mentioned above - in our case, we want to make this code faster!\n",
226
+
"5. Number of steps to optimize for - we'll keep it low to avoid any rate limits being hit on your free Gemini API key\n",
227
+
"6. Additional context - anything information you think should guide the optimization process"
228
+
],
229
+
"metadata": {
230
+
"id": "YfDg-pP9fAdC"
231
+
}
232
+
},
233
+
{
234
+
"cell_type": "markdown",
235
+
"source": [
236
+
"Now let's get straight into it. Keep an eye on the `Best Solution` panel!\n",
237
+
"\n",
238
+
"Note that you can track the optimization in the logs directory (`.runs/`) and on our dashboard (links shown in the `Summary` panel)."
239
+
],
240
+
"metadata": {
241
+
"id": "TbG_3nwEhs5G"
242
+
}
243
+
},
244
+
{
245
+
"cell_type": "code",
246
+
"source": [
247
+
"import sys, weco.cli as weco_cli\n",
248
+
"\n",
249
+
"# When running in a terminal, you can use this instead:\n",
0 commit comments