Xgboost on apple m1?

Hello,

is there anyone having success in running xgboost on m1 yet, and
if you do, how did you get it working?
I utilize it via python if that matters.

// Björn

1 Like

I have the same issue. I have tried everything to fix it, but it does not work.

I have tried:

  1. reinstalling it, pip and pip3 and python -m pip and conda install
  2. brew install limpomp
  3. brew install gcc@8
  4. Downloading source code and compiling locally

XGboost does not work on Apple M1.

It compiles and runs just fine on M1. I compiled it with the Java interface, using the Apple Silicon version of homebrew, cmake and libomp. If you install brew the normal way you’ll get a version that uses binary translation from Intel (i.e. Rosetta 2) and that might cause linker errors. GCC isn’t currently available on Apple Silicon, which is why you need to use clang.

Interesting, can you please share each step, still struggling? Followed same steps with no luck.

Install the ARM version of homebrew (which installs into /opt/homebrew), then the brew versions of python, libomp. I then installed the Azul Zulu 8 java ARM port and Apache Maven. Then it compiles just fine.

What kind of errors are you getting?

1 Like

I unfortunately still get the same error unfortunately. Even after following all the steps

  1. /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
  2. echo ‘eval $(/opt/homebrew/bin/brew shellenv)’ >> /Users/rudzani/.zprofile
    eval $(/opt/homebrew/bin/brew shellenv)
  3. brew install python
  4. Installed Azul Zulu 8 java ARM port
  5. java -version
  6. Downloaded Apache Maven and set path
    export PATH=/Users/rudzani/Downloads/apache-maven-3.6.3/bin:$PATH
  7. mvn --version confirmed install
  8. Installed libomp
  9. installed xgboost (both pip and python3 -m pip install xgboost)

But I still have the error below.

In [1]: import xgboost as xgb
---------------------------------------------------------------------------
XGBoostError                              Traceback (most recent call last)
<ipython-input-1-5943d1bfe3f1> in <module>
----> 1 import xgboost as xgb

/opt/anaconda3/lib/python3.8/site-packages/xgboost/__init__.py in <module>
      7 import os
      8 
----> 9 from .core import DMatrix, DeviceQuantileDMatrix, Booster
     10 from .training import train, cv
     11 from . import rabit  # noqa

/opt/anaconda3/lib/python3.8/site-packages/xgboost/core.py in <module>
    172 
    173 # load the XGBoost library globally
--> 174 _LIB = _load_lib()
    175 
    176 

/opt/anaconda3/lib/python3.8/site-packages/xgboost/core.py in _load_lib()
    155     if not lib_success:
    156         libname = os.path.basename(lib_paths[0])
--> 157         raise XGBoostError(
    158             'XGBoost Library ({}) could not be loaded.\n'.format(libname) +
    159             'Likely causes:\n' +

XGBoostError: XGBoost Library (libxgboost.dylib) could not be loaded.
Likely causes:
  * OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows, libomp.dylib for Mac OSX, libgomp.so for Linux and other UNIX-like OSes). Mac OSX users: Run `brew install libomp` to install OpenMP runtime.
  * You are running 32-bit Python on a 64-bit OS
Error message(s): ['dlopen(/opt/anaconda3/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib, 6): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib\n  Referenced from: /opt/anaconda3/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib\n  Reason: image not found']

You’re using the version inside anaconda rather than one compiled from source.

I looked into it a little more and on Python XGBoost needs scipy, and scipy requires a fortran compiler which is not currently available on Apple M1 (as they haven’t ported gcc yet, and I don’t think flang is supported by scipy). So until scipy works the python bindings won’t work.

The JVM bindings talk directly to the XGBoost native library, and both of those work fine on Apple Silicon.

1 Like

No this is not correct. I was successfully able to install xgboost in Apple MacBook pro M1 chip

For Python-3.x, do the following in Mac

Make sure gcc-6 (and g+±6) is installed, if not do so with

brew install gcc
brew install cmake

Then, do the following

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost/
make -j4
cd python-package
python3 setup.py install

If you are using Anaconda and haven’t yet configured your path to use the binaries in ~/anaconda/bin , then run the last line as

/path/to/anaconda/bin/python3 setup.py install

1 Like

I think you’re running the x86_64 version under Rosetta 2, as gcc-6 isn’t available as a native binary for macOS/ARM64. See here https://formulae.brew.sh/formula/gcc@6 which only mentions Intel (i.e. x86_64) versions. If you ran those commands on an Apple Silicon Mac then you’d get gcc-10.

As Rosetta 2 doesn’t support AVX instructions this way is dependent on the XGBoost binary not using any of those instructions, and I believe that will depend on the compilation flags (so it might be a bit fragile).

Thank you for sharing. This helps me!

As of today(10 September 2021) is there a way to install XGBoost and Lightroomgb on M1 Mac

how to install XGBoost and Lightroom as of today 10 sept 2021

For people who use mac m1 (Apple silicon ) and try to use XGBoost4j and face the same problem or something like:

 mach-o, but wrong architecture

and

no suitable image found.  Did find

just check your JAVA_HOME, if it’s zulu jdk, replace it with oracle jdk.

What version of xgboost were you able to install? I am using anaconda on Apple M1 Chip Mac. xgboost v0.90 works, but when I try to upgrade, it fails.

This didn’t work for me. I need to be on version > 1.0.0 or < 1.3.1.

I followed the steps you outlined and then downgraded from 1.6 to 1.3.1. When I run the model.fit command, my jupyter kernel dies.

No, it is just a next to impossible process of making work on Xgboost on apple m1. I have tried this from an essay outline template from last three weeks and it is not working.

@JK-858 XGBoost now supports Apple Silicon, starting from version 1.6.0 (release note). You should be able to install it by running

pip install xgboost