HyukjinKwon opened a new pull request, #804:
URL: https://github.com/apache/spark-connect-rust/pull/804

   ### What changes were proposed in this pull request?
   
   A follow-up of #784 (SPARK-61865), from a round-2 review of the ML saves 
against PySpark 4.3.0. Each item was probed on both clients against a Spark 
4.3.0 server.
   
   **1. `RegexTokenizer.gaps` is saved.**
   - `gaps` has no converter in PySpark (ml/feature.py:4118-4122), so the 
drop-in keeps its Python value aside and sends it at a transform. The save sent 
the params without it.
   - So a saved tokenizer loaded with `gaps=True`, also inside a Pipeline or 
PipelineModel, and gave other results with no error. For example, 
`RegexTokenizer(inputCol="text", outputCol="w", pattern="\\d+", gaps=False)` 
transformed to `['1', '22']`, but once saved and loaded, to `['a', 'b', 'c']`.
   - Values that PySpark's save refuses saved silently too. PySpark raises 
`UNSUPPORTED_DATA_TYPE` for `gaps=(1,)`, `VALUE_NOT_BETWEEN` for `2**63`, and 
the server's `ClassCastException` for `1`, `'yes'` or `[True]`.
   
   **2. The set params of a Python subclass are sent.** PySpark's 
`serialize_ml_params` sends every item of `_paramMap` 
(ml/connect/serialize.py:210-214). So a subclass's own `Param` that is set 
reaches the server, which refuses it with `NoSuchElementException: Param 
myParam does not exist.` The drop-in dropped it silently, at a fit, a 
transform, an evaluation and a save.
   
   With this PR, fits, transforms, evaluations and saves send the params as 
`serialize_ml_params` does:
   - in `_paramMap`'s order;
   - the values of params of no converter, and the set params of a Python 
subclass;
   - with the error of the first param that PySpark cannot send.
   
   The save takes the same path, so it raises PySpark's errors. Only `gaps` is 
affected by item 1; the other params of no converter belong to meta-algorithms, 
whose writers save them themselves.
   
   **3. The class of subclasses of meta-algorithms.** PySpark writes 
`instance.__module__ + "." + instance.__class__.__name__` into the metadata 
(ml/util.py:918). Subclasses of Pipeline, the validators and OneVsRest, and 
their models, saved the base class's constant name. They now save the 
subclass's, such as `__main__.MyOVR`. Such files load as PySpark loads them:
   - OneVsRest and Pipeline as their base class;
   - the validators raise PySpark's `TypeError` (tuning.py:445);
   - a stage of a class missing from its module raises an `AttributeError`.
   
   `docs/compatibility.md` describes these.
   
   ### Why are the changes needed?
   
   A saved `RegexTokenizer` of `gaps=False` silently tokenized otherwise once 
loaded. Set params of subclasses were dropped, and the metadata of subclasses 
was not PySpark's.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, as above:
   - `gaps` is saved;
   - values that PySpark's save refuses raise at the save;
   - subclass params reach the server;
   - subclasses of meta-algorithms save their own class.
   
   Remaining differences:
   - A subclass param of a model is not sent; a model gets one only if a 
subclass model is built by hand.
   - The subclass params of meta-algorithms are not written into their 
metadata, where PySpark's `extractJsonParams` writes them.
   
   ### How was this patch tested?
   
   - **New tests.** Each fails on master and passes here.
     - `test_ml_features_offline.py`: 
`test_regex_identity_is_saved_of_its_python_value_as_pyspark`.
     - `test_ml_offline.py`: 
`test_ml_connect_params_of_a_python_subclass_are_sent_as_pyspark`.
     - Live, `test_ml_subclasses_e2e.py`: 
`test_a_set_param_of_a_subclass_is_sent_and_refused_by_the_server` and 
`test_the_metadata_of_a_subclass_of_a_meta_algorithm_is_of_its_class`. Both 
pass on the official client too.
     - Live, `test_ml_features_e2e.py`: 
`test_regex_tokenizer_saves_its_gaps_of_no_converter`.
   - **Probes of both clients** differ in nothing:
     - the saves of all 66 native classes, of every param set (267 lines);
     - `gaps`, the subclass params, and their order among unsendable values;
     - the metadata of subclasses.
   - **Python.**
     - The 15 ML offline files on pandas 2 and 3 (2322 passed each).
     - After the rebase on master, the offline suite of `coverage.yml` (6169 
passed).
     - The related live ML files (503 passed).
   - **Rust.**
     - After the rebase, `cargo test -p apache-spark-connect -p 
apache-spark-connect-core --release` (1644 passed);
     - `--features wasm-udf`;
     - `cargo test -p pyspark-rs --lib`.
   - **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -D warnings`, 
ruff 0.14.0, `audit_no_stubs.sh` and `scripts/tests`.
   
   ### 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]

Reply via email to