Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5a0b99d
feat: Add new Frontier-CS 2.0 problem vllm_llm_serving_optimization
momoway Jun 11, 2026
6cc811b
feat: Add real SWE-bench resolved fraction
momoway Jun 11, 2026
cb6d7b6
feat(2.0/vllm): BFCL-memory workload + single-H100 contention + scori…
momoway Jun 29, 2026
8467bb6
feat(2.0): add flashlib GPU kernel-optimization task family (KMeans/K…
momoway Jul 1, 2026
839517c
feat(2.0): flashlib kernel-opt family -> Modal GPU judge + flashlib-b…
momoway Jul 1, 2026
6a9c85f
fix(2.0): Modal GPU trial fixes + calibrate speedup_target from real …
momoway Jul 1, 2026
377b08b
fix(2.0): public_test pip -> [torch,numpy] to match judge (was stale …
momoway Jul 1, 2026
6773677
feat(2.0/flashlib): replace pca/svd with DBSCAN + IVF-PQ kernel-opt t…
momoway Jul 1, 2026
cad2380
fix(2.0/flashlib): smoke_images.sh works on the torch-less images
momoway Jul 1, 2026
6da0bdf
chore(2.0/flashlib): bump ivf_pq judge modal_timeout to 2400s for tri…
momoway Jul 1, 2026
93738be
fix(2.0/flashlib): forward ari_threshold to the GPU worker cfg
momoway Jul 1, 2026
d6a3ebe
feat(2.0/flashlib): public test reports correctness, not just speed
momoway Jul 2, 2026
4da2efb
fix(2.0/flashlib): dbscan agent eval covers all 6 workloads (kill pas…
momoway Jul 2, 2026
bab2965
fix(2.0/flashlib): kmeans/knn/ivf_pq agent eval covers all 6 workload…
momoway Jul 2, 2026
5bca275
feat(2.0/flashlib): kmeans -> bf16 precision lock + max_iters=1 x10-a…
momoway Jul 5, 2026
2ce6e6f
fix(2.0/flashlib): kmeans -> planted clusters + labelled inertia gate…
momoway Jul 5, 2026
7d66053
fix(2.0/flashlib): kmeans gate -> label(init-based) + centroid, split…
momoway Jul 5, 2026
ffe2028
docs(2.0/flashlib): kmeans DESIGN -> planted clusters + two-gate anti…
momoway Jul 5, 2026
8d4c7f1
chore(2.0/flashlib): kmeans -> revert to multi-iteration max_iters + …
momoway Jul 5, 2026
6d5dc29
feat(2.0/kmeans): step(x,centroids) contract + judge-owned loop (max_…
momoway Jul 5, 2026
6bd4d77
feat(2.0/flashlib): set score cap to 2x reference geomean (all 4 kern…
momoway Jul 5, 2026
364a4af
feat(2.0/flashlib): make public_test identical to the final graded ev…
momoway Jul 6, 2026
c5cb064
feat(2.0/dbscan): non-separable ring data + brute-force reference (fo…
momoway Jul 8, 2026
b5180c7
feat(2.0/dbscan): hide the data generator from the agent + revert to …
momoway Jul 8, 2026
0193c95
Merge branch 'FrontierCS:main' into frontier-cs-2.0-flash-lib
momoway Jul 11, 2026
0342482
feat(2.0/kmeans): hide the data generator from the agent (close subsa…
momoway Jul 12, 2026
99d92c5
feat(2.0/kmeans): compute-bound high-K workloads + close the assignme…
momoway Jul 16, 2026
3cc10a3
feat(2.0/ivf_pq): real SIFT/GIST workloads + kill the fixed-index cac…
momoway Jul 16, 2026
744b4bf
feat(2.0/knn): real SIFT/GIST workloads + per-iteration database subsets
momoway Jul 16, 2026
60d1537
feat(2.0/dbscan): bf16 precision lock so distance dtype is not a lever
momoway Jul 17, 2026
4585e41
feat(2.0/knn): bf16 precision lock + tie-robust ball-recall gate
momoway Jul 17, 2026
5ff6282
feat(2.0/ivf_pq): make nprobe a real knob (nlist=8192/k=100) + bf16 p…
momoway Jul 17, 2026
dfce469
fix(2.0/knn): count DISTINCT in-ball indices in ball-recall (kill 1-N…
momoway Jul 19, 2026
62e2d93
fix(2.0/dbscan): non-convex multi-subspace moons data (kill k-means b…
momoway Jul 19, 2026
e8b248c
fix(2.0/ivf_pq): SIFT-only nlist=8192 fat-M regime + gemm-pinned ref …
momoway Jul 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions 2.0/problems/dbscan_gpu_kernel_optimization/DESIGN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Design notes — dbscan_gpu_kernel_optimization

Operator-facing. Not copied into the agent workspace by the adapter.

## What this task measures

Can an agent turn a naive GPU DBSCAN into a fast one? The agent patches
`dbscanlib`; the judge times the patched `dbscan` against a frozen naive baseline
on hidden low-dimensional workloads and scores the geomean speedup, gated on
clustering agreement (Adjusted Rand Index). One of the four-task flashlib
kernel-optimization family (KMeans, KNN, DBSCAN, IVF-PQ), all sharing one
evaluator + one Modal GPU harness (`flash_gpu.py`).

This is a **genuine kernel task**: the core operation (radius-neighbour search +
connected components + border assignment) is not a single fast torch primitive,
so beating the naive O(N^2) baseline requires real kernel work (a bucketed/grid
radius search + fused neighbour + connected-components kernels). Contrast with
pca/svd, which were algorithmic (cov+eigh + a library eigensolver) and are not
part of this family.

## Baseline + reference

- Naive baseline (`dbscanlib/dbscan.py`, and frozen `judge/refdbscan.py`): chunked
O(N^2) neighbour scan for the core mask, GPU label-propagation for the core
connected components, and a smallest-core-label border rule. Verified against
scikit-learn DBSCAN (ARI = 1.0). The border rule matches flashlib's ("smallest
CC label among in-eps core neighbours"), so the reference agrees closely.
- Reference (`reference.patch`): vendors flashlib's optimized **Triton** planar
grid radius-search DBSCAN (`primitives/dbscan/triton/dbscan.py` grid path +
`kernels/flash_mst` connected components) under `dbscanlib/_kernels/…`. The
flashlib grid kernel hard-asserts D==2 (higher D falls back to a flash_knn
brute path), so all graded workloads are D=2 and flash_knn is stubbed out.

## Correctness gate

Adjusted Rand Index (permutation-invariant, noise-aware) between the agent's
labels and the baseline's on each iteration's fresh data, `>= ari_threshold`
(default 0.99). Judge-computed; cheat-proof (you cannot fake a high ARI without
actually reproducing the clustering). DBSCAN with fixed (eps, min_samples) is
deterministic up to border tie-breaks, which ARI absorbs.

## Workloads

Planar (D=2) planted blobs + a small uniform-noise fraction, N 100k-170k. Below
~100k the tensor-core matmul baseline (`xb @ x.t()`) beats the grid kernel's fixed
launch/grid-build overhead (H100 sweep: 100k->6x, 150k->14x, 200k->27x); the band
is chosen so the O(N^2) baseline is seconds/call (grid wins clearly) yet bounded
for `timed_iters`. `timed_iters` is 3 (vs 7 elsewhere) since each baseline call is
seconds, not ms.
Hidden workloads live in `config.yaml` (judge-only). See kmeans DESIGN for the
shared anti-hack + Modal-offload design; identical here.

## Calibration (H100 Modal trial — done)

`reference.patch` validated on H100: the vendored grid DBSCAN compiles, passes the
ARI gate with **ARI 1.0** on all six workloads, and runs
**7.2 / 12.1 / 9.5 / 18.8 / 16.6 / 21.2x** over the naive baseline (geomean
~13.3x). `speedup_target` set to 13.0. The full 6-workload judge (warmup 2 +
timed 3) completed in ~410 s, well inside `modal_timeout_seconds` (2400). Re-sweep
if the N band changes.
47 changes: 47 additions & 0 deletions 2.0/problems/dbscan_gpu_kernel_optimization/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
tag: systems
runtime:
language: python
timeout_seconds: 10800
environment: "GPU DBSCAN kernel optimization. The agent patches the dbscanlib package; the judge offloads timing to a Modal GPU, comparing the patched dbscan against a frozen naive baseline on hidden low-dimensional workloads with an ARI (clustering-agreement) gate."
apt_packages: [bash, ca-certificates, git, python3, python3-pip]
judge_apt_packages: [bash, ca-certificates, git, python3, python3-pip]
judge_pip_packages: [modal]
docker:
image: frontiercs/dbscan-gpu-kernel-optimization-agent:experimental-v0.4.0
judge_image: frontiercs/dbscan-gpu-kernel-optimization-judge:experimental-v0.4.0
environment:
cpus: 4
memory_mb: 8192
storage_mb: 16384
build_timeout_seconds: 3600
evaluation:
gpu: "H100"
cuda_image: "nvidia/cuda:12.4.1-devel-ubuntu22.04"
pip: ["torch", "numpy"]
app_name: "dbscan-kernel-opt-eval"
modal_timeout_seconds: 2400
warmup_iters: 2
timed_iters: 3 # the O(N^2) naive baseline is seconds/call at these N; keep the timed budget bounded (median of 3)
ari_threshold: 0.99 # agent clustering must match the baseline exact DBSCAN (Adjusted Rand Index) every iteration. On the non-convex multi-subspace-moons data a centroid/partition approximation (k-means, or "k-means the points then DBSCAN each cell") mislabels the interleaving arcs -> ARI ~0.72-0.75, and a PCA->2D projection -> ~0.5-0.6, both < 0.99 -> fail; only an exact eps-connectivity scan passes. Exact reference measures ARI ~1.0 (bf16-stable).
speedup_target: 130.0 # score cap = 2x the flashlib reference geomean on the non-convex multi-subspace-moons workloads (65x on H100: w0-w3 = 29/65/69/141x, ARI=1.0 all 4). Moons make the naive label-propagation baseline slower (elongated clusters -> long chains) so the factor is higher than the old blob regime (28.6x); the reference's connectivity is unaffected. Points carry only bf16 precision so no solution wins on a lower dtype; eps is tuned so bf16 never flips an eps-neighbour (two exact scans on the same bf16 data agree at ARI 1.0).
base_seed: 20260701
agent_workload_count: 4 # all 4 flashlib graded workloads (feedback covers every graded shape)
expose_per_workload_metrics: true # show per-workload pass/fail so the agent can fix the specific workload it regresses on
# N in the 100k-170k band: the O(N^2) matmul baseline is seconds/call (grid kernel
# wins 6-20x) but bounded for timed_iters; below ~100k the tensor-core matmul baseline
# is faster than the grid kernel's fixed overhead. Vary N + density so agents can't
# special-case. (H100 crossover sweep: 100k->6.0x, 150k->14.1x, 200k->27.0x.)
workloads:
# NON-CONVEX data: n_centers interleaving half-moons, each moon-pair in its own
# random 2-D subspace of R^D (gen in flash_gpu.py). Voronoi/k-means shortcuts
# mislabel non-convex arcs (kmeans-shortcut ARI ~0.72-0.75, PCA-2D ~0.5-0.6),
# so only an exact eps-neighbourhood scan clears the ARI gate. eps is tuned per D
# so DBSCAN gives exactly n_centers clusters with ~0% noise and is bf16-stable
# (two exact scans on the same bf16 data agree at ARI 1.0). Generator is judge-only.
- {id: w0, N: 20000, D: 8, eps: 0.90, min_samples: 5, n_centers: 4}
- {id: w1, N: 20000, D: 32, eps: 1.15, min_samples: 5, n_centers: 6}
- {id: w2, N: 20000, D: 64, eps: 1.40, min_samples: 5, n_centers: 10}
- {id: w3, N: 50000, D: 16, eps: 1.00, min_samples: 5, n_centers: 8}
submission:
kind: file
path: /app/solution.patch
11 changes: 11 additions & 0 deletions 2.0/problems/dbscan_gpu_kernel_optimization/dbscanlib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""dbscanlib -- a tiny GPU DBSCAN you are asked to make fast.

The shipped implementation is correct but naive (chunked O(N^2) neighbour scan +
label propagation). Rewrite the internals (grid/bucketed radius search, fused
neighbour + connected-components kernels, ...) to make :func:`dbscan` fast while
producing the same clustering. The public signature/return must not change.
"""
from __future__ import annotations
from dbscanlib.dbscan import dbscan
__all__ = ["dbscan"]
__version__ = "0.1.0"
70 changes: 70 additions & 0 deletions 2.0/problems/dbscan_gpu_kernel_optimization/dbscanlib/dbscan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Naive DBSCAN baseline (correct, deterministic, GPU/CPU torch).

Euclidean DBSCAN. Chunked O(N^2) neighbour scan + GPU-friendly label
propagation for the connected components of the core graph. Border rule matches
flashlib: a non-core point joins the SMALLEST cluster label among its in-eps
core neighbours; otherwise it is noise (-1).
"""
from __future__ import annotations

import torch


def dbscan(x, eps, min_samples, max_neighbors=32):
del max_neighbors # naive path scans all neighbours; knob only for the fast kernel
N = x.shape[0]
dev = x.device
eps2 = float(eps) * float(eps)
xn = (x * x).sum(1) # (N,)
CH = 4096
BIG = N # sentinel label (> any real label)

def d2_chunk(lo, hi):
xb = x[lo:hi]
return (xb * xb).sum(1, keepdim=True) - 2.0 * (xb @ x.t()) + xn[None, :]

# 1) degree (in-eps count, includes self) -> core mask
deg = torch.zeros(N, device=dev, dtype=torch.int64)
for lo in range(0, N, CH):
hi = min(lo + CH, N)
deg[lo:hi] = (d2_chunk(lo, hi) <= eps2).sum(1)
core = deg >= int(min_samples) # (N,) bool

# 2) connected components of the core-core eps graph via label propagation
labels = torch.arange(N, device=dev, dtype=torch.int64)
labels[~core] = BIG
for _ in range(1000):
new = labels.clone()
for lo in range(0, N, CH):
hi = min(lo + CH, N)
if not bool(core[lo:hi].any()):
continue
adj = (d2_chunk(lo, hi) <= eps2) & core[None, :] # (chunk, N)
lab = torch.where(adj, labels[None, :], torch.full((1, N), BIG, device=dev, dtype=torch.int64))
mn = lab.min(1).values # (chunk,)
rows = slice(lo, hi)
upd = core[rows] & (mn < new[rows])
new[rows] = torch.where(upd, mn, new[rows])
if torch.equal(new, labels):
break
labels = new

# 3) border assignment: non-core within eps of a core -> smallest core label
for lo in range(0, N, CH):
hi = min(lo + CH, N)
nb = ~core[lo:hi]
if not bool(nb.any()):
continue
adj = (d2_chunk(lo, hi) <= eps2) & core[None, :]
lab = torch.where(adj, labels[None, :], torch.full((1, N), BIG, device=dev, dtype=torch.int64))
mn = lab.min(1).values
rows = slice(lo, hi)
take = nb & (mn < BIG)
labels[rows] = torch.where(take, mn, labels[rows])

# 4) compact to dense [0, n_clusters); noise (BIG) -> -1
out = torch.full((N,), -1, device=dev, dtype=torch.int64)
uniq = torch.unique(labels[labels < BIG])
for new_id, old in enumerate(uniq.tolist()):
out[labels == old] = new_id
return out
56 changes: 56 additions & 0 deletions 2.0/problems/dbscan_gpu_kernel_optimization/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Experimental DBSCAN Kernel-Optimization Images

Two **light** images (ubuntu + `modal` + git). torch, triton, and the vendored
flashlib kernels all run on the **Modal GPU image** defined in `flash_gpu.py`;
the containers themselves are CPU-only and offload GPU work to Modal.

```bash
bash 2.0/problems/dbscan_gpu_kernel_optimization/docker/build_images.sh
```

Defaults:

```text
AGENT_TAG=frontiercs/dbscan-gpu-kernel-optimization-agent:experimental-v0.2.0
JUDGE_TAG=frontiercs/dbscan-gpu-kernel-optimization-judge:experimental-v0.2.0
```

Agent image:

```text
/app/dbscanlib # clean, git-tracked package (the agent edits this)
/opt/flash_gpu.py # shared Modal GPU harness (public test uses it)
/opt/dbscan_ref/refdbscan.py # frozen naive baseline (public-test speed denominator)
```

Judge image:

```text
/opt/dbscanlib-clean/dbscanlib # pristine tree; the patch is applied to a copy
/opt/dbscan_ref/refdbscan.py # frozen naive baseline (speed denominator + quality oracle)
/opt/flash_gpu.py # shared Modal GPU harness (the evaluator uses it)
```

## Runtime requirements

Both the judge and the agent public test **offload timing to a Modal GPU** and
therefore need Modal credentials in the environment:

```text
MODAL_TOKEN_ID / MODAL_TOKEN_SECRET
```

`flash_gpu.py` builds an ephemeral Modal app on a GPU (`evaluation.gpu`, default
`H100`), ships the frozen baseline + the patched package as data, times both on
fresh per-iteration data, verifies quality each iteration, and returns the
speedups. No persistent deployment is used, so a fresh GPU container is spun up
per evaluation. Without Modal credentials the evaluator returns a patch-policy
smoke pass (which repo CI exercises).

## Smoke test

```bash
bash 2.0/problems/dbscan_gpu_kernel_optimization/docker/smoke_images.sh
```

Import-only (modal + flash_gpu + the baked packages); does not touch a GPU or Modal.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Agent image for dbscan_gpu_kernel_optimization.
#
# Light image (no torch/triton): the agent edits /app/dbscanlib and runs the
# public test, which offloads timing to a Modal GPU (torch/triton live on the
# Modal image defined in flash_gpu.py). Needs MODAL_TOKEN_ID / MODAL_TOKEN_SECRET
# in the environment to run the GPU public test.
#
# Build context = the task directory:
# docker build -f docker/agent/Dockerfile -t <agent_tag> .
FROM ubuntu:24.04

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends \
bash ca-certificates git python3 python3-pip ripgrep && \
rm -rf /var/lib/apt/lists/*

RUN pip3 install --break-system-packages --no-cache-dir modal

# The package the agent edits (git-tracked so make_submission.sh can diff it).
WORKDIR /app
COPY dbscanlib /app/dbscanlib
RUN printf '%s\n' '__pycache__/' '*.pyc' > /app/.gitignore && \
git -C /app init -q && \
git -C /app config user.email task@frontier-cs && \
git -C /app config user.name frontier-cs && \
git -C /app add -A -- dbscanlib .gitignore && \
git -C /app -c commit.gpgsign=false commit -qm "pristine dbscanlib"

# NOTE: the GPU harness (flash_gpu.py) and its data GENERATOR are deliberately
# NOT baked into the agent image -- they live only in the judge. The agent gets
# feedback by submitting to the judge (public_test == the graded submission),
# so it cannot read how the workloads are generated and hardcode a
# data-specific shortcut. See harbor_app/public_test.py.
17 changes: 17 additions & 0 deletions 2.0/problems/dbscan_gpu_kernel_optimization/docker/build_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Build the experimental agent + judge images for dbscan_gpu_kernel_optimization.
set -euo pipefail
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) # the problem directory (build context)

AGENT_TAG=${AGENT_TAG:-frontiercs/dbscan-gpu-kernel-optimization-agent:experimental-v0.3.0}
JUDGE_TAG=${JUDGE_TAG:-frontiercs/dbscan-gpu-kernel-optimization-judge:experimental-v0.3.0}

echo "Building agent image: $AGENT_TAG"
docker build -f "$HERE/docker/agent/Dockerfile" -t "$AGENT_TAG" "$HERE"

echo "Building judge image: $JUDGE_TAG"
docker build -f "$HERE/docker/judge/Dockerfile" -t "$JUDGE_TAG" "$HERE"

echo "Built:"
echo " $AGENT_TAG"
echo " $JUDGE_TAG"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Judge image for dbscan_gpu_kernel_optimization.
#
# Light image (no torch/triton): the judge validates + applies the patch and
# offloads timing to a Modal GPU (torch/triton live on the Modal image defined
# in flash_gpu.py). Needs MODAL_TOKEN_ID / MODAL_TOKEN_SECRET in the environment.
# The Frontier-CS 2.0 adapter builds the final judge image ON TOP of this one.
#
# Build context = the task directory:
# docker build -f docker/judge/Dockerfile -t <judge_tag> .
FROM ubuntu:24.04

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends \
bash ca-certificates git python3 python3-pip && \
rm -rf /var/lib/apt/lists/*

RUN pip3 install --break-system-packages --no-cache-dir modal

# Pristine tree the patch is applied to, the frozen naive baseline (speed
# denominator + quality oracle), and the shared Modal GPU harness.
COPY dbscanlib /opt/dbscanlib-clean/dbscanlib
COPY judge/refdbscan.py /opt/dbscan_ref/refdbscan.py
COPY flash_gpu.py /opt/flash_gpu.py

WORKDIR /judge
22 changes: 22 additions & 0 deletions 2.0/problems/dbscan_gpu_kernel_optimization/docker/smoke_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Smoke test for the built (intentionally torch-less) images: confirm the host-side
# harness imports (modal + flash_gpu) and that the frozen baseline + package parse.
# torch/triton live on the Modal image, so the packages are py_compiled here (a
# torch-less parse check), not imported. No GPU / Modal tokens required.
set -euo pipefail

AGENT_TAG=${AGENT_TAG:-frontiercs/dbscan-gpu-kernel-optimization-agent:experimental-v0.2.0}
JUDGE_TAG=${JUDGE_TAG:-frontiercs/dbscan-gpu-kernel-optimization-judge:experimental-v0.2.0}

SMOKE='import sys, modal, py_compile, pathlib
sys.path.insert(0, "/opt"); import flash_gpu
for root in sys.argv[1:]:
for p in pathlib.Path(root).rglob("*.py"):
py_compile.compile(str(p), doraise=True)
print("ok: modal + flash_gpu import; dbscan baseline + dbscanlib parse")'

echo "== agent image =="
docker run --rm -w /app "$AGENT_TAG" python3 -c "$SMOKE" /opt/dbscan_ref /app/dbscanlib

echo "== judge image =="
docker run --rm "$JUDGE_TAG" python3 -c "$SMOKE" /opt/dbscan_ref /opt/dbscanlib-clean/dbscanlib
12 changes: 12 additions & 0 deletions 2.0/problems/dbscan_gpu_kernel_optimization/evaluate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Local CLI evaluation for dbscan_gpu_kernel_optimization.
#
# A full run needs a GPU plus the baked judge sources at /opt (the pristine
# /opt/dbscanlib-clean tree and the frozen /opt/dbscan_ref baseline; see the
# judge image). Without them the evaluator still validates the patch policy and
# returns a smoke score, which is what repository CI exercises (the reference
# patch passes the policy). Pass a patch path to score it directly.
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
SOLUTION="${1:-$SCRIPT_DIR/reference.patch}"
exec python3 "$SCRIPT_DIR/evaluator.py" "$SOLUTION"
Loading
Loading