LightGBM: published maven jars don't support Apple Silicon (ARM) Macs (arm64e) because of missing dynamic library

Description

Running lightgbm on a Mac with apple silicon (M1 chip, aarch64 architecture) fails because of missing native library for the architecture:

22/02/16 10:51:32 ERROR LightGBMRanker: {"uid":"LightGBMRanker_7c727e2d1c9e","className":"class com.microsoft.azure.synapse.ml.lightgbm.LightGBMRanker","method":"train","buildVersion":"0.9.5"}
org.apache.spark.SparkException: Job aborted due to stage failure: Could not recover from a failed barrier ResultStage. Most recent failure reason: Stage failed because barrier task ResultTask(13, 0) finished unsuccessfully.
java.lang.UnsatisfiedLinkError: /private/var/folders/31/56fwtfy17t520t96p0zwjnt40000gq/T/mml-natives618985592717473613/lib_lightgbm.dylib: dlopen(/private/var/folders/31/56fwtfy17t520t96p0zwjnt40000gq/T/mml-natives618985592717473613/lib_lightgbm.dylib, 0x0001): tried: '/private/var/folders/31/56fwtfy17t520t96p0zwjnt40000gq/T/mml-natives618985592717473613/lib_lightgbm.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/lib_lightgbm.dylib' (no such file)
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1950)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1832)
	at java.lang.Runtime.load0(Runtime.java:811)
	at java.lang.System.load(System.java:1088)
	at com.microsoft.azure.synapse.ml.core.env.NativeLoader.loadLibraryByName(NativeLoader.java:66)
	at com.microsoft.azure.synapse.ml.lightgbm.LightGBMUtils$.initializeNativeLibrary(LightGBMUtils.scala:39)
	at com.microsoft.azure.synapse.ml.lightgbm.LightGBMBase.trainLightGBM(LightGBMBase.scala:356)

I think the fix should be as simple as adding the appropriate library inside lightgbmlib-3.2.110.jar.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

Hey guys @mhamilton723, @imatiach-msft 🙋‍♂️

Do you know how he can get started with trying to make that change?

Unfortunately, not.

Adding a different architecture from the current build step sounds like a lot of work though, I don’t even know if it is possible.

my guess is something about this task/vm image needs to be modified:

As of best of my knowledge, there is no any free CI service that suggests ARM64 macOS right now. So we cannot simply add new CI job.

Probably, cross-compilation is a workaround. But I don’t know much about it and unfortunately don’t have enough time to get familiar with it right now. Also, I heard cross compilation for ARM64 macOS has its own challenges.

Some potentially useful links if one has interest to start digging: https://github.com/dmlc/xgboost/issues/7706 https://github.com/dmlc/xgboost/pull/7621 https://stackoverflow.com/questions/64788005/java-jdk-for-the-apple-m1-chip https://github.com/conda-forge/lightgbm-feedstock/blob/master/.ci_support/osx_64_python3.9.____cpython.yaml

Thanks for using LightGBM. If you’re saying you have access to an environment with an arm64e architecture and are willing to work on proposing fixes to allow compiling LightGBM in such environments, we’d welcome the help!

Otherwise, click “subscribe” on this issue to be notified of updates.

Some thoughts about cross-compilation from more experienced person than me.

Probably, cross-compilation is a workaround. But I don’t know much about it and unfortunately don’t have enough time to get familiar with it right now. Also, I heard cross compilation for ARM64 macOS has its own challenges.

I think cross-compiling the JNI binding will be tricky. You’ll probably need to have an ARM64 JVM as well as an x86 one to ensure you have the right libraries to link against. https://github.com/dmlc/xgboost/issues/7501#issuecomment-991813377

In addition, to be clear, “support for M1 macs in github actions” runner doesn’t mean free GitHub Actions hosted runner on M1 Mac. https://github.com/actions/virtual-environments/issues/2187

“As of best of my knowledge, there is no any free CI service that suggests ARM64 macOS right now. So we cannot simply add new CI job.” Oh I see… I guess this is just not possible then, unless a CI is created for ARM64 macOS. I don’t think we should try to do something special just for this architecture. Sorry @xelax . If you are really, really, really motivated you could create your own lightgbm jar, upload it on maven, and then create a custom build of mmlspark (which can be done with any PR) that would use that jar. But that is really a lot of work.

@imatiach-msft

Adding some screenshots of the generated artifacts we use:

You can simply download nightly builds. They have files you need. https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#nightly-builds

@xelax Hey, sorry about the problem you are having! Next time please add a reference to the preceding context of the issue. https://github.com/microsoft/SynapseML/issues/1405