Download code/docs/METHOD.md from QianQu/CompoundingKernel-Explorer: direct link, hf CLI and curl.
- Browser
- Download file 11 kB
-
https://huggingface.co/spaces/QianQu/CompoundingKernel-Explorer/resolve/main/code/docs/METHOD.md
- Command line
-
hf download hf://spaces/QianQu/CompoundingKernel-Explorer/code/docs/METHOD.md
-
curl -L -o METHOD.md https://huggingface.co/spaces/QianQu/CompoundingKernel-Explorer/resolve/main/code/docs/METHOD.md
The method
CompoundingKernel searches for fast GPU kernels, one search per problem. This page explains the method in plain words, shows which file holds which part, and lists what we left out on purpose. The paper has the full story, the results and the A/B tests: arXiv 2611.19230.
The idea in five lines
- Every kernel that is measured goes into an archive, with its parent: the kernel it was built from.
- An LLM controller reads the archive and decides what to try next: which kernel to build on (or a new design), and one direction for each child.
- Child agents run in parallel, one per free GPU slot. Each child gets one parent and one direction, writes a kernel, and checks and times it with NVIDIA's public SOL-ExecBench harness.
- Checks outside the model decide what is correct. The model never grades its own work.
- The archive keeps every correct kernel. So a slower kernel can later be the parent of the fastest one: the gains compound.
The four loops
| loop | who | what happens | in this code |
|---|---|---|---|
| (1) child | a child agent | gets a parent and a direction, writes and times one kernel | child.py |
| (2) controller | the LLM controller | reads the archive, picks parents and directions, refills slots | controller.py |
| (3) team | helper agents, approved by people | fix faults in the tools; a fix goes live at a "warm restart" | not included |
| (4) outer | people | decide which kernels to send to the benchmark site, and when | not included |
A warm restart stops the agents, updates the tools and starts them again. The archives stay, so each search goes on where it stopped. Loops 1 and 2 ran without people, and scores from the benchmark site never entered them: the search learns only from its own tests and timings. (People set the number of child slots per run and added a few approved notes to some prompts; none of them held a score or a rank.) In the final run both loops used the same model, Claude Opus 5.5.
Loop 1: a child (child.py)
- A child is one Claude Agent SDK session. It gets the parent's files (or none, for a new design) and one direction.
- Its tools:
compile_check(build and run one small workload),evaluate_kernel(the full timed run),profile_kernel(Nsight Compute on one small workload),check_robustness,query_history(read-only SQL over its own run's archive) andget_solution(the code of a stored kernel). evaluate_kernelfirst runs a check that costs no GPU time (native code). Code that is unchanged after removing comments and spacing is not timed again: the earlier result comes back. Every timed candidate is stored in the archive with its parent.- "One candidate per child" is a soft rule:
evaluate_kernelreturnsstop: trueonce the child has its first correct kernel, and the child's prompt asks it to stop there. - The sessions run with all permissions granted and a short deny list (tools that end a turn to be woken later, or start work that is never waited for). Run them in a sandbox.
Loop 2: the controller (controller.py)
- One controller per problem. It has only two tools:
query_archive(sql): read-only SQL over its run's archive, including alineagetable with each kernel's subtree (its descendants, how many were correct, the best reward among them);expand(parent, directions): starts one child per direction on a free GPU slot, waits until a slot is free again, and reports what changed: finished and running children, free slots, new candidates with their notes, the minutes left, and flags on bests that failed a check.
- Slots are refilled as soon as children end, until the time limit or the budget is used up.
- The controller keeps no state of its own. It re-reads the archive, so a stopped search resumes.
- If the controller ends its turn while time is left, it gets a follow-up turn with the real clock (at most 20 such turns). A turn that ends on a server error is retried after a backoff and is not counted. When the controller is done, every running child still runs to its end.
- In the final run, the LLM controller chose the parents. The UCB-style tree (
run_tree) is in the code only because it was the A/B baseline (see below).
The archive (archive.py)
- One folder per run: an append-only
ledger.jsonl, one folder per candidate (solution.json,eval.json) and the session transcripts. - A candidate's files are written first and its ledger row last, so a row always points to complete files. The candidate id is a hash of the problem and the code, so a replay adds no copy.
archive.sqliteis a copy rebuilt from the ledger. Agents only read it: the connection is read-only and an SQLite authorizer refuses every write.- Tables:
candidates(one row per evaluated kernel, failed tries included, so agents can see dead ends),evaluation(one row per workload),lineage(each node's subtree). - A parent link must point to an earlier correct kernel of the same run, so the tree has no cycles.
- A correct kernel stays in the archive forever. If a later check fails it, it stops counting as a best, but its measured numbers never change.
Correct and fast (harness.py, score.py)
- Each evaluation runs NVIDIA's
sol-execbenchcommand once. Only the trace of this one call is read. - A kernel is correct only if every trace row passed and the rows match the problem's workloads exactly (one row per workload, no missing rows, no extra rows).
- A time below 0.1 microseconds is flagged and never counts (so is a time below the speed-of-light bound, when you pass the published times).
- One timed run per GPU at a time: a file lock per GPU.
- The SOL score of one workload is
S = (t_b - t_sol) / ((t_k - t_sol) + (t_b - t_sol)): 0.5 at the benchmark's baseline, 1.0 at the bound. A problem's score is the mean over its workloads. - The reward is the geometric-mean speedup
t_b / t_kover the workloads, from our own timings. The publishedt_bandt_solare NVIDIA's data and are not included. You can pass your own copy (harness.anchors); without it, the code ranks by the reference time the harness can measure, or by latency. For correct kernels the three rank kernels alike (the measured reference time adds some noise).
Checks outside the model (checks/)
| check | what it catches | where it ran in the final run |
|---|---|---|
correctness (harness.py) |
a failed workload, a partial run, an impossible time | every evaluation |
native_code.py |
native code built or loaded at run time, or processes started | every evaluation; such a kernel never counts (here: refused before any GPU time, plus a guard in the eval process) |
precision.py |
math below the problem's declared data types | every evaluation (decides whether a kernel counts) |
robustness.py |
failures on new valid shapes, and on special input values | each new best of a run (automatic), or when a child asks |
sanitizer.py |
memory errors and races (compute-sanitizer memcheck and racecheck) | new bests with a large gain (here: every new best, if switched on) |
Several of these checks were added during the run, at warm restarts, often after the search found a reward hack that the earlier checks missed. The paper's harness timeline says when each one went live.
- Robustness. New shapes come from the shipped workloads: values no workload used, one axis above its largest value (up to 2x), boundary mixes and new mixes, all valid and under a size cap. Special values (tiny, alternating sign, constant) run on the smallest shape. A case where the reference code itself fails is no evidence and is left out. Only ROBUST passes.
- Precision. On an fp32 problem, reduced precision (TF32, fp16 or bf16 math, lower formats, or fp32 emulation) counts only once the robustness check says ROBUST. On a bf16 or fp16 problem, going below the declared type is never allowed. Quantization problems are exempt.
The tree baseline (A/B only)
For the A/B test we also ran a coded tree with no LLM in the loop that picks the parents: each
round it scores every live node with reward / best + c * sqrt(ln(|A| + 1) / (children + 1)),
expands the top nodes with children that get no direction, and prunes nodes that stay far below
the best. The paper reports that, at equal wall time, the LLM controller beat this tree on 35 of
38 problems, mainly because it made more correct attempts. select_tree and prune_tree are in
archive.py, run_tree in controller.py; the settings are in examples/example_config.yaml.
Which file shows which part
| part of the method | file |
|---|---|
| the controller loop, its two tools, slot refill, follow-up turns | compoundingkernel/controller.py |
| one child session and its tools | compoundingkernel/child.py |
| the archive, lineage, read-only SQL, the tree's UCB pick | compoundingkernel/archive.py |
| the SOL-ExecBench interface, correctness, "unchanged code" key | compoundingkernel/harness.py |
| the SOL score, the speedup, the reward | compoundingkernel/score.py |
| the checks | compoundingkernel/checks/ |
| prompt slots (placeholders) and the default settings | compoundingkernel/__init__.py |
| the settings of one search | examples/example_config.yaml |
What is left out on purpose
- Our prompts. Every model-facing text is left out: the controller's and the children's
prompts, the first and follow-up turns, the tool descriptions, and the notes our tools added to
their results. In this code
load_prompt()returns"<prompt not released>". Tool results here carry only codes and numbers. You can pointprompts.prompt_dirto your own files (PROMPT_SLOTSlists the slots and the fields each one is given). - Our infrastructure. Remote GPU hosts and how we reached them, cluster scheduling, shared storage and backups, our model-access setup, monitoring pages, chat alerts and analytics exports. This code runs on one machine with local GPUs and keeps everything in a local folder.
- Checks that ran only before a send to the benchmark site. A robustness re-check with many seeds, checks that the outputs are really written on every call, checks of the outputs of the timed calls, a build-time check, a rehearsal of the site's own evaluation, one review per send, and a daily audit of the agents' shell commands. Some of these were added during the run, so not every kernel went through all of them.
- Switches added during the run. For example ways to fill idle slots, to steer stuck runs and to share designs between runs. The paper describes the main ones.
- The calibration of our local timings to the site's clock. People did this outside the search.
- The benchmark itself. No problem definitions, workloads, reference code or published times. The checks only read your own copy, at run time. Get SOL-ExecBench from NVIDIA.