BillHosea opened a new pull request, #60748:
URL: https://github.com/apache/spark/pull/60748

   ### What changes were proposed in this pull request?
   
   Fix `KMeans.preferBlockSolver` so that the `auto` solver sums the 
per-feature non-zero counts from the `numNonZeros` summary instead of the 
feature indices. This makes `solver=auto` actually select the block solver for 
dense datasets as documented.
   
   I also added a unit test that verifies auto selects the block solver for a 
dense dataset and the row solver for a sparse dataset, and that explicit 
`row`/`block` selections always win.
   
   ### Why are the changes needed?
   
   `activeIterator` yields `(index, count)` pairs, so `map(_._1)` sums feature 
indices. The resulting sum is at most `numFeatures * (numFeatures - 1) / 2`, 
far below the `count * numFeatures * 0.5` threshold for any dataset with at 
least as many rows as features, so `auto` has always chosen `row` since the 
block solver was introduced in SPARK-30661. Dense datasets never benefit from 
the block solver.
   
   Prior to this fix, `preferBlockSolver` also ran a full-dataset aggregation 
job before every training run, so for dense data the scan was pure overhead. In 
a benchmark of 384 concurrent KMeans jobs on the same hardware, explicitly 
setting `solver=row` (which kept the effective algorithm unchanged but skipped 
the scan) improved the throughput score by 9.7% and reduced the slowest job's 
elapsed time by 8.9%.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `solver=auto` (the default) now behaves as documented and selects the 
block solver for dense input. Users who want to force the row solver can set 
`solver=row`.
   
   ### How was this patch tested?
   
   Added a unit test in `KMeansSuite`. Ran on master (87d177b) with JDK 21:
   
       build/sbt "mllib/testOnly org.apache.spark.ml.clustering.KMeansSuite"
       ...
       [info] Tests: succeeded 17, failed 0, canceled 0, ignored 0, pending 0
       [info] All tests passed.
   
   I also confirmed that the new test catches the bug: reverting only the 
`map(_._2)` change makes it fail:
   
       [info] - SPARK-62121: auto solver prefers block solver for dense input 
*** FAILED ***
   
   `mllib` scalastyle (main + test): 0 errors, 0 warnings.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to