Skip to content

Commit

Permalink
[SPARK-26228][MLLIB] OOM issue encountered when computing Gramian matrix
Browse files Browse the repository at this point in the history
Avoid memory problems in closure cleaning when handling large Gramians (>= 16K rows/cols) by using null as zeroValue

Existing tests.
Note that it's hard to test the case that triggers this issue as it would require a large amount of memory and run a while. I confirmed locally that a 16K x 16K Gramian failed with tons of driver memory before, and didn't fail upfront after this change.

Closes apache#23600 from srowen/SPARK-26228.

Authored-by: Sean Owen <[email protected]>
Signed-off-by: Sean Owen <[email protected]>
(cherry picked from commit 6dcad38)
Signed-off-by: Sean Owen <[email protected]>
  • Loading branch information
srowen committed Jan 23, 2019
1 parent 10d7713 commit f36d0c5
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,25 @@ class RowMatrix @Since("1.0.0") (
val nt = if (n % 2 == 0) ((n / 2) * (n + 1)) else (n * ((n + 1) / 2))

// Compute the upper triangular part of the gram matrix.
val GU = rows.treeAggregate(new BDV[Double](nt))(
seqOp = (U, v) => {
val GU = rows.treeAggregate(null.asInstanceOf[BDV[Double]])(
seqOp = (maybeU, v) => {
val U =
if (maybeU == null) {
new BDV[Double](nt)
} else {
maybeU
}
BLAS.spr(1.0, v, U.data)
U
}, combOp = (U1, U2) => U1 += U2)
}, combOp = (U1, U2) =>
if (U1 == null) {
U2
} else if (U2 == null) {
U1
} else {
U1 += U2
}
)

RowMatrix.triuToFull(n, GU.data)
}
Expand Down

0 comments on commit f36d0c5

Please sign in to comment.