spark-test commented on code in PR #60299:
URL: https://github.com/apache/spark/pull/60299#discussion_r4530981560
##########
mllib/src/test/scala/org/apache/spark/ml/regression/GBTRegressorSuite.scala:
##########
@@ -330,6 +330,9 @@ class GBTRegressorSuite extends MLTest with
DefaultReadWriteTest {
.setMaxDepth(2)
.setCheckpointInterval(5)
.setSeed(123)
+ assert(gbt.getIntermediateStorageLevel === "MEMORY_AND_DISK")
+ gbt.setIntermediateStorageLevel("DISK_ONLY")
Review Comment:
**Non-blocking (P2):** This test switches to `DISK_ONLY` before the fit. Its
assertions check only per-tree `maxDepth`, `checkpointInterval`, and `seed`,
which do not depend on where the caches live. The other tests this PR changes
have the same gap. The Scala `params` tests round-trip the getter and setter.
The `DecisionTreeRegressor` stump test compares against the RDD-based API,
which still trains at `MEMORY_AND_DISK`. The PySpark
`model.getIntermediateStorageLevel()` checks read the value that
`JavaEstimator._fit` copies on the Python side. No test fits at a non-default
level together with `cacheNodeIds` or a validation column. A later change could
stop passing the level in one trainer call, or revert one of the eight persist
and checkpointer sites to `MEMORY_AND_DISK`, and every test would still pass.
Users who chose `DISK_ONLY` to relieve executor memory would then silently get
`MEMORY_AND_DISK` caches. The manual smoke check in the PR description covers
this but is not in t
he repository. `ALSStorageSuite` ("default and non-default storage params set
correct RDD StorageLevels") shows that a listener can turn it into a test.
**Verification:**
- **Regression:** The new storage-level test fails if any one persist or
checkpointer site in the tree trainers is reverted to MEMORY_AND_DISK, if
either call from the GBT trainer into RandomForest.runBagged drops the level,
or if any one of the six estimators' calls into the trainers drops the level.
- **Behavior:** With a non-default level that uses disk, every RDD persisted
while each tree estimator fits reports the configured level, including the
node-ID caches of decision tree, random forest, and GBT fits and the GBT
validation caches. With the default level, every one reports MEMORY_AND_DISK.
##########
mllib/src/main/scala/org/apache/spark/ml/tree/impl/GradientBoostedTrees.scala:
##########
@@ -349,7 +352,7 @@ private[spark] object GradientBoostedTrees extends Logging {
// Cache input RDD for speedup during multiple passes.
val treePoints = TreePoint.convertToTreeRDD(
retaggedInput, splits, metadata)
- .persist(StorageLevel.MEMORY_AND_DISK)
+ .persist(intermediateStorageLevel)
Review Comment:
**Blocking (P1):** This persist, like the other persist and checkpointer
sites in the tree trainers, now takes any level the shared validator allows,
including `MEMORY_ONLY`, `MEMORY_ONLY_2`, `MEMORY_ONLY_SER`, and
`MEMORY_ONLY_SER_2`. Those levels have no disk fallback. If a `treePoints`
partition does not fit in storage memory, BlockManager keeps no copy of it. If
it is evicted later, for example to make room for `labelWithCounts`, it is
dropped. Either way, the next read recomputes it from the input plan. When the
training DataFrame is read from shuffle output with remote blocks (after a
join, aggregation, or repartition on a multi-executor cluster), the recomputed
partition can return the same rows in a different order, because
`ShuffleBlockFetcherIterator` queues remote fetches in random order.
The trainers pair caches by position: `treePoints.zip(firstCounts)`,
`convertToBaggedRDD(treePoints, ...).zip(predError)`,
`treePoints.zip(labelWithCounts)`, `updatePredictionError`,
`computeWeightedError`, and, with `cacheNodeIds`, `input.zip(nodeIds)` in
`RandomForest`. `RDD.zip` checks only element counts. After a reordered
recompute, the next tree is fit to pseudo-residuals that belong to other rows,
and the training and validation errors that drive early stopping use mismatched
predictions. The fit still reports success and returns a wrong model. Decision
trees and random forests with `cacheNodeIds` aggregate rows under other rows'
node IDs. Random forests with bootstrap or `subsamplingRate < 1` redraw per-row
subsample counts in the new row order, so the levels of one tree see different
bags. A decision tree without `cacheNodeIds` pairs no caches and is unaffected.
The default `MEMORY_AND_DISK` and every other level that uses disk keep a
stored copy, so those fits reread the
same rows in the same order, as before this PR.
**Recommended change:** At the start of RandomForest.run and
GradientBoostedTrees.boost, before the trainer reads its input or builds any
cache, reject an intermediateStorageLevel that does not use disk (MEMORY_ONLY,
MEMORY_ONLY_2, MEMORY_ONLY_SER, or MEMORY_ONLY_SER_2) with an
IllegalArgumentException. The message names intermediateStorageLevel and the
rejected level, and gives the reason: the tree trainers pair cached training
data with caches derived from it by position, so a cached partition must never
be dropped and recomputed. State that requirement in the documentation of the
six new setIntermediateStorageLevel setters in Scala and PySpark. Add tree
estimator tests showing that a memory-only level fails and that levels which
use disk still train.
**Why this works:** A level that uses disk writes a block to local disk when
it does not fit in memory or is evicted from it, so every later read of
treePoints or baggedInput returns the same rows in the same order, as on the
base branch. Rejecting levels without disk before any cache is built removes
the only supported way for ordinary memory pressure to make those caches
recompute. It also turns a silently wrong model into an error at fit time.
**Scope:** Add a check for disk-backed levels at the two tree trainer entry
points, document the requirement on the six new setters, and test both
rejection and acceptance.
**Compatibility:** These keep their current behavior: the default
MEMORY_AND_DISK path, every level that uses disk, the RDD-based mllib.tree
APIs, and every other estimator that uses intermediateStorageLevel.
**Risks:** Fits that set a memory-only level now fail, including fits that
would have trained correctly: fits whose input keeps its row order when
recomputed, and decision tree or random forest fits that neither cache node IDs
nor sample rows (bootstrap off and subsamplingRate 1.0), which pair no caches
by position and give every row the same count. One rule for all six estimators
keeps the check simple and independent of how each mode pairs its caches. These
levels are new for the tree estimators in this change, so no released workflow
depends on them. Choosing MEMORY_AND_DISK or MEMORY_AND_DISK_SER gives a
working fit, so no rollback flag is needed. The error appears when the
estimator is fit, not when the param is set, because the shared validator also
serves other estimators. A pipeline that sets a memory-only level therefore
fails at its first fit.
**Constraints:** Leave the shared HasIntermediateStorageLevel validator and
its description unchanged, because KMeans, ALS, LogisticRegression, LinearSVC,
and FMClassifier share it. Run the check at the start of both trainer entry
points, so a rejected fit builds no cache and trains no tree. When the label
column carries no class count, the decision tree and random forest classifiers
still scan it to count classes before they call the trainer. Keep the RDD-based
mllib.tree APIs on their MEMORY_AND_DISK default.
**Exclusions:**
- Recomputation of these caches after executor or disk loss is out of scope.
It can also misalign them on the base branch at MEMORY_AND_DISK, and this PR
does not change it.
**Success:** Fitting any of the six tree estimators with
intermediateStorageLevel set to MEMORY_ONLY, MEMORY_ONLY_2, MEMORY_ONLY_SER, or
MEMORY_ONLY_SER_2 fails before the trainer builds any cache or trains any tree,
with an IllegalArgumentException that names intermediateStorageLevel and says
the level must use disk. Fits with the default level, or with any level that
uses disk, train exactly as before this repair. The RDD-based mllib.tree APIs,
and the other estimators that share intermediateStorageLevel, accept the same
levels as before. The setIntermediateStorageLevel documentation of the six tree
estimators, in Scala and PySpark, says the level must use disk.
**Verification:**
- **Regression:** At each memory-only level, a fit of each of the six tree
estimators fails before training with the documented message, from Scala and
from PySpark, including a decision tree with cacheNodeIds enabled and a GBT
estimator with and without a validation indicator column.
- **Behavior:** Fitting a decision tree, a random forest, and a GBT
estimator at DISK_ONLY and at MEMORY_AND_DISK_SER succeeds and produces the
same model as the default level on the same data.
- **Compatibility:** KMeans and ALS still accept a memory-only
intermediateStorageLevel, and the RDD-based decision tree, random forest, and
GBT APIs still train with their default level.
--
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]