Skip to content
FunCoding

benchmark-pair-authoring

Author or repair baseline/optimized benchmark pairs, CUDA binary benchmarks, and multi-GPU torchrun benchmarks in this repository. Use when creating or fixing `baseline_*.py` / `optimized_*.py` modules, `VerificationPayloadMixin` contracts, deterministic seeding, tolerances, or benchmark linter errors.

Star
2,262
License
Apache-2.0
Last commit
Dec 1, 2026

.agents/skills/benchmark-pair-authoring/SKILL.md

View on GitHub

Benchmark Pair Authoring

Use this skill when writing or repairing a chapter or lab benchmark pair under code/.

Required benchmark structure

  1. Expose a top-level get_benchmark() -> BaseBenchmark factory. Do not add a if __name__ == "__main__": runner to discoverable benchmark modules.
  2. Subclass VerificationPayloadMixin and BaseBenchmark (or CudaBinaryBenchmark for compiled native binaries).
  3. Put allocations, random input generation, model initialization, compilation, and graph capture in setup(), never inside benchmark_fn().
  4. Keep benchmark_fn() free of .item(), .cpu(), .numpy(), .tolist(), ad-hoc logging, or host transfers unless the benchmark explicitly measures them.
  5. Capture the real timed output in capture_verification_payload() via self._set_verification_payload(inputs=..., output=..., batch_size=..., parameter_count=..., precision_flags=..., output_tolerance=(rtol, atol)).

Deterministic seeding and equivalent workloads

  • Both baseline and optimized must execute the same mathematical workload on the same logical inputs, shapes, dtypes, and sequence/batch dimensions.
  • Respect the harness verification seed (resolve_verification_input_seed() / caller seeding) so VerifyRunner can run identical inputs, jitter checks, and fresh-input checks cleanly. Avoid hardcoding torch.manual_seed(42) in helper builders that ignore the harness seed.
  • Warmup must leave both arms with identical starting state. If a training or stateful workload mutates weights or KV caches, restore the shared start state before timing.
  • Never cheat verification with checksums, constants, cached setup outputs, reduced work (such as shrinking vocab or skipping layers), or silent fallbacks under the same benchmark name.

Discriminating output tolerances

VerifyRunner rejects tolerances that admit an all-zero output or a half-scale output. Choose the tightest mathematically justified (rtol, atol) for the output dtype and magnitude:

  • Exact integer or discrete outputs: (0.0, 0.0)
  • FP32 mathematically equivalent ops: (1e-4, 1e-4) to (1e-3, 1e-3)
  • FP16 / BF16 matrix multiplies or attention: (1e-2, 1e-2) or (2e-2, 1e-2), scaled strictly below output magnitude so zero and half-scale outputs always fail. Initialize inputs at realistic O(1) LayerNorm/RMSNorm scale rather than shrinking them (shrunk inputs produce tiny SwiGLU/MLP outputs near atol that trigger VerifyRunner's zero-admission rejection). When baseline and optimized run identical BF16/FP16 math across different stream schedules, tighten to (1e-3, 1e-3).
  • FP8 / NVFP4 quantized paths: measure actual baseline vs optimized error on target hardware and set a discriminating tolerance backed by that measurement

Multi-GPU, planner-tool boundaries, and capability skips

  • Distributed multi-GPU benchmarks implement get_torchrun_spec(config) returning a TorchrunLaunchSpec and consume real rank receipts.
  • Single-process multi-GPU NVLink P2P overlap benchmarks set multi_gpu_required = True, call require_min_gpus(2, ...), allow explicit end-of-step multi-GPU sync via allowed_benchmark_fn_antipatterns = ("sync",), seed inputs deterministically on cuda:0 before transferring peer shards so both arms receive identical hashes, gather all ranks' outputs onto cuda:0 in capture_verification_payload(), and keep cross-rank event waits symmetric between baseline and optimized.
  • Keep tool-only planner labs (such as labs/moe_parallelism, where list-targets intentionally returns empty) free of baseline_*.py / optimized_*.py pairs. Put empirical GPU benchmarks in the companion CUDA lab (such as labs/moe_cuda) and cross-link both READMEs. In PlanEvaluator.analyze(), preserve raw un-overlapped collective times (ep_time_ms) for invariant tests and model schedule overlap (such as DualPipeV) separately via exposed_ep_time_ms inside estimated_step_ms.
  • Missing required hardware or software features must raise RuntimeError("SKIPPED: <clear reason>") (note the exact SKIPPED: prefix so the harness classifies the capability skip cleanly instead of failing or falling back).

Required checks before finishing

cd code
python -m core.scripts.linting.check_benchmarks --include-unpaired --fail-on-warnings
python -m pytest -q tests/test_get_benchmark_presence.py
python -m cli.aisp bench verify --targets <chapter_or_lab>:<example>

Similar Skills

rea-analysis-optimization

MOmorluto/rea485k7,690 new stars in the last 7 days

codebase-design

MAmattpocock/skills336k4,217 new stars in the last 7 days

Featured

diagnosing-bugs

Diagnose hard bugs and performance regressions by building a feedback loop with tests or scripts.

MAmattpocock/skills336k4,217 new stars in the last 7 days

setup-ts-deep-modules

MAmattpocock/skills336k4,217 new stars in the last 7 days

code-review

MAmattpocock/skills336k4,217 new stars in the last 7 days

implement

MAmattpocock/skills336k4,217 new stars in the last 7 days