HyukjinKwon opened a new pull request, #690:
URL: https://github.com/apache/spark-connect-rust/pull/690
### What changes were proposed in this pull request?
**Stacked on #681**: the commits before the last are #681's, so please
review the last commit, and merge after #681.
Base D1 of completing the native ML classes to the full `pyspark.ml` 4.3.0
surface, after Base C (#681). The native `Pipeline` of `pyspark.ml.connect`
held stage names and did not fit. It is now PySpark's `Pipeline` and
`PipelineModel` of `pyspark.ml.pipeline`, natively, as PySpark 4.3.0 has them
over Spark Connect (`crates/pyspark-rs/src/ml/pipeline_api.rs`):
- **Stages**: any estimators and transformers, kept as the object that was
set (a param of the converter `identity`). They can be the native classes,
`pyspark.ml`'s, or the user's.
- **Fit**: `fit` is `Pipeline._fit`, with its checks (`Cannot recognize a
pipeline stage of type ...`).
- Up to the last estimator, a transformer transforms and an estimator
fits; the model of each estimator but the last transforms for the next stage.
- The stages after the last estimator are kept as they are, in a
`PipelineModel` of a new uid.
- A param map fits a copy, a list fits once per map, and `fitMultiple`
returns PySpark's iterator.
- **Transform**: `PipelineModel.transform` transforms by each stage in
order, or by a copy of a param map. `stages` is an attribute of the instance,
as PySpark's.
- **Copy**: `Pipeline.copy` keeps the uid and copies each stage with the
extra params. `PipelineModel.copy` is of a new uid.
- **Params**: PySpark's Params API, and `clear`, which a Python class of
PySpark has.
- **Persistence**: `write`, `save`, `read` and `load` are of PySpark's
Python format:
- the metadata of `DefaultParamsWriter.saveMetadata`: a text file of one
line at `<path>/metadata`, of the class `pyspark.ml.pipeline.Pipeline` (or
`PipelineModel`) and the `stageUids`, in PySpark's order of its keys;
- each stage, saved by its own writer at `stages/<index>_<uid>`, the index
zero-padded.
An overwrite deletes the path by the ML helper first (`handleOverwrite`),
as `RemoteMLWriter` does. A stage loads as the native class of
`pyspark.ml.connect` of its name where one loads, else as PySpark's
(`DefaultParamsReader.loadParamsInstance`).
The core gets the metadata of that format, for the validators and OneVsRest
to follow: `Metadata` (with `json_object`, its JSON in PySpark's order),
`save_metadata`, `load_metadata`, `stage_path` and `handle_overwrite`.
The native writers and readers save and load an object of PySpark's Python
format, of the active session, as `RemoteMLWriter` and `RemoteMLReader` do.
### Why are the changes needed?
The native classes are to follow `pyspark.ml`, and a pipeline is how they
are used together. PySpark's Pipeline fits on the client, so the server cannot
fit one.
### Does this PR introduce _any_ user-facing change?
Yes.
- `pyspark.ml.connect.Pipeline` fits, transforms, copies, and saves and
loads, as PySpark's.
- `pyspark.ml.connect.PipelineModel` is the class of its model, not the
generic native model.
- The Rust API gets the metadata helpers.
- `docs/compatibility.md` describes them.
### How was this patch tested?
- **Cases** of `python/tests/_ml_api_cases.py` against the golden of
official pyspark-client 4.3.0 (`tests/golden/ml_api_cases.json`):
- 29 offline: the Params API, the errors of PySpark's binding, its checks
of stages and params, copy and clear, and the PipelineModel.
- 19 live: fits of maps and lists, `fitMultiple`, a trailing transformer,
and transforms. Also save and load of both classes, with the metadata and the
stage directories, which match what PySpark writes, and the error of a second
save.
- **Members**: `test_ml_api_offline.py` compares the members, their kinds,
the parameters of the methods and the Params of both classes with the API
golden.
- **Reference**: both test files pass on official PySpark too.
- **Cross-loading**, by hand: official PySpark loads a pipeline and its
model that this client saved, and this client loads PySpark's. Their transforms
predict the same.
- **Rust**:
- a unit test of the metadata's JSON and of the stage paths;
- a live `e2e_ml_object` test of the save, load and class check of the
metadata, the overwrite by the ML helper, and the stage paths.
- **Existing suites**: the offline list (4687) and the live list, the core
lib tests, clippy (`-D warnings`, Rust 1.100.0), fmt and ruff. The tests of the
old Pipeline's not-implemented fit now cover only the CrossValidator, which a
following PR completes; the live test of the setters expects PySpark's
TypeError of stages that are strings.
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]