HyukjinKwon opened a new pull request, #667:
URL: https://github.com/apache/spark-connect-rust/pull/667
### What changes were proposed in this pull request?
Base B of completing the native ML classes to the full `pyspark.ml` 4.3.0
surface. The plan: the Rust API and the native Python classes get the typed
model accessors, summaries, single-vector prediction and persistence, area by
area. This PR adds `spark_connect::ml::object`, the server-side objects of
Spark Connect ML that those build on, as PySpark 4.3.0 reads and writes them
over Spark Connect:
- **`MlRef`**, the public form of the cached model:
- shared by a model, its clones and the DataFrames whose plans read it;
- deleted on the server when its last owner drops, as PySpark's
`RemoteModelRef` is;
- available as `Model::ml_ref()`, implemented for the 25 models that the
server holds.
- **`fetch(&MlTarget, method, args)`**, as `try_remote_call` of
`pyspark.ml.util`. It is a `Fetch` of a method of:
- an object;
- a method chain (`MlTarget::object(&r).child("summary")`, which PySpark
names `"<id>.summary"`);
- the ML helper (`MlTarget::helper`).
Its result is one of:
- a value;
- new objects (a comma-joined id, as of the `trees` of an ensemble, is one
`MlRef` per tree);
- a string.
When the server has lost a summary with its offloaded model
(`CONNECT_ML.MODEL_SUMMARY_LOST`), the fetch sends `CreateSummary` of the
target's summary dataset and runs once more, as PySpark does.
- **`attribute_relation`**, the DataFrame of a method, as
`invoke_remote_attribute_relation`: an `MlRelation` of the fetch, whose
`model_summary_dataset` is the summary dataset of a summary target. It keeps
the object and the plans of its DataFrame arguments alive.
- **`MlValue`**, a value as `deserialize_param` reads it and
`serialize_param` sends it:
- ML vectors and matrices, as their UDT structs;
- scalars, strings, arrays, maps and structs.
An array is typed by its first element, as `LiteralExpression._infer_type`
types a list. An empty array raises `CANNOT_INFER_ARRAY_ELEMENT_TYPE` unless it
is sent as `FetchArg::Typed`, as PySpark's `(value, DataType)` pairs are.
- **`write_operator`, `write_object` and `read`**, as `RemoteMLWriter` and
`RemoteMLReader` of `pyspark.ml.connect.readwrite`:
- a `Write` of an estimator, transformer or evaluator, or of a fitted
model's object, with the overwrite flag and options;
- a `Read` of a JVM class, whose model is a new `MlRef`, with its uid and
params.
Also:
- `ml/{classification,regression,clustering}_api.rs` are registered (empty)
for the areas that add the typed accessors;
- `e2e_ml_object` is in the Rust live test lists of connect-e2e and of the
coverage.
### Why are the changes needed?
The native models expose only `transform` today. Their inspection, summaries
and persistence, in the Rust API and in the native Python classes, all need
these commands.
### Does this PR introduce _any_ user-facing change?
Yes, in the Rust API: `spark_connect::ml::{MlRef, MlTarget, MlValue,
FetchArg, FetchOutput, fetch, attribute_relation, write_operator, write_object,
read, ReadResult, ML_CONNECT_HELPER_ID}` and `Model::ml_ref`.
`docs/compatibility.md` describes them.
### How was this patch tested?
- `tests/golden/ml_values.json` (from `scripts/capture_ml_values_golden.py`
on official pyspark-client 4.3.0) holds 17 literals of `serialize_param`:
scalars, arrays, nested arrays, dense and sparse vectors and matrices
(transposed too), and typed pairs. `ml_values_golden` checks that `MlValue`
reads and sends each, byte for byte.
- Unit tests: the round trips, the array typing, and the fetch request of a
method chain.
- `e2e_ml_object`, live against Spark 4.3.0, covers:
- the coefficients, intercept, numFeatures, numClasses and predict(vector)
of a LinearSVC model;
- its summary's accuracy and its predictions DataFrame;
- the helper's English stop words (181);
- the 3 trees of a RandomForest as their own objects, each with its
numNodes;
- the save and load of a model (equal coefficients, and the server's error
without overwrite) and of an estimator (uid and params).
- The core lib tests (691), and `e2e_linear_svc`, `e2e_als` and
`e2e_frequent_patterns` live. All integration tests compile, with and without
`wasm-udf`. `pyspark-rs` builds.
- clippy of the lint job (workspace and core, `-D warnings`, Rust 1.100.0),
`cargo fmt --all --check`, and ruff of the script.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
This pull request and its description were written by Isaac.
--
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]