Native clustering benchmarks
Read the local CPU and Metal measurement protocol, final distance definitions and hardware qualification boundaries.
Development APIsThis report preserves the measured dev.3 baseline. See the matched dev.4 M2/V100 comparison for subsequent CUDA and workflow qualification.
The first qualification target is this Mac M2 Max: 12 CPU cores (8 performance, 4 efficiency), 38 GPU cores and 64 GB unified memory. e-means and o-means use native Aner Tensor storage and bounded local workers, with native Metal Float32 kernels. V100 32 GB and L40 measurements are not part of this report yet.
Measured M2 results
Recorded 2026 to 11 to 16T03:26:04.835955+00:00. Each value is the median of five warm resident fits. All 38 configurations, raw samples, final losses and exact source/binary hashes are retained in the machine readable report.
| Rows × features; centers | Algorithm | Fastest measured CPU (workers) | Metal (4 host workers) | Final Metal MSE |
|---|---|---|---|---|
| 2,048 × 16; 32 | e-means | 1.159 ms (12) | 89.407 ms | 6.721301 |
| 2,048 × 16; 32 | o-means | 0.833 ms (1) | 17.131 ms | 11.127453 |
| 8,192 × 32; 64 | e-means | 4.164 ms (4) | 17.083 ms | 16.200475 |
| 8,192 × 32; 64 | o-means | 5.044 ms (4) | 20.110 ms | 16.200677 |
| 16,384 × 32; 4,096 | e-means | 199.814 ms (12) | 72.638 ms | 16.743497 |
| 16,384 × 32; 4,096 | o-means | 222.418 ms (12) | 127.340 ms | 16.816442 |
| 65,536 × 32; 4,096 | e-means | 725.725 ms (12) | 141.257 ms | 14.584420 |
| 65,536 × 32; 4,096 | o-means | 713.896 ms (12) | 214.895 ms | 14.468577 |
At 65,536 rows, Metal is about 5.14× faster for e-means and 3.32× faster for o-means than their fastest measured CPU configurations. These are backend comparisons within each algorithm at the same budget, not equal error comparisons between algorithms. O-means is slower than e-means in these Metal tests; at 65,536 rows its final MSE is about 0.8% lower, while at 16,384 rows its MSE is higher. This first qualification does not establish a general o-means speed advantage.
Small problems favor CPU: Metal submission and synchronization cost can dominate the statistical work. More requested CPU workers also do not guarantee less elapsed time. The larger workloads benefit from using all 12 admitted CPU workers; the 8,192 row cases favor four workers. Use the recorded size and dtype when choosing placement and concurrency.
The small strict Lloyd baseline took 30.580 ms with one worker and 8.140 ms with four, with MSE 10.983158. Its Float64/exact-sum arithmetic and distinct initialization policy are documented above; these figures do not isolate an algorithm only speedup.
The corpus is deterministic synthetic uniform noise blobs with a single initialization seed and a three epoch budget. The runs are sequential on one machine, not a multi seed study or a statistical confidence interval. No claims about V100, L40, large embedding corpora or production deployment follow from them.
Timing and objective
tools/clustering_benchmark.cpp emits one JSON measurement per invocation. It constructs deterministic synthetic blobs from a fixed data seed (20261115), converts to Float32 and uploads to Metal before timing. One untimed fit warms the worker pool and compiles Metal kernels; repeated fits use the same initialization seed and immutable input. Each fit includes initialization, statistical updates, revival, index construction/refresh where applicable, closing means, final exhaustive assignment, inertia and output construction. Destruction, data generation and initial upload are outside the timer.
The primary metric is median total fit milliseconds, with every sample retained. inertia is the sum of final squared distances; mse = inertia / N, without division by dimension. Metal and CPU Float32 have separate numerical policies. Lloyd's existing strict CPU engine widens the same Float32 input to Float64 and uses exact centroid accumulation, so it is a behavioral baseline rather than an identical arithmetic kernel comparison.
Compare only matching workload, N, D, k, epoch budget and seed. Equal epochs are not equal quality; record final objective beside elapsed time. A later equal error study needs several budgets and seeds rather than inferring an algorithmic speedup from one point. Synthetic blobs do not establish embedding or production data performance.
Reproduce
Build with a Release configuration, Metal enabled and the supported Apple CPU profile. This report's build disables LTO and retains the project's strict floating point flags.
cmake -S . -B build/clustering-m2 -G Ninja \
-DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON \
-DANER_USE_MPS=ON -DANER_USE_ACCELERATE=ON -DANER_ENABLE_LTO=OFF
cmake --build build/clustering-m2 --target aner_clustering_benchmark
# algorithm backend workers N D k epochs seed repetitions
build/clustering-m2/aner_clustering_benchmark e-means cpu 4 8192 32 64 3 42 5
build/clustering-m2/aner_clustering_benchmark e-means mps 4 8192 32 64 3 42 5
build/clustering-m2/aner_clustering_benchmark o-means mps 4 8192 32 64 3 42 5The complete sweep is reproducible with python3 tools/run_clustering_benchmark.py --binary build/clustering-m2/aner_clustering_benchmark --output NEW_REPORT.json --repetitions 5. It refuses an existing output and verifies that source and executable hashes remain unchanged during measurement.
Run one timed fit process at a time, after other tests/builds complete, using the same power and thermal conditions. Record source fingerprint, executable hash, compiler, OS, model recipe, batch and step, worker count and actual dtype. Report the final exhaustive scoring cost as part of the total. The harness includes backend/scratch destruction before the fit call returns and excludes destruction of the returned model. The raw report's shorter wording about excluded destruction means returned model destruction. training_seconds() ends before backend/scratch cleanup, so its boundary differs from the external timer. This clarification does not change the historical timings or raw artifact.
Validation coverage
Native tests compare occupancy weighted EMA and closing statistics with independent scalar oracles, including fractional epochs and remainder batches. They exercise revival, deterministic worker parity, o-means restricted and exhaustive probe modes, immutable results, final labels/prediction consistency, admission limits and cancellation. Dedicated Metal cases check stable grouping across reduction tile boundaries, integer IDs, child/grandchild search, overflow handling and resident input buffers. Language tests cover required/named/default arguments and source diagnostics.
Validation completed on the recorded native build: 13 selected CTest suites passed, including existing strict K-means and Tensor/Metal regressions; the high level CPU/Metal clustering suite passed 13,143 checks and the separate GPU oracle suite passed. A separately configured CPU only build passed 11,534 checks. The full editor suite, generated model reference and explicit CLI source/guide review also passed. Missing hardware results are never represented as zero or projected speedup.
Later V100 32 GB and L40 comparison
First implement and qualify native CUDA clustering with the same statistical recipe and final output contract. Tensor CUDA support alone is insufficient. Pin a CUDA toolchain supporting V100's Volta architecture (the later CUDA 13 toolchain removes Volta compilation/library support), and qualify L40 separately. Match datasets, preprocessing, seeds, precision, warm up, timing scope and evaluated objectives. Report upload inclusive application timing separately from resident fitting. Include memory peaks and the fraction of time spent building the o-means index.
Use author implementations as separately pinned comparators only where their hardware requirements are satisfied. The reviewed e-means CuTe path targets SM90; V100 and L40 are not Hopper. The reviewed o-means Triton implementation advertises newer CUDA architectures; a V100 comparison requires a compatible implementation rather than assuming its source runs unchanged.
See e-means, o-means and source attribution.
See the Machine learning module reference for the shared API.
Time and quality, side by side
These observations come from the retained native run on Apple M2 Max with Aner 0.0.10-dev.3. Select a workload to compare the same dimensions, cluster count, epoch budget and seed.
2,048 rows · 16 dimensions · 32 clusters · 3 epochs · seed 42 · Float32 input
| Configuration | MSE | Inertia | Timing runs |
|---|---|---|---|
| e-means · 1 CPU worker · Float32 | 6.72130 | 13765.2 | 5 |
| e-means · 4 CPU workers · Float32 | 6.72130 | 13765.2 | 5 |
| e-means · 8 CPU workers · Float32 | 6.72130 | 13765.2 | 5 |
| e-means · 12 CPU workers · Float32 | 6.72130 | 13765.2 | 5 |
| e-means · Metal + 4 CPU workers · Float32 | 6.72130 | 13765.2 | 5 |
| o-means · 1 CPU worker · Float32 | 11.1275 | 22789.0 | 5 |
| o-means · 4 CPU workers · Float32 | 11.1275 | 22789.0 | 5 |
| o-means · 8 CPU workers · Float32 | 11.1275 | 22789.0 | 5 |
| o-means · 12 CPU workers · Float32 | 11.1275 | 22789.0 | 5 |
| o-means · Metal + 4 CPU workers · Float32 | 11.1275 | 22789.0 | 5 |
| Lloyd k-means · 1 CPU worker · Float64 | 10.9832 | 22493.5 | 5 |
| Lloyd k-means · 4 CPU workers · Float64 | 10.9832 | 22493.5 | 5 |
MSE: inertia / n; sum of backend precision squared coordinate distances per observation. Read distortion alongside elapsed time. A faster run with a larger error is a different tradeoff; this chart does not establish a speedup at equal quality. Lloyd uses the existing strict CPU engine with Float64 and exact centroid accumulation; see the measurement protocol.
Inspect the raw benchmark evidence