Skip to content

[SPARK-62488][CONNECT][PYTHON] Delegate standard KMeans operations to Rust - #1000

Closed
zhengruifeng wants to merge 1 commit into
apache:masterfrom
zhengruifeng:feature/standard-kmeans-rust
Closed

zhengruifeng wants to merge 1 commit into
apache:masterfrom
zhengruifeng:feature/standard-kmeans-rust

Conversation

@zhengruifeng

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Route pyspark.ml.clustering.KMeans.fit, model transformation and prediction, training summary access, and estimator/model persistence through the existing Rust KMeans implementation. Python keeps its parameter setters, copying, and subclass hooks. Setter calls update the native parameter state immediately.

The standard and compatibility imports share KMeans, KMeansModel, and KMeansSummary. The clustering adapter loads the Spark 4.3.0 source from ml/_upstream/clustering.py. The vendor check verifies that copy against the Spark tag.

Why are the changes needed?

The standard Python estimator previously assembled ML requests in Python, so running Spark’s upstream KMeans tests against this package did not exercise the Rust KMeans implementation. This extends the standard ML delegation used for classification and regression to the first clustering estimator. SPARK-62488

Does this PR introduce any user-facing change?

The three compatibility imports now identify their public module as pyspark.ml.clustering. Their standard Python signatures, fitted results and persisted formats match PySpark 4.3.0.

How was this patch tested?

  • Ran the official Spark 4.3.0 clustering, cache, pipeline and tuning parity modules against the built drop-in and a live Spark Connect server. All 8 clustering tests passed. Across the four modules, 25 tests passed and 4 pipeline tests were skipped upstream.
  • Added a weighted two-cluster test with the Python ML request builders disabled. It checks centers, point predictions, summary cost and sizes, persistence, and a lazy transform collected after releasing the loaded model. Also verified that official PySpark and the Rust-backed client can read each other’s estimators and models, with optional Python transport dependencies blocked in the Rust-backed process.
  • Compared the public signatures and member kinds of all three classes against official PySpark 4.3.0. Ran the standard ML offline suite (237 passed), ML API and binding offline suites (1,277 passed, 68 skipped), and type-stub suite with mypy and Pyright (21 passed).
  • Ran the Rust KMeans live and golden tests, Rust library tests (864 passed), release integration-test compilation with and without wasm-udf, Clippy, rustfmt, Ruff, and the vendor, generated stub and binary license checks.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex (GPT-6)

This pull request and its description were written by Isaac.

… Rust

Co-authored-by: Isaac <no-reply@databricks.com>
@zhengruifeng
zhengruifeng deleted the feature/standard-kmeans-rust branch December 1, 2026 03:46
zhengruifeng added a commit that referenced this pull request Dec 1, 2026
…ations to Rust

### What changes were proposed in this pull request?

Delegate `pyspark.ml.clustering.BisectingKMeans` fit, transform, prediction, cost, training summaries and persistence to the existing Rust implementation. Python keeps its setters, parameter maps, copying and subclass hooks. Changes to estimator and model parameters reach Rust as soon as the setter returns.

The standard and compatibility imports share the estimator, model and summary classes. The native `computeCost` method uses the original PySpark warning location so filters for `pyspark.ml.clustering` and the warn-once behavior still work.

### Why are the changes needed?

The standard Python estimator previously built its own ML requests. This lets Spark’s existing BisectingKMeans tests exercise the same implementation as Rust callers and continues the clustering migration started with KMeans. [SPARK-62493](https://issues.apache.org/jira/browse/SPARK-62493) · [KMeans PR #1000](#1000)

### Does this PR introduce _any_ user-facing change?

The three compatibility classes now report `pyspark.ml.clustering` as their public module. The standard signatures and persistence format match PySpark 4.3.0.

### How was this patch tested?

- Ran Spark 4.3.0’s official clustering, cache, pipeline and tuning suites against the Rust-backed package and a live Spark Connect server. All eight clustering tests passed. The four suites had 25 passes and four upstream pipeline skips.
- Extended the weighted clustering test with Python ML request builders disabled. With four clusters requested and a minimum divisible cluster size of 75%, it verifies two fitted centers, summary sizes of `[2, 2, 0, 0]`, weighted training cost of `15.0` and `computeCost` of `12.5`. It also exercises prediction, save/load and a lazy transform after releasing the loaded model.
- Verified both clients could load one another’s saved estimator and model and produce identical predictions, with optional Python transport dependencies blocked in the Rust-backed process. Compared public member signatures and kinds for the estimator, model and summary against official PySpark.
- Ran the standard ML and native binding offline suites, mypy and Pyright stub tests, Rust library and live BisectingKMeans tests, release integration-test compilation with and without `wasm-udf`, Clippy, rustfmt, Ruff, and the vendoring, generated stub and binary license checks.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex (GPT-6)

This pull request and its description were written by Isaac.

Closes #1001 from zhengruifeng/feature/standard-bisecting-kmeans-rust.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant