spark-test commented on code in PR #60338:
URL: https://github.com/apache/spark/pull/60338#discussion_r4542688514
##########
python/pyspark/ml/tests/test_regression.py:
##########
@@ -160,18 +175,26 @@ def test_linear_regression(self):
.sortWithinPartitions("weight")
)
+ self.assertEqual(LinearRegression().getIntermediateStorageLevel(),
"MEMORY_AND_DISK")
lr = LinearRegression(
regParam=0.0,
maxIter=2,
solver="normal",
weightCol="weight",
+ intermediateStorageLevel="DISK_ONLY",
Review Comment:
**Non-blocking (P2):** This fit pins `solver="normal"`, so
`LinearRegression.train` returns through `trainWithNormal`
(`LinearRegression.scala:358-360`) before `trainImpl` persists the training
blocks at the configured level (line 557). `DISK_ONLY` therefore never reaches
the only place LinearRegression uses it. The
`model.getIntermediateStorageLevel()` check after the fit would pass whatever
training did, because the estimator copies its params to the model. The Scala
`params` test sets the level without fitting, and no other test sets it, so no
test runs LinearRegression's configurable cache with a non-default level, in
classic PySpark, Spark Connect or Scala.
The `DISK_ONLY` fits for `AFTSurvivalRegression`, `FMRegressor` and
`IsotonicRegression` in this PR, and the classifier fits in
`test_intermediate_storage_level`, do reach their persist calls. A break that
only a non-default level triggers would fail a test for those estimators, but
not for LinearRegression. One example is persisting the blocks a second time at
a different level, which `RDD.persist` rejects.
Consider adding a separate `DISK_ONLY` fit that pins an iterative solver
(for example `solver="l-bfgs"`) on data whose label varies, next to this one so
it also runs under Spark Connect. Leave this fit as it is, because its expected
coefficients and `objectiveHistory == [0.0]` depend on the normal solver.
**Verification:**
- **Regression:** With a temporary edit that persists LinearRegression's
training blocks a second time at MEMORY_AND_DISK, the new DISK_ONLY fit on the
iterative solver must fail in classic PySpark and under Spark Connect, because
Spark rejects a second persist at a different level. Without the edit it must
pass.
- **Inspection:** Check that the new fit cannot reach the normal-equation or
constant-label returns in LinearRegression's train method: it sets solver
l-bfgs or loss huber explicitly instead of relying on solver auto, and its
label varies across rows. Check also that the existing normal-solver fit and
its assertions are unchanged.
--
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]