Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5330#discussion_r28267765
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/tree/model/treeEnsembleModels.scala 
---
    @@ -131,34 +131,26 @@ class GradientBoostedTreesModel(
         val numIterations = trees.length
         val evaluationArray = Array.fill(numIterations)(0.0)
     
    -    var predictionAndError: RDD[(Double, Double)] = remappedData.map { i =>
    -      val pred = treeWeights(0) * trees(0).predict(i.features)
    -      val error = loss.computeError(pred, i.label)
    -      (pred, error)
    -    }
    +    var predictionAndError = 
GradientBoostedTreesModel.computeInitialPredictionAndError(
    +      remappedData, treeWeights(0), trees(0), loss)
    +
         evaluationArray(0) = predictionAndError.values.mean()
     
    -    // Avoid the model being copied across numIterations.
         val broadcastTrees = sc.broadcast(trees)
    -    val broadcastWeights = sc.broadcast(treeWeights)
    -
         (1 until numIterations).map { nTree =>
           predictionAndError = 
remappedData.zip(predictionAndError).mapPartitions { iter =>
             val currentTree = broadcastTrees.value(nTree)
    -        val currentTreeWeight = broadcastWeights.value(nTree)
    -        iter.map {
    -          case (point, (pred, error)) => {
    -            val newPred = pred + currentTree.predict(point.features) * 
currentTreeWeight
    -            val newError = loss.computeError(newPred, point.label)
    -            (newPred, newError)
    -          }
    +        val currentTreeWeight = treeWeights(nTree)
    --- End diff --
    
    We should make a local (shallow) copy of treeWeights before the map, within 
this method:
    ```
    val localTreeWeights = treeWeights
    ```
    Referencing treeWeights, a member of the class, will actually make the 
entire class get serialized by the ClosureCleaner.  Assigning it to a local val 
fixes that.


---
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]

Reply via email to