[GitHub] spark pull request #15963: [SPARK-18471][MLLIB] In LBFGS, avoid sending huge...

2016-11-28 Thread AnthonyTruchet
Github user AnthonyTruchet closed the pull request at:

https://github.com/apache/spark/pull/15963


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #15963: [SPARK-18471][MLLIB] In LBFGS, avoid sending huge...

2016-11-21 Thread srowen
Github user srowen commented on a diff in the pull request:

https://github.com/apache/spark/pull/15963#discussion_r88906149
  
--- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/optimization/LBFGS.scala ---
@@ -241,16 +241,27 @@ object LBFGS extends Logging {
   val bcW = data.context.broadcast(w)
   val localGradient = gradient
 
-  val (gradientSum, lossSum) = data.treeAggregate((Vectors.zeros(n), 
0.0))(
-  seqOp = (c, v) => (c, v) match { case ((grad, loss), (label, 
features)) =>
-val l = localGradient.compute(
-  features, label, bcW.value, grad)
+  /** Given (current accumulated gradient, current loss) and (label, 
features)
--- End diff --

Nit: just use `//` for two lines of comment. Really `/**` (vs `/*`) is for 
javadoc.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #15963: [SPARK-18471][MLLIB] In LBFGS, avoid sending huge...

2016-11-21 Thread srowen
Github user srowen commented on a diff in the pull request:

https://github.com/apache/spark/pull/15963#discussion_r88906249
  
--- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/optimization/LBFGS.scala ---
@@ -241,16 +241,27 @@ object LBFGS extends Logging {
   val bcW = data.context.broadcast(w)
   val localGradient = gradient
 
-  val (gradientSum, lossSum) = data.treeAggregate((Vectors.zeros(n), 
0.0))(
-  seqOp = (c, v) => (c, v) match { case ((grad, loss), (label, 
features)) =>
-val l = localGradient.compute(
-  features, label, bcW.value, grad)
+  /** Given (current accumulated gradient, current loss) and (label, 
features)
+   * tuples, updates the current gradient and current loss
+   */
+  val seqOp = (c: (Vector, Double), v: (Double, Vector)) =>
+(c, v) match {
+  case ((grad, loss), (label, features)) =>
+val l = localGradient.compute(features, label, bcW.value, grad)
 (grad, loss + l)
-  },
-  combOp = (c1, c2) => (c1, c2) match { case ((grad1, loss1), 
(grad2, loss2)) =>
+}
+
+  // Adds two (gradient, loss) tuples
+  val combOp = (c1: (Vector, Double), c2: (Vector, Double)) =>
+(c1, c2) match { case ((grad1, loss1), (grad2, loss2)) =>
 axpy(1.0, grad2, grad1)
 (grad1, loss1 + loss2)
-  })
+   }
+
+  val (gradientSum, lossSum) = data.mapPartitions { it => {
--- End diff --

Nit: the second brace and its match are redundant


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #15963: [SPARK-18471][MLLIB] In LBFGS, avoid sending huge...

2016-11-21 Thread AnthonyTruchet
GitHub user AnthonyTruchet opened a pull request:

https://github.com/apache/spark/pull/15963

[SPARK-18471][MLLIB] In LBFGS, avoid sending huge vectors of 0

## What changes were proposed in this pull request?

CostFun used to send a dense vector of zeroes as a closure in a
treeAggregate call. To avoid that, we replace treeAggregate by
mapPartition + treeReduce, creating a zero vector inside the mapPartition
block in-place.

## How was this patch tested?

Unit test for module mllib run locally for correctness.

As for performance we run an heavy optimization on our production data (50 
iterations on 128 MB weight vectors) and have seen significant decrease in 
terms both of runtime and container being killed by lack of off-heap memory.


You can merge this pull request into a Git repository by running:

$ git pull https://github.com/criteo-forks/spark master

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/spark/pull/15963.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #15963


commit d5d110b8fc0d7165cce116c1e8342ce7aca2467b
Author: Eugene Kharitonov 
Date:   2016-10-14T11:25:34Z

[SPARK-18471][MLLIB] In LBFGS, avoid sending huge vectors of 0

CostFun used to send a dense vector of zeroes as a closure in a
treeAggregate call. To avoid that, we replace treeAggregate by
mapPartition + treeReduce, creating a zero vector inside the mapPartition
block in-place.

commit 7095bc2c568564ebc4584c1101cb94801079d1bd
Author: Anthony Truchet 
Date:   2016-11-18T12:36:00Z

Style fix according to reviewers' feedback

commit 011a8d77cac26f820c3cecda1c28e623a64f803b
Author: Anthony Truchet 
Date:   2016-11-21T12:26:10Z

Merge pull request #11 from AnthonyTruchet/ENG-17719-lbfgs-only

[SPARK-18471][MLLIB] In LBFGS, avoid sending huge vectors of 0




---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org