← Back to Pull requests

fix(kmeans_init): score the best local trial with its own candidate in k-means++ #3859

Closed
unknown closed this pull request without merging on Oct 15, 2026 18:28 UTC
View on GitHub
unknown unknown commented on Oct 07, 2026 13:35 UTC
Author

Description

k-means++ with local trials scored the previous best trial's slot with trial 0's candidate. updateMinDistInBlock passed pLastAddedCenter (trial 0) instead of &pLastAddedCenter[iBestTrial dim] for the best trial, in both DataHelperDense and DataHelperCSR.

Whenever the previous round's best trial was not trial 0, that slot's candidate was never scored. Its potential came out equal to trial 0's, and the strict < or last-bit rounding decided the pick. Results were still valid centers, but:

  • the init evaluated one candidate fewer than requested in those rounds;

  • the result depended on rounding. Dense and CSR compute distances with different formulas, so on the sse2 kernels (CPUs without AVX2) dense and CSR k-means++ picked different centers for some seeds. This is the release-validation failure of sklearnex/cluster/tests/test_kmeans.py::test_dense_vs_sparse[dims2--k-means++] on the 2026.2 conda/pip VMs, which have no AVX2.
  • The fix passes each trial's own candidate. The bug predates the move of the sources into src/.

    Test. A white-box case in the private suite test/internal.cpp (internal_tests, like knn's) calls DataHelperDense and DataHelperCSR::updateMinDistInBlock directly. On 4 rows with integer coordinates and 3 trials, it runs the update once with each trial as the best and checks every trial's per-row distances and potential against hand-computed values. It covers dense and CSR, float32 and float64. Being private, it is not built against the release package, which ships neither the DAAL sources nor the backend interop headers. Without the fix it fails whenever the best trial is not trial 0.

    Validation.

  • kmeans_init:tests and kmeans:tests pass on CPU in the dev link mode; the public suites also pass with --test_link_mode=release_static.

  • The DPC++ test binaries build and pass. The new case only covers the CPU kernel, since the GPU plus_plus_dense is a separate implementation.

  • Against a local 2026.2 build with dispatch forced to sse2, avx2 and avx512: dense and CSR k-means++ agree for 60/60 seeds with the fix (4-5/60 disagreed on sse2 without it).

  • The scikit-learn-intelex KMeans and k-means init tests pass with the fix on the sse2 and avx512 paths.
  • Results of k-means++ init change wherever a non-zero trial won a round, on every ISA.

    The GPU Fatal Python error: Aborted from the same validation report is not addressed here. It needs a GPU repro.

    ---

    <details>
    <summary>Checklist:</summary>

    Completeness and readability

  • I have commented my code, particularly in hard-to-understand areas.

  • I have updated the documentation to reflect the changes or created a separate PR with updates and provided its number in the description, if necessary.

  • Git commit message contains an appropriate signed-off-by string _(see CONTRIBUTING.md for details)_.

  • I have resolved any merge conflicts that might occur with the base branch.
  • Testing

  • I have run it locally and tested the changes extensively.

  • All CI jobs are green or I have provided justification why they aren't.

  • I have extended testing suite if new functionality was introduced in this PR.
  • Performance

  • I have provided justification why performance and/or quality metrics have changed or why changes are not expected. The init now scores every requested trial; the amount of work per round is unchanged.
  • </details>

    🤖 Generated with Claude Code

    Diff: 450 lines (+337 / -113) across 5 files Reviewer: Vika-F Review duration: 11812m
    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 · 450 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.366
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3859"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.4% (MEDIUM) · Higher = larger blast radius
    45.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.9% · Safe to merge
    17.9%