You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by mgaido91 <gi...@git.apache.org> on 2017/11/07 16:48:09 UTC

[GitHub] spark pull request #19685: [SPARK-19759][ML] not using blas in ALSModel.pred...

GitHub user mgaido91 opened a pull request:

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

    [SPARK-19759][ML] not using blas in ALSModel.predict for optimization

    ## What changes were proposed in this pull request?
    
    In `ALS.predict` currently we are using `blas.sdot` function to perform a dot product on two `Seq`s. It turns out that this is not the most efficient way.
    
    I used the following code to compare the implementations:
    
    ```
    def time[R](block: => R): Unit = {
        val t0 = System.nanoTime()
        block
        val t1 = System.nanoTime()
        println("Elapsed time: " + (t1 - t0) + "ns")
    }
    val r = new scala.util.Random(100)
    val input = (1 to 500000).map(_ => (1 to 100).map(_ => r.nextFloat).toSeq)
    def f(a:Seq[Float], b:Seq[Float]): Float = {
        var r = 0.0f
        for(i <- 0 until a.length) {
            r+=a(i)*b(i)
        }
        r
    }
    import com.github.fommil.netlib.BLAS.{getInstance => blas}
    val b = (1 to 100).map(_ => r.nextFloat).toSeq
    time { input.foreach(a=>blas.sdot(100, a.toArray, 1, b.toArray, 1)) }
    // on average it takes 2968718815 ns
    time { input.foreach(a=>f(a,b)) }
    // on average it takes 515510185 ns
    ``` 
    
    Thus this PR proposes the old-style for loop implementation for performance reasons.
    
    ## How was this patch tested?
    
    existing UTs


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

    $ git pull https://github.com/mgaido91/spark SPARK-19759

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

    https://github.com/apache/spark/pull/19685.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 #19685
    
----
commit 8b0add68ddf68939c0f5ac19836f9b3b9cc58432
Author: Marco Gaido <mg...@hortonworks.com>
Date:   2017-11-07T16:29:23Z

    [SPARK-19759][ML] not using blas in ALSModel.predict for optimization

----


---

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


[GitHub] spark pull request #19685: [SPARK-19759][ML] not using blas in ALSModel.pred...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

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


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    **[Test build #83551 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/83551/testReport)** for PR 19685 at commit [`8b0add6`](https://github.com/apache/spark/commit/8b0add68ddf68939c0f5ac19836f9b3b9cc58432).


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    **[Test build #83551 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/83551/testReport)** for PR 19685 at commit [`8b0add6`](https://github.com/apache/spark/commit/8b0add68ddf68939c0f5ac19836f9b3b9cc58432).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    **[Test build #83598 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/83598/testReport)** for PR 19685 at commit [`4867345`](https://github.com/apache/spark/commit/486734502026c2eb2a7a92d12e12da676013d7dd).


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/83551/
    Test PASSed.


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by srowen <gi...@git.apache.org>.
Github user srowen commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    Merged to master


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    **[Test build #83598 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/83598/testReport)** for PR 19685 at commit [`4867345`](https://github.com/apache/spark/commit/486734502026c2eb2a7a92d12e12da676013d7dd).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark pull request #19685: [SPARK-19759][ML] not using blas in ALSModel.pred...

Posted by WeichenXu123 <gi...@git.apache.org>.
Github user WeichenXu123 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19685#discussion_r149554146
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala ---
    @@ -289,9 +289,11 @@ class ALSModel private[ml] (
     
       private val predict = udf { (featuresA: Seq[Float], featuresB: Seq[Float]) =>
         if (featuresA != null && featuresB != null) {
    -      // TODO(SPARK-19759): try dot-producting on Seqs or another non-converted type for
    -      // potential optimization.
    -      blas.sdot(rank, featuresA.toArray, 1, featuresB.toArray, 1)
    +      var dotProduct = 0.0f
    +      for(i <- 0 until rank) {
    --- End diff --
    
    You should `while` instead of `for`


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by mgaido91 <gi...@git.apache.org>.
Github user mgaido91 commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    @srowen I tried enabling native BLAS, but native BLAS implementation is still much slower: average on 10 runs is 2529,922753 ms against 515,510185 ms of the for loop. As a reference, I am using a OSX 2.5 GHz Intel Core i7.
    What is worth to notice, though, is that I tried to run the same code but performing the `toArray` before, thus excluding its time from the computation. In this case, native BLAS implementation is much faster: 100,969697 ms. Thus here the "performance killer" is the conversion to array, as you pointed out.
    
    @WeichenXu123 In the description od the PR and here you can see the tests I made. Do you think something else is needed?


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/83598/
    Test PASSed.


---

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


[GitHub] spark issue #19685: [SPARK-19759][ML] not using blas in ALSModel.predict for...

Posted by WeichenXu123 <gi...@git.apache.org>.
Github user WeichenXu123 commented on the issue:

    https://github.com/apache/spark/pull/19685
  
    Have you made some test to check the performance difference for this ?


---

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