LightGBM
LightGBM copied to clipboard
LIghtGBM generates incompatible architecture version in an M1 Mac
Description
I compiled LIghtGBM from the sources in a MacOS M1 (arm64), Ventura, by using the following commands:
sh ./build-python.sh bdist_wheel
cd dist
pip install lightgbm-4.2.0.99-py3-none-macosx_13_0_arm64.whl
The .whl
file is generated with the correct architecture version, according to the filename.
Reproducible example
When I enter python and type
import lightgbm
The following error occurs:
OSError: dlopen(/Users/monique/miniforge3/lib/python3.10/site-packages/lightgbm/lib/lib_lightgbm.so, 0x0006): tried: '/Users/monique/miniforge3/lib/python3.10/site-packages/lightgbm/lib/lib_lightgbm.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/monique/miniforge3/lib/python3.10/site-packages/lightgbm/lib/lib_lightgbm.so' (no such file), '/Users/monique/miniforge3/lib/python3.10/site-packages/lightgbm/lib/lib_lightgbm.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
In fact, when I type
lipo -info /Users/monique/miniforge3/lib/python3.10/site-packages/lightgbm/lib/lib_lightgbm.so
it shows:
Non-fat file: /Users/monique/miniforge3/lib/python3.10/site-packages/lightgbm/lib/lib_lightgbm.so is architecture: x86_64
Environment info
LightGBM version or commit hash: 4.2.0.99
Command(s) you used to install LightGBM: (shown above)
Additional Comments
Thanks for using LightGBM.
I've reformatted your report slightly to make the difference between code, text produced by code, and your own words clearer. If you're unsure how I did that, please see https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax.
I'll look into this in the next few days, and in general I'm hoping to prioritize better macOS support for the next release.
My first thought is that maybe you're getting a version of CMake
that doesn't have good support for the M1/M2 Macs.
Could you please show me the output of running the following commands?
which cmake
cmake --version
Could you also share the full logs from running the build script?
sh ./build-python.sh bdist_wheel
You can put them in a collapsible section in a GitHub comment like this:
<details><summary>logs (click me)</summary>
...
...
...
</details>
Hi @jameslamb
Here are the outputs you asked for:
which make
# /usr/local/bin/cmake
cmake --version
# cmake version 3.28.1
And the logs by sh ./build-python.sh bdist_wheel
:
logs (click me)
building lightgbm
Requirement already satisfied: build>=0.10.0 in /Users/monique/miniforge3/lib/python3.10/site-packages (1.0.3)
Requirement already satisfied: packaging>=19.0 in /Users/monique/miniforge3/lib/python3.10/site-packages (from build>=0.10.0) (23.0)
Requirement already satisfied: pyproject_hooks in /Users/monique/miniforge3/lib/python3.10/site-packages (from build>=0.10.0) (1.0.0)
Requirement already satisfied: tomli>=1.1.0 in /Users/monique/miniforge3/lib/python3.10/site-packages (from build>=0.10.0) (2.0.1)
--- building wheel ---
* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (scikit-build-core>=0.4.4)
* Getting build dependencies for wheel...
* Installing packages in isolated environment... (pathspec, pyproject_metadata)
* Building wheel...
2024-01-03 16:10:21,581 - scikit_build_core - INFO - CMake version: 3.28.1
*** scikit-build-core 0.7.1 using CMake 3.28.1 (wheel)
2024-01-03 16:10:21,585 - scikit_build_core - INFO - Build directory: /private/var/folders/h2/zv0j6jpj7dd5rlwgff3qz6pm0000gn/T/tmp7m2wnhfj/build
*** Configuring CMake...
2024-01-03 16:10:21,655 - scikit_build_core - INFO - Ninja version: 1.11.1
2024-01-03 16:10:21,655 - scikit_build_core - WARNING - libdir/ldlibrary: /Users/monique/miniforge3/lib/libpython3.10.a is not a real file!
2024-01-03 16:10:21,655 - scikit_build_core - WARNING - Can't find a Python library, got libdir=/Users/monique/miniforge3/lib, ldlibrary=libpython3.10.a, multiarch=darwin, masd=None
loading initial cache file /var/folders/h2/zv0j6jpj7dd5rlwgff3qz6pm0000gn/T/tmp7m2wnhfj/build/CMakeInit.txt
CMake Deprecation Warning at CMakeLists.txt:35 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- The C compiler identification is AppleClang 15.0.0.15000100
-- The CXX compiler identification is AppleClang 15.0.0.15000100
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
-- Found OpenMP_C: -Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include (found version "5.0")
-- Found OpenMP_CXX: -Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include (found version "5.0")
-- Found OpenMP: TRUE (found version "5.0")
-- Performing Test MM_PREFETCH
-- Performing Test MM_PREFETCH - Success
-- Using _mm_prefetch
-- Performing Test MM_MALLOC
-- Performing Test MM_MALLOC - Success
-- Using _mm_malloc
-- Configuring done (74.8s)
-- Generating done (0.0s)
-- Build files have been written to: /var/folders/h2/zv0j6jpj7dd5rlwgff3qz6pm0000gn/T/tmp7m2wnhfj/build
*** Building project with Ninja...
[39/53] Building CXX object CMakeFiles/lightgbm_objs.dir/src/network/linkers_socket.cpp.o
/Users/monique/Documents/UFPE/Doutorado/Disciplinas/IN1087/LightGBM/lightgbm-python/src/network/linkers_socket.cpp:174:7: warning: variable 'need_connect_cnt' set but not used [-Wunused-but-set-variable]
int need_connect_cnt = 0;
^
1 warning generated.
[53/53] Linking CXX shared library /Users/monique/Documents/UFPE/Doutorado/Disciplinas/IN1087/LightGBM/lightgbm-python/lib_lightgbm.so
*** Installing project into wheel...
-- Install configuration: "Release"
-- Installing: /var/folders/h2/zv0j6jpj7dd5rlwgff3qz6pm0000gn/T/tmp7m2wnhfj/wheel/platlib/lightgbm/lib/lib_lightgbm.so
*** Making wheel...
2024-01-03 16:15:50,135 - scikit_build_core - INFO - Discovered Python package at lightgbm
*** Created lightgbm-4.2.0.99-py3-none-macosx_13_0_arm64.whl...
Successfully built lightgbm-4.2.0.99-py3-none-macosx_13_0_arm64.whl
cleaning up
Thanks so much for that! I hope you don't mind, but I've reformatted your recent post as well to make it a bit easier to see the difference between code and output from code. You can click the ...
in the top right corner of the comment and then click "edit" to see the raw text for how I did that.
These details are very helpful! I'll try to reproduce this soon and get back to you. I apologize for the inconvenience.
Until we're able to resolve this.... is it absolutely necessary that you build LightGBM from source? If it'd be acceptable to use a pre-built, non-GPU-accelerated version of the library from a recent release (v4.2.0), you could do the following.
pip uninstall --yes lightgbm
conda install -c conda-forge 'lightgbm>=4.2.0'
conda-forge
has lightgbm
binaries for the M1/M2 Macs, and I Noticed in the logs you provided that you're using conda
.
Hi @jameslamb
In fact, I was trying to install another package, and I read somewhere a recommendation to install lightgbm from the source; unfortunately, I really don't remember the reference after so many attempts.
When I run conda install -c conda-forge 'lightgbm>=4.2.0' after uninstalling lightgbm, I get the following error:
Retrieving notices: ...working... done
Collecting package metadata (current_repodata.json): done
Solving environment: \
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
- pytorch/osx-arm64::pytorch==1.13.1=py3.10_0
- apple/osx-arm64::tensorflow-deps==2.10.0=0
- pytorch/osx-arm64::torchaudio==0.13.1=py310_cpu
- pytorch/osx-arm64::torchvision==0.14.1=py310_cpu
unsuccessful initial attempt using frozen solve. Retrying with flexible solve.
Solving environment: unsuccessful attempt using repodata from current_repodata.json, retrying with next repodata source.
ResolvePackageNotFound:
- conda==22.11.1
These incompatibilities may explain the problem.
BTW do you know if M3 support is better for lightgbm and other libs than M1/M2?
These incompatibilities may explain the problem.
Yes, those look unrelated to LightGBM.
if M3 support is better for lightgbm and other libs than M1/M2
The level of support for M3 is slightly worse for LightGBM than M1/M2... at least we have coverage of compiling the project on M1 via submissions of the R package to CRAN (https://cran.r-project.org/web/checks/check_results_lightgbm.html) and on M2 via me (and I think @jmoralez) building things on our personal M2 laptops.
But all 3 are poorly supported at this point... no precompiled binaries provided with releases, no testing in CI.
It's an area I'd like to focus on in the next LightGBM release (after v4.3.0).
Sorry for the delay in responding @monilouise . I believe this is fixed in recent versions of LightGBM.
I just tried this on my M2 Mac.
sh ./build-python.sh bdist_wheel
pip install dist/lightgbm-4.3.0.99-py3-none-macosx_14_0_arm64.whl
That installation succeeded without issue. And I was able to import lightgbm
.
import lightgbm
Versions I have locally:
pip --version
# pip 24.0 from /Users/jlamb/miniforge3/envs/lgb-test/lib/python3.11/site-packages/pip (python 3.11)
cmake --version
# cmake version 3.26.4
Could you please clone the latest version of lightgbm
and try again? I think I understand why this happened... even though you have CMake 3.28, LightGBM was still setting this in its build script
cmake_minimum_required(VERSION 3.0)
Setting a minimum version on CMake
doesn't just cause a check on the installed version... it also prevents newer versions of CMake from adopting new behavior.
In January of this year, LightGBM bumped that version to CMake 3.18 (#6260). I suspect that that might have helped fix this issue you've reported.
Thanks again for using LightGBM, and sorry about the difficulties building it on the new Macs. We're working on fixing that.