Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build mlx on M1 Ultra w/ XCode installed #208

Closed
chimezie opened this issue Dec 18, 2023 · 6 comments
Closed

Unable to build mlx on M1 Ultra w/ XCode installed #208

chimezie opened this issue Dec 18, 2023 · 6 comments

Comments

@chimezie
Copy link
Contributor

When I try to build the latest mlx main branch via:

env CMAKE_BUILD_PARALLEL_LEVEL="" pip install -U .

I get:

Processing /Users/oori/medical_llm/mlx
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mlx
  Building wheel for mlx (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for mlx (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [146 lines of output]
      running bdist_wheel
      running build
      running build_py
      copying python/mlx/optimizers.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx
      copying python/mlx/utils.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx
      copying python/mlx/extension.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx
      copying python/mlx/_reprlib_fix.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx
      copying python/mlx/nn/__init__.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn
      copying python/mlx/nn/utils.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn
      copying python/mlx/nn/losses.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn
      copying python/mlx/nn/layers/convolution.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      copying python/mlx/nn/layers/embedding.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      copying python/mlx/nn/layers/activations.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      copying python/mlx/nn/layers/containers.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      copying python/mlx/nn/layers/linear.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      copying python/mlx/nn/layers/__init__.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      copying python/mlx/nn/layers/transformer.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      copying python/mlx/nn/layers/dropout.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      copying python/mlx/nn/layers/positional_encoding.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      copying python/mlx/nn/layers/normalization.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      copying python/mlx/nn/layers/base.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx/nn/layers
      running egg_info
      writing python/mlx.egg-info/PKG-INFO
      writing dependency_links to python/mlx.egg-info/dependency_links.txt
      writing requirements to python/mlx.egg-info/requires.txt
      writing top-level names to python/mlx.egg-info/top_level.txt
      reading manifest file 'python/mlx.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      adding license file 'LICENSE'
      writing manifest file 'python/mlx.egg-info/SOURCES.txt'
      running build_ext
      -- Building MLX for arm64 processor on Darwin
      -- Building METAL sources
      -- Building with SDK for macOS version 14.0
      
      -- Accelerate found /Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Accelerate.framework
      -- Building Python bindings.
      -- Found pybind11: /Users/oori/.local/venv/medical-finetune/include (found version "2.11.1")
      -- Configuring done (1.0s)
      -- Generating done (0.0s)
      -- Build files have been written to: /Users/oori/medical_llm/mlx/build/temp.macosx-10.9-universal2-cpython-311/mlx.core
      [  1%] Building arange.air
      [  2%] Building unary.air
      [  5%] Building indexing.air
      [  5%] Building softmax.air
      [  6%] Building sort.air
      [  8%] Building scan.air
      [  9%] Building random.air
      [ 10%] Building gemv.air
      [ 15%] Building reduce.air
      [ 16%] Building conv.air
      [ 15%] Building copy.air
      [ 17%] Building gemm.air
      [ 17%] Building arg_reduce.air
      [ 19%] Building binary.air
      xcrun: error: unable to find utility "metal", not a developer tool or in PATH

According to the Install instructions, this is because Xcode is not installed. However, when I check if XCode commandline tools are installed, I get this:

% xcode-select --version
xcode-select version 2403.
@awni
Copy link
Member

awni commented Dec 18, 2023

See the second section in #200 If that does not fix your issue, comment here and I will reopen.

@awni awni closed this as completed Dec 18, 2023
@chimezie
Copy link
Contributor Author

chimezie commented Dec 18, 2023

XCode command line tools are already installed:
% xcode-select --install

I get

xcode-select: note: Command line tools are already installed. Use "Software Update" in System Settings or the softwareupdate command line interface to install updates

When I try this (from that section):
% xcode-select --switch /Applications/Xcode.app/Contents/Developer

I get

xcode-select: error: invalid developer directory '/Applications/Xcode.app/Contents/Developer'

@awni
Copy link
Member

awni commented Dec 18, 2023

Hmm maybe try something like this: https://stackoverflow.com/a/17980786

@chimezie
Copy link
Contributor Author

After installing XCode per reference, I got further, but getting a different build error (using latest on main):

Processing /Users/oori/medical_llm/mlx
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mlx
  Building wheel for mlx (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for mlx (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [121 lines of output]
      running bdist_wheel
      running build
      running build_py
      copying python/mlx/optimizers.py -> build/lib.macosx-10.9-universal2-cpython-311/mlx
[..snip..]
      writing manifest file 'python/mlx.egg-info/SOURCES.txt'
      running build_ext
      CMake Warning at /private/var/folders/4b/bht1mbdj6xd_1jmhss9cmpbw0000gn/T/pip-build-env-rin2oxfy/overlay/lib/python3.11/site-packages/cmake/data/share/cmake-3.28/Modules/Platform/Darwin-Initialize.cmake:308 (message):
        Ignoring CMAKE_OSX_SYSROOT value:
     
         /Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk
     
        because the directory does not exist.
      Call Stack (most recent call first):
        /private/var/folders/4b/bht1mbdj6xd_1jmhss9cmpbw0000gn/T/pip-build-env-rin2oxfy/overlay/lib/python3.11/site-packages/cmake/data/share/cmake-3.28/Modules/CMakeSystemSpecificInitialize.cmake:34 (include)
        CMakeLists.txt:3 (project)
     
     
      -- Building MLX for arm64 processor on Darwin
      -- Building METAL sources
      -- Building with SDK for macOS version 14.2
     
      -- Accelerate found /Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Accelerate.framework
      -- Building Python bindings.
      -- Found pybind11: /Users/oori/.local/venv/medical-finetune/include (found version "2.11.1")
      -- Configuring done (0.6s)
      -- Generating done (0.0s)
      -- Build files have been written to: /Users/oori/medical_llm/mlx/build/temp.macosx-10.9-universal2-cpython-311/mlx.core
      [ 20%] Built target mlx-metallib
      [ 22%] Building CXX object CMakeFiles/mlx.dir/mlx/allocator.cpp.o
      /Users/oori/medical_llm/mlx/mlx/allocator.cpp:3:10: fatal error: 'cstdlib' file not found
      #include <cstdlib>
[ 20%] Built target mlx-metallib
      [ 22%] Building CXX object CMakeFiles/mlx.dir/mlx/allocator.cpp.o
      /Users/oori/medical_llm/mlx/mlx/allocator.cpp:3:10: fatal error: 'cstdlib' file not found
      #include <cstdlib>
               ^~~~~~~~~
      1 error generated.
      make[2]: *** [CMakeFiles/mlx.dir/mlx/allocator.cpp.o] Error 1
      make[1]: *** [CMakeFiles/mlx.dir/all] Error 2
      make: *** [all] Error 2```

@chimezie
Copy link
Contributor Author

BTW, I was able to resolve and successfully build after (see solution here):

% export CC=`which gcc`  
% export CXX=`which g++` 

There might be some changes made to setup.py (as described in that solution) that would address this

@awni
Copy link
Member

awni commented Dec 20, 2023

Thanks for the tip, will look into it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants