viirya commented on a change in pull request #24531: [SPARK-27636][MLLIB]Remove 
cached RDD blocks after PIC execution
URL: https://github.com/apache/spark/pull/24531#discussion_r281052732
 
 

 ##########
 File path: 
mllib/src/main/scala/org/apache/spark/mllib/clustering/PowerIterationClustering.scala
 ##########
 @@ -337,7 +343,10 @@ object PowerIterationClustering extends Logging {
   def initDegreeVector(g: Graph[Double, Double]): Graph[Double, Double] = {
     val sum = g.vertices.values.sum()
     val v0 = g.vertices.mapValues(_ / sum)
-    Graph(VertexRDD(v0), g.edges)
+    val graph = Graph(VertexRDD(v0), g.edges)
+    materialize(graph)
+    g.unpersist()
 
 Review comment:
   Unpersisting the input Graph at `randomInit` and `initDegreeVector` is 
actually unpersisting the same Graph. I think it is better to unpersist it in 
`run`:
   
   ```scala
   def run(graph: Graph[Double, Double]): PowerIterationClusteringModel = {
       val w = normalize(graph)
       val w0 = initMode match {
         case "random" => randomInit(w)
         case "degree" => initDegreeVector(w)
       }
       w.unpersist()
       pic(w0)
     }
   ```
   
   It looks more reasonable, as it looks a bit strange that a function 
unpersists an input from outside.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to