Repository navigation
bench: --candidate chooses between implementations of an op in the real graph - #145
Conversation
…al graph An op is an interface and an implementation, so which kernel runs, at which launch geometry, for which batch size is a question about one op, and every answer is a manifest that differs in that op's `impl`. A candidate is such an answer as a file: `modules` and `ops`, nothing else. A kernel in another language, the same cubin at another grid and the same grid over another cubin are all candidates; tuning geometry needs no syntax of its own. kern-manifest gains `candidate`: `splice` puts a candidate into a verified manifest (the interface is checked, modules travel with their launches, the result is verified again), and `tile` assembles one implementation from several, each under `when` in its own range of a var. `kern bench --candidate <file|dir>` runs the manifest, every candidate spliced into it, and the manifest again over the same workload in one process, weights resident from one to the next. A candidate is held to the manifest's outputs scenario by scenario (tokens, counts and every row of every distribution over tokens the program writes) and is chosen from only where it is identical or within kern test's KL limit. Per op, the pick is the tiling of fewest ranges whose cost is within the noise of choosing per value, the noise being what the manifest's two runs disagree by. The picked manifest is then run and held to the same outputs; if a combination of merely-within candidates does not hold, the choice is made again from the identical alone. The report carries every run and the pick as a candidate file. `Bench::load` goes through `load_ranks`, so bench no longer has a loader of its own. Measured on one GB300 (2026-11-18, software timestamps), Qwen3.8-27B FP8 over the 57 round scenarios of its served trace, five W8A16 GEMM ops: from one 64-row tile for every batch the pick tiles `tokens` in four to five ranges, 2220.7 -> 2037.6 s measured against 2039.9 predicted (the kernel's author had 2039.7 by hand); against the served Triton GEMM a CuTe DSL kernel is within the limit in 53 of 57 scenarios and is taken where it held everywhere, 2753.0 -> 2391.1 s against 2392.7 predicted. A candidate that runs nothing outside one range holds only there, one that does not reproduce its own tokens is reported failed, and a pick fed back as the only candidate comes out byte for byte. Signed-off-by: JinYan Su <751080330@qq.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a13876cee0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| rows: rows.len(), | ||
| rows_differ: rows.iter().filter(|l| l.cmp.n_diff > 0).count(), | ||
| kl_sum: rows.iter().map(|l| l.kl).sum(), | ||
| kl_max: rows.iter().map(|l| l.kl).fold(0., f64::max), |
There was a problem hiding this comment.
Reject non-finite KL values before computing the maximum
If a candidate produces NaNs or infinities in a logits row, Runtime::logits can return a NaN KL value. f64::max ignores NaNs, so this fold can report kl_max == 0 even when every compared row has invalid numerics. Judged::verdict then admits the candidate as Within, and confirmation repeats the same check, allowing a numerically broken implementation to be exported. Reject non-finite KL values and one-sided NaNs before aggregation, as kern_test::compare::LogitStats::from_device already does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 98291b7. A row's KL is read as kern test reads it: infinite when it is not finite or one side has a NaN the other has not, so the maximum, the mean and the flips beyond the limit all see it.
| j if j.outputs_differ == 0 && j.rows_differ == 0 => Verdict::Identical, | ||
| j if j.rows > 0 && j.kl_max <= LOGIT_KL => Verdict::Within, |
There was a problem hiding this comment.
Validate output differences independently of logits proximity
For a candidate replacing sampling or speculative-acceptance logic, unchanged logits do not imply correct emitted tokens or counts. This branch accepts any output mismatch whenever some logits rows exist and their KL is small: a candidate can emit an arbitrary token or incorrect accepted-token count while leaving logits untouched, receive Within with KL zero, and pass confirmation. Require counts to agree and establish that any permitted token change actually corresponds to a near-tie in the relevant distribution rather than using unrelated logits proximity to waive all output differences. The GPU-oracle guidance in AGENTS.md specifically distinguishes near-tie flips from confidently wrong tokens.
AGENTS.md reference: AGENTS.md:L158-L161
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 98291b7. A scenario whose tokens or counts moved while no row changed its argmax now differs, whatever the KL: bench runs unsampled, so nothing the distributions show moved them. Outputs that moved are admitted only where some row flipped and every row is within the limit. In a speculative round a count moves with the token before it, so counts are held to the same rule and not to equality.
| let rt = &bench.ranks[0].rt; | ||
| let judged = match &self.kept { | ||
| None => { | ||
| now.push(keep(rt, &bench.protocol, s, &priced.vars)?); |
There was a problem hiding this comment.
Compare candidate outputs on every rank
For multi-rank workloads, Bench::scenario measures every rank and measure feeds each rank its own sequences and prose, but the baseline snapshots and candidate judgments here use only rank 0. A candidate that produces stable but incorrect outputs on another rank can therefore be admitted and exported whenever that error does not affect rank 0's observed buffers; the final confirmation has the same blind spot. Keep and judge each rank's outputs and distributions, then combine their verdicts before admitting a scenario.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 98291b7. Every rank keeps what the manifest handed back and is judged against it; a scenario's verdict is what any rank moved. Not exercised on a multi-rank manifest yet: the gate run is one GB300.
Three holes in the gate a candidate has to pass, from review. A row whose KL is not a number, or with a NaN on one side only, is infinitely far, as `kern test` reads it: `f64::max` skipped the NaN and left the row within the limit. Tokens or counts that moved in a scenario where no row changed its argmax differ, however close the distributions are: bench runs unsampled, so nothing the distributions show moved them, and the candidate changed what is done with them. Every rank keeps what the manifest handed back and is judged against it; a scenario is what any rank moved. Rank 0 alone stood for the group. Gate: the round workload against the served manifest on one GB300, 57 scenarios, verdicts unchanged scenario by scenario (the DSL kernel holds in 53, the hand-written one in 52, the control that runs nothing in 12), pick 2752.8 -> 2391.4 s measured against 2392.3 predicted. No multi-rank manifest was run. Signed-off-by: JinYan Su <751080330@qq.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A pick interpolates nothing: a value between two measured ones runs what the larger one runs. Leaving one measured row count out of the DSL tile pick and pricing it under whatever then covers it costs an op 6% to 82% more there than its best candidate, and the report said nothing. A `gap` line now follows a pick whose boundary falls between two measured values more than a doubling apart, and the pick's record carries the same. docs/bench.md says what a candidate replaces, the microbenchmark a kernel's author writes, and records what was measured of that: per call the graph's time is 0.96 to 1.06 of a careful standalone harness's over 25 op and row-count pairs, with no harness written. It also says what the tile example did not exercise: every boundary there is worth far more than the noise. Signed-off-by: JinYan Su <751080330@qq.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An op is an interface and an implementation, so "which kernel, at which launch geometry, for which batch size" is a question about one op, and every answer is a manifest that differs in that op's
impl. Today that answer is tuned by hand in a microbench outside the graph: a launcher for that kernel's parameter layout, inputs, weights the cache has not seen, a reference. This makes it akern benchrun, where the launcher is the runtime, the inputs and the cache are the program's own, and a candidate is a file with no code in it.What it adds
A candidate is a file with the
modulesandopssections of a manifest and nothing else. A kernel in another language, the same cubin at another grid, and the same grid over another cubin are all candidates; tuning geometry needs no syntax of its own, and a directory of files written by the kernel author's script is the sweep.kern_manifest::candidate(pure host code, property-tested):spliceputs a candidate into a verified manifest: params must equal the op's, modules travel with their launches (renamed after their hash on a name clash, pruned when nothing launches them), and the result is verified again.tileassembles one implementation from several, each underwhenin its own range of a var.kern bench --candidate <file|dir>:logits*buffer or any float buffer as wide as the token domain).identicalmay be chosen from, and so maywithin: every row within kern test's 0.01 nat, with tokens or counts moved only where some row changed its argmax. A row with a NaN on one side is infinitely far. Anything else is measured and reported, never chosen.bench::pick, property-tested against every tiling written out). The noise is what the manifest's own two runs disagree by. A boundary that falls between two measured values more than a doubling apart is named in agapline: the values between ran in no scenario.picked: the choice as a candidate file.Bench::loadnow goes throughload_ranks, so bench has no loader of its own. No schema change.Measured
One GB300, 2026-11-18, software timestamps. Qwen3.8-27B FP8 over the 57
roundscenarios of its served trace (73227 calls), five W8A16 GEMM ops.whentokensin 4–5 ranges, 2220.7 → 2037.6 s (predicted 2039.9). The kernel's author had 2039.7 s by handgapline is for.seqs3..4 holds in exactly the 12 scenarios there; a build missing a fence between its TMA writes and reads does not reproduce its own tokens, is reportedfailed, and the run goes on.What the gate cannot see
A program that drafts its own tokens feeds each row what the last one chose, so one tie that flips changes every row after it. A candidate that is not bit-identical seldom holds in every scenario of such a program (the third row above), and those are
kern test e2e-logits's to judge; once accepted, the kernel is the manifest and its variants are identical to it (the first two rows).docs/bench.mdsays this in the new Candidates section, with the limits: one var per op, values between measured ones follow the larger, and the manifest's distributions stay on the device for the run.Checked
cargo fmt --check,cargo clippy --workspace --exclude kern-py --all-targets -- -D warnings,cargo test --workspace --exclude kern-py, hawk's restricted-visibility rule, the schema golden and the protocol-names check pass locally.🤖 Generated with Claude Code