Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/19122#discussion_r136924008
--- Diff: python/pyspark/ml/tuning.py ---
@@ -255,18 +257,24 @@ def _fit(self, dataset):
randCol = self.uid + "_rand"
df = dataset.select("*", rand(seed).alias(randCol))
metrics = [0.0] * numModels
+
+ pool = ThreadPool(processes=min(self.getParallelism(), numModels))
+
for i in range(nFolds):
validateLB = i * h
validateUB = (i + 1) * h
condition = (df[randCol] >= validateLB) & (df[randCol] <
validateUB)
- validation = df.filter(condition)
+ validation = df.filter(condition).cache()
train = df.filter(~condition)
- models = est.fit(train, epm)
- for j in range(numModels):
- model = models[j]
+
+ def singleTrain(index):
+ model = est.fit(train, epm[index])
# TODO: duplicate evaluator to take extra params from input
- metric = eva.evaluate(model.transform(validation, epm[j]))
- metrics[j] += metric/nFolds
+ metric = eva.evaluate(model.transform(validation,
epm[index]))
+ metrics[index] += metric/nFolds
+
+ pool.map(singleTrain, range(numModels))
--- End diff --
Can we have a benchmark for this? Can Python GIL a problem here to
downgrade performance in the end?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]