You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "pan3793 (via GitHub)" <gi...@apache.org> on 2025/02/17 09:58:41 UTC

[PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

pan3793 opened a new pull request, #49986:
URL: https://github.com/apache/spark/pull/49986

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'common/utils/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   This PR proposes introducing a new configuration `spark.ml.allowNativeBlas`, when set to `false`, Spark always uses Java BLAS even when the native library `openblas` or `mkl` is available on the machine.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   Currently, there are many places in the Spark codebase hardcoded to call `BLAS.nativeBLAS`, when `NativeBLAS` is available, it always uses `JNIBLAS`, this generally is a good idea, but I found some negative cases in our internal ML workloads, that `JavaBLAS` is faster than `JNIBLAS`, this might be caused by the native library (e.g. `mkl` or `openblas`) bugs or does not optimized for some hardware. Given that, I think we should allow users to disable `NativeBLAS` explicitly.
   
   The proposed `spark.ml.allowNativeBlas` configuration does not strictly follow the Spark configuration system because the `sparkConf` is not always available on the caller side of `BLAS.nativeBLAS`
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
   
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   Add a new feature, but the default value keeps the current behavior.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   Manual tests, will supply more context after reaching a consensus on how to expose the configuration to end users.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   No.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1958955170


##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -3436,6 +3437,20 @@ object SparkContext extends Logging {
     supplement(DRIVER_JAVA_OPTIONS)
     supplement(EXECUTOR_JAVA_OPTIONS)
   }
+
+  private def supplementBlasOptions(conf: SparkConf): Unit = {
+    conf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>
+      def supplement(key: OptionalConfigEntry[String]): Unit = {

Review Comment:
   This is repeated so many times now - I wonder if a simple refactor is in order to have one 'supplement' function?



##########
mllib-local/src/main/scala/org/apache/spark/ml/linalg/BLAS.scala:
##########
@@ -39,8 +39,11 @@ private[spark] object BLAS extends Serializable {
   // For level-3 routines, we use the native BLAS.
   private[spark] def nativeBLAS: NetlibBLAS = {
     if (_nativeBLAS == null) {
-      _nativeBLAS =
-        try { NetlibNativeBLAS.getInstance } catch { case _: Throwable => javaBLAS }
+      _nativeBLAS = System.getProperty("spark.ml.allowNativeBlas", "true") match {

Review Comment:
   This has to be a sys property because of how early it has to be initialized?



##########
resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala:
##########
@@ -1049,6 +1049,10 @@ private[spark] class Client(
 
     javaOpts += s"-Djava.net.preferIPv6Addresses=${Utils.preferIPv6}"
 
+    sparkConf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>
+      javaOpts += s"-Dspark.ml.allowNativeBlas=$allowNativeBlas"

Review Comment:
   Do other resource managers like k8s need this? not sure



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #49986:
URL: https://github.com/apache/spark/pull/49986#issuecomment-2817990487

   Kindly ping @WeichenXu123


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r2032334933


##########
mllib-local/pom.xml:
##########
@@ -66,6 +66,11 @@
       <groupId>org.apache.spark</groupId>
       <artifactId>spark-tags_${scala.binary.version}</artifactId>
     </dependency>
+    <dependency>

Review Comment:
   I am still a bit worried about the dependency change.
   Defer to @WeichenXu123 's review.



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r2032381308


##########
mllib-local/pom.xml:
##########
@@ -66,6 +66,11 @@
       <groupId>org.apache.spark</groupId>
       <artifactId>spark-tags_${scala.binary.version}</artifactId>
     </dependency>
+    <dependency>

Review Comment:
   the dep change can be eliminated if logging is unnecessary.



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1958946765


##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -3436,6 +3437,20 @@ object SparkContext extends Logging {
     supplement(DRIVER_JAVA_OPTIONS)
     supplement(EXECUTOR_JAVA_OPTIONS)
   }
+
+  private def supplementBlasOptions(conf: SparkConf): Unit = {
+    conf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>

Review Comment:
   I am not sure whether we can use a env variable like `MKL_NUM_THREADS=1` `OPENBLAS_NUM_THREADS=1`



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1960038301


##########
mllib/src/main/scala/org/apache/spark/mllib/linalg/BLAS.scala:
##########
@@ -17,44 +17,14 @@
 
 package org.apache.spark.mllib.linalg
 
-import dev.ludovic.netlib.blas.{BLAS => NetlibBLAS, JavaBLAS => NetlibJavaBLAS, NativeBLAS => NetlibNativeBLAS}
-
 import org.apache.spark.internal.Logging
+import org.apache.spark.ml.linalg.BLAS.{getBLAS, nativeBLAS}
 
 /**
  * BLAS routines for MLlib's vectors and matrices.
  */
 private[spark] object BLAS extends Serializable with Logging {
 
-  @transient private var _javaBLAS: NetlibBLAS = _
-  @transient private var _nativeBLAS: NetlibBLAS = _

Review Comment:
   remove the duplicated instance creation and call `org.apache.spark.ml.linalg.BLAS`



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #49986:
URL: https://github.com/apache/spark/pull/49986#issuecomment-2781859884

   @luhenry thanks for your review and approval.
   @srowen @zhengruifeng would appreciate it if you could have another look. also cc @LuciferYang @yaooqinn 


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1959011315


##########
resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala:
##########
@@ -1049,6 +1049,10 @@ private[spark] class Client(
 
     javaOpts += s"-Djava.net.preferIPv6Addresses=${Utils.preferIPv6}"
 
+    sparkConf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>
+      javaOpts += s"-Dspark.ml.allowNativeBlas=$allowNativeBlas"

Review Comment:
   the impl almost follows how we process `java.net.preferIPv6Addresses`, I will do test on K8s and back here.



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #49986:
URL: https://github.com/apache/spark/pull/49986#issuecomment-2666058013

   Find some issues during work on this PR:
   1) `spark.executor.extraJavaOptions` forbids shipping value contains `-Dspark`, this also affects SPARK-47383 (https://github.com/apache/spark/pull/45504#issuecomment-2665957194). To fix that, we can either give an exception to `spark.ml.allowNativeBlas` when checking `spark.executor.extraJavaOptions` or choose a different prefix, e.g. `netlib.allowNativeBlas`
   2) 
     - mllib/src/main/scala/org/apache/spark/mllib/linalg/LAPACK.scala


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1958982565


##########
mllib-local/src/main/scala/org/apache/spark/ml/linalg/BLAS.scala:
##########
@@ -39,8 +39,11 @@ private[spark] object BLAS extends Serializable {
   // For level-3 routines, we use the native BLAS.
   private[spark] def nativeBLAS: NetlibBLAS = {
     if (_nativeBLAS == null) {
-      _nativeBLAS =
-        try { NetlibNativeBLAS.getInstance } catch { case _: Throwable => javaBLAS }
+      _nativeBLAS = System.getProperty("spark.ml.allowNativeBlas", "true") match {

Review Comment:
   Ideally, I think we should propagate the conf via `SparkConf`, and change the method signature to
   
   ```patch
   - def nativeBLAS: NetlibBLAS
   + def nativeBLAS(allowNative: Boolean): NetlibBLAS
   ```
   
   but I found many places call `BLAS.nativeBLAS` where `SparkConf` is unavailable, so I proposed to use sys property.



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #49986:
URL: https://github.com/apache/spark/pull/49986#issuecomment-2662640045

   cc @zhengruifeng @panbingkun, could you please take a look? and do you have a better idea of how to implement the configuration?


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #49986:
URL: https://github.com/apache/spark/pull/49986#issuecomment-3927041539

   close and in favor SPARK-55605


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1958980059


##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -3436,6 +3437,20 @@ object SparkContext extends Logging {
     supplement(DRIVER_JAVA_OPTIONS)
     supplement(EXECUTOR_JAVA_OPTIONS)
   }
+
+  private def supplementBlasOptions(conf: SparkConf): Unit = {
+    conf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>

Review Comment:
   I guess I mean, does this have to propagate via sys property at all versus just being used as a config in the code directly? But probably it is hard to plumb through access to the config object 



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1959011507


##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -3436,6 +3437,20 @@ object SparkContext extends Logging {
     supplement(DRIVER_JAVA_OPTIONS)
     supplement(EXECUTOR_JAVA_OPTIONS)
   }
+
+  private def supplementBlasOptions(conf: SparkConf): Unit = {
+    conf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>
+      def supplement(key: OptionalConfigEntry[String]): Unit = {

Review Comment:
   thanks for suggestion, will do



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1960063444


##########
resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala:
##########
@@ -1049,6 +1049,10 @@ private[spark] class Client(
 
     javaOpts += s"-Djava.net.preferIPv6Addresses=${Utils.preferIPv6}"
 
+    sparkConf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>
+      javaOpts += s"-Dspark.ml.allowNativeBlas=$allowNativeBlas"

Review Comment:
   > Do other resource managers like k8s need this? not sure
   
   K8s does not need that change.
   
   #### Spark on YARN
   
   the code appends `-Dspark.ml.allowNativeBlas=...` to YARN AM process command, we should assemble a java command to let YARN RM know how to bootstrap the process
   
   #### Spark on K8s
   
   - client mode, no driver Pod
   - cluster mode, run `spark-submit`(which carries all Java options from local `spark-submit`) in the driver Pod
   
   so it does not need to append those Java options again.



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1960046637


##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -3436,6 +3437,20 @@ object SparkContext extends Logging {
     supplement(DRIVER_JAVA_OPTIONS)
     supplement(EXECUTOR_JAVA_OPTIONS)
   }
+
+  private def supplementBlasOptions(conf: SparkConf): Unit = {
+    conf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>
+      def supplement(key: OptionalConfigEntry[String]): Unit = {

Review Comment:
   refactored by extracting a common method `supplementJavaOpts`



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #49986:
URL: https://github.com/apache/spark/pull/49986#issuecomment-2664384195

   I think this PR needs reviews from @srowen @WeichenXu123 and @luhenry 
   
   


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1958986727


##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -3436,6 +3437,20 @@ object SparkContext extends Logging {
     supplement(DRIVER_JAVA_OPTIONS)
     supplement(EXECUTOR_JAVA_OPTIONS)
   }
+
+  private def supplementBlasOptions(conf: SparkConf): Unit = {
+    conf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>

Review Comment:
   @srowen I replied in https://github.com/apache/spark/pull/49986#discussion_r1958982565



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1960034433


##########
docs/ml-linalg-guide.md:
##########
@@ -46,8 +46,7 @@ The installation should be done on all nodes of the cluster. Generic version of
 
 For Debian / Ubuntu:
 ```
-sudo apt-get install libopenblas-base
-sudo update-alternatives --config libblas.so.3
+sudo apt-get install libopenblas-dev

Review Comment:
   `libopenblas-base` is removed in Debian 12 and Ubuntu 24.04, `libopenblas-dev` should be used instead.
   
   https://github.com/luhenry/netlib/blob/6835050840ead1a724e2f305875c92d7cc21f834/.github/workflows/build-and-test.yml#L31
   
   also `update-alternatives --config libblas.so.3` does not work, and it's variant in different CPU-arch OS.
   
   ```
   root@0bef5c80cdaa:/# update-alternatives --config libblas.so.3
   update-alternatives: error: no alternatives for libblas.so.3
   ```
   
   Given it already allows using `-Ddev.ludovic.netlib.lapack.nativeLib=...` to choose the native libraries, I would suggest eliminating how to use `alternatives` to manage the OS default library in our docs.



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1960040676


##########
mllib/src/main/scala/org/apache/spark/mllib/linalg/ARPACK.scala:
##########
@@ -19,10 +19,13 @@ package org.apache.spark.mllib.linalg
 
 import dev.ludovic.netlib.arpack.{ARPACK => NetlibARPACK, JavaARPACK => NetlibJavaARPACK, NativeARPACK => NetlibNativeARPACK}
 
+import org.apache.spark.internal.Logging
+import org.apache.spark.util.SparkEnvUtils
+
 /**
  * ARPACK routines for MLlib's vectors and matrices.
  */
-private[spark] object ARPACK extends Serializable {
+private[spark] object ARPACK extends Serializable with Logging {

Review Comment:
   should I move `ARPACK` and `LAPACK` to `mllib-local`, to align with `BLAS`?



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #49986:
URL: https://github.com/apache/spark/pull/49986#issuecomment-2662622310

   the current approach works with `spark-submit`
   ```
   spark-submit --conf spark.ml.allowNativeBlas=false ...
   ```
   
   but does not work with creating embedded `SparkContext` in user code, unless the user modifies their Java command options.
   ```
   java -Dspark.ml.allowNativeBlas=false ...
   ```
   


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on PR #49986:
URL: https://github.com/apache/spark/pull/49986#issuecomment-2666214616

   @srowen I addressed your previous comments(replied inline in each thread) and found some other issues during work on this PR:
   1) `spark.executor.extraJavaOptions` forbids shipping value contains `-Dspark`, this also affects SPARK-47383 (https://github.com/apache/spark/pull/45504#issuecomment-2665957194). To fix that, we can either give an exception to `spark.ml.allowNativeBlas` when checking `spark.executor.extraJavaOptions` or choose a different prefix, e.g. `netlib.allowNativeBlas`
   2) In addition to `mllib-local/src/main/scala/org/apache/spark/ml/linalg/BLAS.scala`, I found other three places that need to modify
      - `mllib/src/main/scala/org/apache/spark/mllib/linalg/BLAS.scala`
      - `mllib/src/main/scala/org/apache/spark/mllib/linalg/ARPACK.scala`
      - `mllib/src/main/scala/org/apache/spark/mllib/linalg/LAPACK.scala`
   
      I'm not sure if we want to have 3 configurations(e.g. `spark.ml.allowNativeBlas`, `spark.ml.allowNativeArpack`, `spark.ml.allowNativeLapack`) or just a single one `spark.ml.allowNativeBlas`(or a better name?)
   3) the official Spark docker image does not install the BLAS native libraries, should we install them?
   
   would be great if you could have another look, thank you in advance.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1958982565


##########
mllib-local/src/main/scala/org/apache/spark/ml/linalg/BLAS.scala:
##########
@@ -39,8 +39,11 @@ private[spark] object BLAS extends Serializable {
   // For level-3 routines, we use the native BLAS.
   private[spark] def nativeBLAS: NetlibBLAS = {
     if (_nativeBLAS == null) {
-      _nativeBLAS =
-        try { NetlibNativeBLAS.getInstance } catch { case _: Throwable => javaBLAS }
+      _nativeBLAS = System.getProperty("spark.ml.allowNativeBlas", "true") match {

Review Comment:
   Ideally, I think we should propagate the conf via `SparkConf`, and change the method signature to
   
   ```patch
   - def nativeBLAS: NetlibBLAS
   + def nativeBLAS(allowNative: Boolean): NetlibBLAS
   ```
   
   but I found many places call `BLAS.nativeBLAS` where `SparkConf` is unavailable, so I propose to use a sys property.



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 commented on code in PR #49986:
URL: https://github.com/apache/spark/pull/49986#discussion_r1958978004


##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -3436,6 +3437,20 @@ object SparkContext extends Logging {
     supplement(DRIVER_JAVA_OPTIONS)
     supplement(EXECUTOR_JAVA_OPTIONS)
   }
+
+  private def supplementBlasOptions(conf: SparkConf): Unit = {
+    conf.getOption("spark.ml.allowNativeBlas").foreach { allowNativeBlas =>

Review Comment:
   I skimmed the codebase https://github.com/luhenry/netlib and found neither sys prop nor env to disable native blas loading, so I need to introduce a new one. do you mean env var is preferred over sys prop?



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] [SPARK-51243][CORE][ML] Configurable allow native BLAS [spark]

Posted by "pan3793 (via GitHub)" <gi...@apache.org>.
pan3793 closed pull request #49986: [SPARK-51243][CORE][ML] Configurable allow native BLAS
URL: https://github.com/apache/spark/pull/49986


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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