fix(hdbscan): give each medoid task its own distance tile #3883
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 414 lines diff across 5 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.361
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3883"
general
weight: 0.35
Vika-F
Description
HDBSCAN medoids were not deterministic: on some machines a fit occasionally returned a different member of a cluster as its medoid. Labels, probabilities and centroids were not affected.
Cause.
computeMedoidsinhdbscan_centers_impl.iruns one task per (cluster, row block) and gave each thread oneTlsMemdistance tile. Inside a task,EuclideanDistances::finalizecalls MKL'svSqrt, and under MKL's TBB threading layer that call can run in parallel. While the thread waits on it, TBB may start another medoid task on the same thread, and that task overwrites the shared tile. The interrupted task then scores its members against another cluster's distances.Fix. Each task allocates its own tile of
iCount x min(colBlock, cluster size), so a task started on the same thread can no longer overwrite it.Where it reproduces.
MKL_CBWR=COMPATIBLE, which also makes that sqrt run in parallel: 52 to 74 bad fits out of 2000 before the fix, 0 out of 9000 after.finalize, and only that task's tile was wrong.Test. "hdbscan: medoids are the same on every compute" repeats a fit on eight symmetric lattices, where each lattice center is the medoid, and checks every medoid on every run. Without the fix it fails under
MKL_CBWR=COMPATIBLEon 4 CPUs (2 of 3 runs). With the fix it passed 10 of 10 runs. With the default MKL settings on Intel it passes either way, because there MKL runs that sqrt serially.Other kernels that use a
TlsMembuffer acrossPairwiseDistances::finalizeinsidethreader_formay have the same exposure; that is left for a separate change.---
<details>
<summary>Checklist:</summary>
Completeness and readability
Testing
Performance
</details>
🤖 Generated with Claude Code