perf(hdbscan): stop calling a length-1 vPowx per coordinate in the Minkowski distance #3895
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.344
Real PR Conversation Timeline
1 comments
"Review active on #3895"
general
weight: 0.35
Vika-F
Problem
MinkowskiDistraised every coordinate difference withMathInst::sPowxand took the root with anothersPowx. With MKL,sPowxisvPowx(1, &in, p, &r), a VML call of length 1. So one distance costd + 1VML calls, inpointDist,bboxLowerBoundandblockDist.As a result, minkowski with p not in {1, 2, inf} was 0.26-0.6x scikit-learn single-threaded on ball_tree and brute. p = 1 and p = 2 were not affected, because scikit-learn-intelex maps them to manhattan and euclidean.
Fix
All of this is in
hdbscan_distance_utils.h.sqrtfor the half. The root is skipped for p = 1 and issqrtfor p = 2.vPowxcall covers a whole row, or several short rows inblockDist.blockDist: takes all the roots of a block with onevPowx(orvSqrt) call.blockDistcall per row, through a newuseBlockDisttemplate flag onfillFullDistMatrix. Manhattan and Chebyshev keep the per-pair loop; routing them throughblockDistmeasured 3-6% slower.hdbscan_ball_tree_batch_impl.iis not touched.Results:
vPowxas before, now on many terms per call; the test checks the MST weights againststd::powto tolerance, and in the measured runs (p = 2.7) the MST weights came out identical.powto tolerance, not bitwise. The largest relative MST weight difference is 2.2e-16 to 4.2e-16 in float64, and the labels are identical in every measured case.MathInstcalls used are the same on both, so the change applies to both. On the reference backendsPowxwas alreadypow, so the gain there is smaller.Test
New test
hdbscan: minkowski merge distances match the MST of std::pow distancesintest/batch.cpp. Each method and float type is checked against a reference that uses neither oneDAL code nor tie handling:vPowx);min_samples = 1, so the merge distances equal the MST weights;std::powdistances.bazel test --config=host //cpp/oneapi/dal/algo/hdbscan:testspasses. A gcc-Wall -Wextra -Werrorsyntax check of the three DAAL HDBSCAN sources with the reference backend passes too.Measured effect
Setup:
param_blobs_n10000_d4(10000 x 4, float64) from the HDBSCAN benchmark study;main(same base);sklearnex.preview.cluster.HDBSCAN, scikit-learn 1.9.1;numactl --physcpubind=0 / 0-7 / 0-55 --membind=0on a 2-socket Intel CPU, withOMP/MKL/OPENBLAS_NUM_THREADS,threadpool_limitsandn_jobsall set to the thread count.Each process warms up, then runs 3 timed fits. main, this PR and scikit-learn processes are interleaved, with the order alternated over 3 rounds. Values are medians of 9 fits per side, given as ratios: speedup vs main is main time / PR time, and "vs sklearn" is sklearn time / sklearnex time, so > 1 means sklearnex is faster.
The machine is shared; the load average was recorded for every process.
| algorithm | p | threads | speedup vs main | main vs sklearn | this PR vs sklearn |
|---|---|---|---|---|---|
| kd_tree | 1.5 | 1 | 2.72x | 1.46 | 3.98 |
| kd_tree | 1.5 | 8 | 2.65x | 11.35 | 30.03 |
| kd_tree | 1.5 | 56 | 2.47x | 67.15 | 165.56 |
| kd_tree | 2.7 | 1 | 2.36x | 1.07 | 2.54 |
| kd_tree | 2.7 | 56 | 2.15x | 51.47 | 110.76 |
| kd_tree | 3 | 1 | 4.02x | 1.40 | 5.61 |
| kd_tree | 3 | 8 | 3.87x | 10.94 | 42.38 |
| kd_tree | 3 | 56 | 3.34x | 65.99 | 220.52 |
| kd_tree | 1 (control) | 1 | 1.01x | 2.78 | 2.81 |
| kd_tree | 1 (control) | 8 | 1.01x | 21.02 | 21.22 |
| kd_tree | 1 (control) | 56 | 1.01x | 60.69 | 61.04 |
| kd_tree | 2 (control) | 1 | 1.00x | 3.53 | 3.53 |
| kd_tree | 2 (control) | 8 | 1.00x | 22.90 | 22.93 |
| kd_tree | 2 (control) | 56 | 1.03x | 61.73 | 63.52 |
| ball_tree | 1.5 | 1 | 2.70x | 0.58 | 1.56 |
| ball_tree | 1.5 | 8 | 2.78x | 3.87 | 10.74 |
| ball_tree | 1.5 | 56 | 3.27x | 19.95 | 65.26 |
| ball_tree | 2.7 | 1 | 2.47x | 0.35 | 0.86 |
| ball_tree | 2.7 | 56 | 2.89x | 12.29 | 35.51 |
| ball_tree | 3 | 1 | 4.01x | 0.38 | 1.54 |
| ball_tree | 3 | 8 | 4.12x | 2.65 | 10.93 |
| ball_tree | 3 | 56 | 4.70x | 13.35 | 62.75 |
| ball_tree | 1 (control) | 1 | 0.98x | 1.49 | 1.46 |
| ball_tree | 1 (control) | 8 | 0.98x | 15.08 | 14.82 |
| ball_tree | 1 (control) | 56 | 1.00x | 56.18 | 55.93 |
| ball_tree | 2 (control) | 1 | 1.01x | 1.26 | 1.28 |
| ball_tree | 2 (control) | 8 | 1.01x | 11.71 | 11.87 |
| ball_tree | 2 (control) | 56 | 1.00x | 48.79 | 48.75 |
| brute | 1.5 | 1 | 7.25x | 0.38 | 2.76 |
| brute | 1.5 | 8 | 6.24x | 0.92 | 5.72 |
| brute | 1.5 | 56 | 4.71x | 1.38 | 6.47 |
| brute | 2.7 | 1 | 8.77x | 0.26 | 2.26 |
| brute | 2.7 | 56 | 5.65x | 0.97 | 5.46 |
| brute | 3 | 1 | 10.00x | 0.26 | 2.57 |
| brute | 3 | 8 | 8.32x | 0.63 | 5.28 |
| brute | 3 | 56 | 6.42x | 0.98 | 6.32 |
| brute | 1 (control) | 1 | 1.00x | 1.07 | 1.07 |
| brute | 1 (control) | 8 | 1.00x | 3.70 | 3.68 |
| brute | 1 (control) | 56 | 1.01x | 6.75 | 6.80 |
| brute | 2 (control) | 1 | 1.00x | 1.20 | 1.20 |
| brute | 2 (control) | 8 | 1.01x | 4.22 | 4.25 |
| brute | 2 (control) | 56 | 1.00x | 7.19 | 7.20 |
The brute rows come from the final commit. The tree rows come from the commit before it, which only differed in how
fillFullDistMatrixtreats non-Minkowski metrics; the tree paths do not use that function.Remaining gap: ball_tree with a p that is not a multiple of 1/2 (2.7 here) is still 0.86x scikit-learn single-threaded. Each tree distance still needs one
vPowxcall for its coordinates and onesPowxcall for its root.🤖 Generated with Claude Code