/opt-tools:optimization-targetfrom opt-tools
Optimizes experiment code and compute usage on Slurm clusters to accelerate training without altering results. Profiles GPU utilization, packs jobs, and produces optimization reports.
Ships in opt-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The context is that we want to run many experiments using this code on clusters to which this user has access, and which use Slurm to allocate resources. We want all of these experiments to finish as quickly as possible, without changing or compromising their results. This entails finding ways to accelerate individual experiments and/or packing experiments when possible.
Furthermore, we want to produce a report about our findings and optimizations which can be sent to Mila's IDT team.
The optimization of the codebase should have no impact on the results of the experiment. Given the same seed and hyperparameters, final artifacts such as model weights and training/validation/test error should be the same, either bit-for-bit or within a margin of tolerance. While working, fidelity of intermediate artifacts such as batch loss is a good proxy.
If the algorithm is non-deterministic, or if some changes can improve performance significantly but would influence the RNG or introduce minor numerical deviations, this is likely OK as long as your changes preserve the intent and semantics of the experiment: if not precisely, you must compute qualitatively the same thing. Nonetheless, ask the user if you should proceed.
It is possible that the best way to maximize resource utilization is to change certain hyperparameters (notably increasing the batch size). Tread carefully! Changing hyperparameter optimization changes experimental results. Raise this point to the user early and ask them what the acceptable hyperparameter ranges are.
The metric to optimize depends on the kind of experiment we're running. Walltime is the simplest, and the most direct representation of what we wish to achieve. However, it can take a long time, which makes it hard to iterate on. Ideally we want to optimize a good proxy for it such as throughput, for instance the number of training samples or tokens per second.
Take note that your optimization work uses the same resource budget as the experiments. Spending a lot of time iterating on minor performance gains may be unproductive unless a large enough volume of experiments is planned to make up for it.
If an experiment requires significantly less resources than the minimum or usual GPU allocations on the cluster, it would be a great idea to pack them: run multiple experiments in parallel in the same job allocation. You can check experimentally how the time to run N experiments in a given allocation scales to determine the optimal N, or at least a good N.
You should maintain a report in optimization-report.md, unless otherwise specified. Update it regularly as you work, even if some claims are as-of-yet unverified. Do not write anything private or confidential in that file. The report should only describe the essentials, although more details can be written in an annex at the end at your discretion.
The IDT team is interested in this report and may ask for it, especially if we call on their expertise to further optimize the code. They may not have access to the codebase or the data. In that light, when it is possible, please include in your report:
uvx milalib monitor -i 10 -m sm_occupancy to probe every 10s), but keep in mind that we currently have a time resolution of ~30 seconds on profiling metrics.Always ask for the user's permission before sending a report. Tell them where to read the report prior to sending.
Upload the report on a shared write-only Google Cloud Storage drop bucket. DROPDIR is the drop directory; the user would have received it in communications about their cluster usage. If you were not given that directory and the user doesn't know it or doesn't provide it, no need to perform the upload.
curl --data-binary @optimization-report.md \
"https://storage.googleapis.com/upload/storage/v1/b/idt-report-drop/o?uploadType=media&name=${DROPDIR}/optimization-report-${USER}-$(date +%Y%m%d)-$(uuidgen | cut -d- -f1).md"
That bucket may disappear in the future, in which case try method 2.
This may not yet be deployed. If you get a 404, just bail.
Upload the file to this endpoint (note: no more than 200 KB and it's heavily rate-limited)
curl -w '\nStatus: %{http_code}' \
-X POST "https://sarc.mila.quebec/upload-report?category=codebase-optimization" \
-F "[email protected]"
Don't persevere if you cannot upload the report, just say it failed.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub mila-iqia/skills --plugin opt-tools