fix(dbscan): split the metrics example per metric and batch the Minkowski powers #3995
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3995"
general
weight: 0.35
Vika-F
Description
dbscan_brute_force_metrics_batchran DBSCAN with five metrics in one process and exceeded the 5-minute per-example limit in the internal Windows example run (TIMEOUT (0:05:00) dbscan_brute_force_metrics_batch). This PR splits the example per metric, which showed that Minkowski is the slow one, and fixes the Minkowski distance computation.Examples. One example per metric, in
examples/oneapi/cppandexamples/oneapi/dpc:dbscan_brute_force_manhattan_batch.cppdbscan_brute_force_minkowski_batch.cpp(degree 3)dbscan_brute_force_chebyshev_batch.cppdbscan_brute_force_cosine_batch.cppData,
epsilonandmin_observationsare the same as in the removed example. The euclidean case is dropped, sincedbscan_brute_force_batchalready shows the default metric.docs/source/includes/clustering/dbscan-examples.rstlists the new files; Bazel, CMake and the docs pick the files up by glob. After the split, the internal Windows run times out only indbscan_brute_force_minkowski_batch.Minkowski distances.
MinkowskiDistances::computeBatch(service_kernel_math.h) is used for Minkowski degrees other than 1 and 2 by the CPU DBSCAN default path, by brute-force kNN (classification, regression and search, which scikit-learn-intelex uses forKNeighborsClassifier,KNeighborsRegressor,NearestNeighborsandLocalOutlierFactorwithmetric="minkowski") and by the HDBSCAN medoid computation. It calledsPowxon every coordinate of every pair, and on the MKL backend eachsPowxis a separatevPowxcall withn = 1; the example (10500 x 2, degree 3) makes about 2.2e8 of them.computeBatchnow writes the absolute differences of up to 32 values into a stack buffer, raises them topin onevPowxcall with the same VML mode, and sums each pair in coordinate order; a row with more than 32 features is processed in pieces. Degree 1 keeps the existing path. Brute-force kNN maps degree 2 to the euclidean distance; DBSCAN passes any degree to this class, so degree 2 takes the chunked path there. The chunk stays small on purpose: with the TBB threading layer VML starts its ownparallel_forfor longer vectors (seen from 128 elements),mkl_set_num_threads_localdoes not stop it, and from inside the DBSCAN neighborhood loop that made a 1024-value chunk up to 2.5x slower thanmainon all cores.computeBatchalso returns the status ofcomputeBatchImplinstead of dropping it.Performance. Speedup of this PR over
main(median time onmain/ median time with this PR) on a two-socket Intel CPU. Each cell is the range over degrees 1.5, 3 and 4.7. scikit-learn-intelexmainwas built once and run against both oneDAL builds by switchingLD_LIBRARY_PATH; brute force,n_neighbors=10(20 for LOF), 2000 queries against 20000 rows up to d=17, 1000 against 10000 for d=32 and 100, 500 against 4000 for d=512, 200 against 2000 for d=1000; median of 5 calls, three alternating rounds.| sklearnex, all cores | d=2 | d=8 | d=16 | d=17 | d=32 | d=100 | d=512 | d=1000 |
|---|---|---|---|---|---|---|---|---|
| KNeighborsClassifier, float32 | 3.9-4.9x | 7.5-10.0x | 1.3-1.4x | 1.3-1.5x | 1.4-1.7x | 2.0-2.1x | 1.0-1.2x | 1.3-1.4x |
| KNeighborsClassifier, float64 | 3.9-4.6x | 1.7-2.1x | 1.7-1.9x | 1.7-1.8x | 1.5-2.3x | 2.2-2.9x | 1.1-2.2x | 1.4-2.2x |
| KNeighborsRegressor, float32 | 3.9-4.8x | 7.8-10.4x | 1.2-1.4x | 1.4-1.5x | 1.3-1.6x | 1.9-2.1x | 1.0-1.2x | 1.3-1.7x |
| NearestNeighbors, float32 | 3.8-5.0x | 7.8-10.1x | 1.2-1.5x | 1.3-1.5x | 1.4-1.4x | 1.9-2.0x | 1.0-1.3x | 1.3-1.9x |
| LocalOutlierFactor, float32 | 2.2-3.0x | 4.7-6.2x | 1.2-1.4x | 1.3-1.3x | 1.2-1.3x | 1.7-2.3x | 0.9-1.2x | 1.1-1.5x |
| sklearnex, limited cores | d=2 | d=16 | d=100 |
|---|---|---|---|
| 1 core | 11.5-15.0x | 1.4-1.6x | 1.7-2.0x |
| 8 cores | 11.6-14.6x | 1.6-1.9x | 1.8-2.3x |
| 56 cores | 5.4-8.0x | 1.4-1.5x | 1.7-2.1x |
DBSCAN through the oneAPI C++ interface (rows chosen so that rows^2 x d is about 2e9, 2000-20000 rows; median of 3 runs, three alternating rounds; float and double):
| DBSCAN, all cores | d=1 | d=2 | d=3 | d=8 | d=15 | d=16 | d=17 | d=32 | d=64 | d=100 | d=256 | d=512 | d=1000 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| float | 1.6-2.5x | 2.9-4.3x | 2.7-4.3x | 6.5-12.6x | 7.7-11.3x | 1.4-1.7x | 1.3-1.7x | 1.3-1.9x | 1.3-1.8x | 1.6-2.1x | 1.2-1.7x | 1.3-1.7x | 1.4-2.1x |
| double | 2.1-2.6x | 2.6-4.2x | 2.4-4.0x | 1.6-2.0x | 4.8-6.2x | 1.6-2.3x | 1.5-2.4x | 1.5-2.5x | 1.3-2.5x | 1.5-2.3x | 1.4-2.7x | 1.4-2.7x | 1.3-2.2x |
| DBSCAN float, limited cores | d=2 | d=16 | d=100 |
|---|---|---|---|
| 1 core | 8.4-14.3x | 1.1-1.6x | 1.9-2.1x |
| 8 cores | 8.1-14.4x | 1.6-1.8x | 1.9-2.1x |
| 56 cores | 5.9-8.9x | 1.2-1.5x | 2.1-2.3x |
mainalready raised the differences in 16-valuevPowxcalls through the AVX-512 specialization ofcomputeDistance. Every other kNN and DBSCAN scenario is at least 1.06x faster, most of them 1.3x or more.p=1andp=2in the matrices above are within 0.8-1.2x on runs of a few milliseconds, and a targeted rerun with larger inputs and 15 calls per round gives 0.96-1.10x for kNN and 0.98-1.01x for DBSCAN.Correctness.
mainand against along doublereference for 1-1100 features (including 15, 16, 17, 1024 and 1025), degrees 0.5, 1, 1.5, 3 and 4.7, float and double. The neighbor indices are identical tomain. The distances differ frommainonly in the last bits, from the summation order, and the largest relative error against the reference is lower than onmain(8.4e-7 vs 1.0e-6 in float, 1.5e-15 vs 2.2e-15 in double).mainin all 104 type/feature/degree cases of the matrix and in the limited-core runs. HDBSCAN responses and medoid coordinates are identical too.NearestNeighborscase, 1 of 5000 in another, and 1 of 500KNeighborsRegressorpredictions. In every case the neighbors involved are at distances 1 ulp apart or equal: the k-th neighbor swaps at a tie, as with any change of rounding. All other outputs are identical.Tests.
bazel test --config=host://cpp/oneapi/dal/algo/{dbscan,knn,hdbscan}:tests,//examples/daal/cpp:{dbscan,k_nearest_neighbors}and//examples/oneapi/cpp:{dbscan,hdbscan,knn}pass (26 targets). The dbscan, knn and hdbscan batch suites also pass with--order randfor three seeds.bazel test --config=dpc --device=gpu://cpp/oneapi/dal/algo/{dbscan,knn}:testsand//examples/oneapi/dpc:{dbscan,knn}pass (16 targets).bazel build //:releasewith GCC 13 succeeds.sklearnex/neighborsandonedal/neighbors(88 passed) and scikit-learn'ssklearn.neighborssuite under the patch (1516 passed) give the same results withmainand with this PR.No public API or ABI changes.
---
Checklist:
Completeness and readability
Testing
Performance
Not with scikit-learn_bench: measured with scikit-learn-intelex estimators and the oneDAL DBSCAN/HDBSCAN interface directly (tables above).
🤖 Generated with Claude Code