Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/18313#discussion_r129178830
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/tuning/CrossValidator.scala ---
@@ -113,15 +122,28 @@ class CrossValidator @Since("1.2.0") (@Since("1.4.0")
override val uid: String)
// multi-model training
logDebug(s"Train split $splitIndex with multiple sets of
parameters.")
val models = est.fit(trainingDataset,
epm).asInstanceOf[Seq[Model[_]]]
- trainingDataset.unpersist()
+
var i = 0
while (i < numModels) {
// TODO: duplicate evaluator to take extra params from input
val metric = eval.evaluate(models(i).transform(validationDataset,
epm(i)))
logDebug(s"Got metric $metric for model trained with ${epm(i)}.")
+ if (isDefined(modelPreservePath)) {
+ models(i) match {
+ case w: MLWritable =>
+ // e.g. maxIter-5-regParam-0.001-split0-0.859
+ val fileName = epm(i).toSeq.map(p => p.param.name + "-" +
p.value).sorted
+ .mkString("-") + s"-split$splitIndex-${math.rint(metric *
1000) / 1000}"
+ w.save(new Path($(modelPreservePath), fileName).toString)
+ case _ =>
+ // for third-party algorithms
+ logWarning(models(i).uid + " did not implement MLWritable.
Serialization omitted.")
+ }
+ }
metrics(i) += metric
--- End diff --
I agree that 80 models in driver memory sounds like a lot. However, we
already are holding that many in driver memory at once in ```val models =
est.fit(trainingDataset, epm)```, so that should not be a problem for current
use cases.
Scaling to large models which do not fit in memory is a different problem,
but your PR does bring up the issue that exposing something like ```models:
Seq[...]``` could cause problems in the future if we want to scale more. I'd
suggest 2 things:
* The models could be exposed via a getter, rather than a val. In the
future, if the models are not available, the getter could throw a nice
exception.
* In the future, we could add the Param which you are suggesting for
dumping the models to some directory during training. Feel free to preserve
this PR for that, but I think this PR is overkill for most users' needs.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]