Github user d0evi1 commented on a diff in the pull request:
https://github.com/apache/spark/pull/18034#discussion_r117607822
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/clustering/LDAModel.scala ---
@@ -468,7 +469,16 @@ object LocalLDAModel extends Loader[LocalLDAModel] {
val topics = Range(0, k).map { topicInd =>
Data(Vectors.dense((topicsDenseMatrix(::, topicInd).toArray)),
topicInd)
}
-
spark.createDataFrame(topics).repartition(1).write.parquet(Loader.dataPath(path))
+
+ val bufferSize = Utils.byteStringAsBytes(
+ spark.conf.get("spark.kryoserializer.buffer.max", "64m"))
+ // We calculate the approximate size of the model
+ // We only calculate the array size, considering an
+ // average string size of 15 bytes, the formula is:
+ // (floatSize * vectorSize + 15) * numWords
+ val approxSize = (4L * k + 15) * topicsMatrix.numRows
+ val nPartitions = ((approxSize / bufferSize) + 1).toInt
+
spark.createDataFrame(topics).repartition(nPartitions).write.parquet(Loader.dataPath(path))
--- End diff --
I've read mllib's online lda's code implements and the paper.
i found a simple way to test it , u can try this code snippet, simulation a
matrix to save:
`
val vocabSize = 500000
val k = 300
val random = new Random()
val topicsDenseMatrix = DenseMatrix.fill[Double](vocabSize,
k)(random.nextDouble())
`
if the spark's configure param not set ok, the repartition(1) way will
fail. in the raw implement, every row has has a very long Vector. this will
cause the seralize problem.
another problem is why not to save the transposition matrix?
Can someone check it's raw purpose(use repartition(1))? thanks!
---
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]