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

   ### What changes were proposed in this pull request?
   
   This is a follow-up of #700 (SPARK-61714), found while reviewing the last 50 
commits. A reviewer probed the Rust API's meta-algorithms against official 
PySpark 4.3.0 on the same server, and found six differences. This PR fixes them.
   
   1. **Nested validators ignored their own grid params (wrong results).** 
`CrossValidator::apply_param_map` and `TrainValidationSplit`'s set only the 
estimator's and evaluator's params. So a validator nested in a grid ignored its 
own `numFolds`, `trainRatio`, `seed`, `foldCol`, `parallelism` and 
`collectSubModels`. They now set them first, as PySpark's `Params.copy(self, 
extra)` does (`tuning.py:945`, `:1524`).
      - Outer CV over `Pipeline([inner CV(LinearSVC, ...)])` with a grid of the 
inner `numFolds` [2, 4]: official avgMetrics `[0.4245580808080808, 
0.42077020202020204]`, Rust before `[0.4245580808080808, 0.4245580808080808]`, 
now official's.
   2. **Loaded estimators crashed at transform.** A stage loaded as an 
estimator fitted into a model that carried the estimator's params, and the 
model's transform sent them. So a Pipeline saved by official with ALS, 
QuantileDiscretizer or MinHashLSH loaded and fit, then failed (`Param rank does 
not exist`, and so on). The fitted model now carries only the params of its 
class, as PySpark's `_copyValues` copies only the params that the model has. 
Param maps skip params a known class lacks.
   3. **No folds gave NaN metrics.** `numFolds` < 1 returned a model with NaN 
metrics; now the fit fails with PySpark's message, `'numpy.float64' object is 
not iterable`. `numFolds=0` without `foldCol` still fails with `float division 
by zero`, as before.
   4. **Grid values weren't converted.** The values of param maps are now 
converted as PySpark's `TypeConverters` convert them, with their messages, when 
they are applied and when `estimatorParamMaps` is saved:
      - an integer `regParam` now saves as `"0.0"`, as official's does;
      - an integer `fitIntercept` now fails with `Boolean Param requires value 
of type bool. Found <class 'int'>.`, instead of a JVM ClassCastException at fit.
      - The Rust `ParamGridBuilder` has no class, so the conversion happens 
where the stage's class is known.
   5. **Default seeds.** The default seed of a validator class (and of its 
model class) is now drawn once per process, as PySpark's 
`hash(type(self).__name__)` is the same for every instance in a process. The 
value still differs from PySpark's, which is documented.
   6. **Fitted model class names.** A fitted model of a loaded estimator is now 
named by the JVM class that PySpark creates, e.g. 
`DecisionTreeClassificationModel`, or `Bucketizer` for QuantileDiscretizer, not 
`<Estimator>Model`. The names come from a table generated by 
`scripts/gen_ml_stage_kinds.py` (`ml/param_specs.rs`), which also gives the 
params of each class.
   
   On the wire, `rand(seed)` and `randn(seed)` now send the seed as PySpark's 
`lit` does: an integer literal when it fits in 32 bits, so the k-fold split's 
`rand(7)` is the same request as PySpark's.
   
   ### Why are the changes needed?
   
   To match PySpark 4.3.0. Finding 1 gave silently wrong metrics, and finding 2 
crashed on pipelines that official PySpark saves.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, the six behaviors above, in the Rust API.
   
   ### How was this patch tested?
   
   - Unit tests next to the existing ones, each failing without its fix.
   - `crates/spark-connect/tests/e2e_ml_meta.rs`, new and live, against 
official's numbers:
     - the nested CV and TVS;
     - a CV over a loaded ALS, with avgMetrics `[0.6690446412218276, 
0.8557945260815127]`;
     - the loaded ALS, QuantileDiscretizer, DecisionTree and MinHashLSH 
pipelines, from small fixtures of official's metadata 
(`tests/fixtures/ml_meta`);
     - the model class names.
   
     The file is added to the `cargo test --test` lists of both workflows.
   - The crate's offline tests pass, and so do the live ML e2e files.
   - `cargo fmt --check`, `cargo +1.100.0 clippy --workspace --all-targets -- 
-D warnings` and `scripts/audit_no_stubs.sh` are clean.
   
   ### 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