HyukjinKwon opened a new pull request, #347: URL: https://github.com/apache/spark-connect-rust/pull/347
### What changes were proposed in this pull request? [SPARK-61158](https://issues.apache.org/jira/browse/SPARK-61158): Delete the cached server model of a native LinearSVC or LogisticRegression fit when its last owner is dropped, as pyspark.ml does. - The cached model (`CachedModel` in `crates/spark-connect/src/ml.rs`) is now a shared reference. A fitted model, its clones and every DataFrame it transforms hold it. - `LogicalPlan::MlTransform` keeps the input plan and the owner of the cached model alive, because the input relation is sent inline. Every ML transform that takes an input keeps it, so a DataFrame derived from a model transform keeps the model alive too. - When the last owner drops, `CachedModelRef::drop` sends `MlCommand.Delete { obj_refs }` on the fitting session through the new `SparkSession::release_ml_objects`. The request runs on the shared runtime, and its result and errors are ignored, so the drop never blocks and never panics at interpreter exit or after the session is stopped. - Official `pyspark.ml` does the same: its `RemoteModelRef` calls `del_remote_cache` when the last reference goes, and a transformed DataFrame keeps its source transformer alive. - `docs/compatibility.md` describes the new lifetime. ### Why are the changes needed? A native model stayed in the server's ML cache for the whole session. Each fit added an entry to `MlCommand.GetCacheInfo` that nothing removed. Repro: fit `LinearSVC(maxIter=2)` ten times in one session, `del` each model, `gc.collect()`, then count `GetCacheInfo` entries. Ours gives 10. Official `pyspark.ml.classification.LinearSVC` gives 0. ### Does this PR introduce _any_ user-facing change? Yes. A native LinearSVC or LogisticRegression model's server cache entry is deleted when the last model, clone or transformed DataFrame that refers to it is dropped. Before, it lived until the session closed. Clones and lazy DataFrames still work after the model is dropped. ### How was this patch tested? - `linear_svc_model_is_deleted_from_the_server_when_its_last_owner_is_dropped` (`crates/spark-connect/tests/e2e_linear_svc.rs`) and `logistic_regression_model_is_deleted_from_the_server_when_its_last_owner_is_dropped` (`crates/spark-connect/tests/e2e_coverage.rs`) count `GetCacheInfo` after fits and drops, check that a clone, a lazy DataFrame, and a DataFrame of another model over the lazy one keep the model cached, and that the cache entry goes once the last of them is dropped. - `test_linear_svc_releases_its_cached_model_once_the_last_owner_is_gone` (`python/tests/test_dropin_e2e.py`) fits ten models, deletes them and collects the garbage, then checks the cache is back to its baseline. It also checks that a lazy transformed DataFrame collects after `del model`. - The tests of both crates, e2e included, against a local Spark 4.3.0 server (877 passed), the build of all tests, also with `wasm-udf`, the offline Python suites (2201 passed, 8 skipped), and the live drop-in, Arrow and ML suites (185 passed) and live cases (10 passed). rustfmt passes, and clippy reports no diagnostics in the changed lines. ### 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]
