zhengruifeng commented on a change in pull request #27052: [SPARK-30390][MLLIB] 
Avoid double caching in mllib.KMeans#runWithWeights.
URL: https://github.com/apache/spark/pull/27052#discussion_r362149460
 
 

 ##########
 File path: mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeans.scala
 ##########
 @@ -232,7 +232,10 @@ class KMeans private (
     val zippedData = data.zip(norms).map { case ((v, w), norm) =>
       (new VectorWithNorm(v, norm), w)
     }
-    zippedData.persist(StorageLevel.MEMORY_AND_DISK)
+
+    if (data.getStorageLevel == StorageLevel.NONE) {
+      zippedData.persist(StorageLevel.MEMORY_AND_DISK)
+    }
 
 Review comment:
   what about caching norms if data is already cached? like this:
   
   ```scala
   val handlePersistence = data.getStorageLevel == StorageLevel.NONE
   val norms = ...
   val zippedData = if (handlePersistence) {
      data.zip(norms).map { case ((v, w), norm) =>
         (new VectorWithNorm(v, norm), w)
       }.persist(StorageLevel.MEMORY_AND_DISK)
   } else {
        norms.persist(StorageLevel.MEMORY_AND_DISK)
        data.zip(norms).map { case ((v, w), norm) =>
           (new VectorWithNorm(v, norm), w)
        }
   }
   
   ...
   
   
   if (handlePersistence) {
      zippedData.unpersist()
   } else {
      norms.unpersist()
   }
   
   ```

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