at 25.11-pre 2.2 kB view raw
1{ 2 lib, 3 fetchFromGitHub, 4 buildPythonPackage, 5 pybind11, 6 cmake, 7 xcbuild, 8 zsh, 9 blas, 10 lapack, 11 setuptools, 12}: 13 14let 15 # static dependencies included directly during compilation 16 gguf-tools = fetchFromGitHub { 17 owner = "antirez"; 18 repo = "gguf-tools"; 19 rev = "af7d88d808a7608a33723fba067036202910acb3"; 20 hash = "sha256-LqNvnUbmq0iziD9VP5OTJCSIy+y/hp5lKCUV7RtKTvM="; 21 }; 22 nlohmann_json = fetchFromGitHub { 23 owner = "nlohmann"; 24 repo = "json"; 25 rev = "v3.11.3"; 26 hash = "sha256-7F0Jon+1oWL7uqet5i1IgHX0fUw/+z0QwEcA3zs5xHg="; 27 }; 28in 29buildPythonPackage rec { 30 pname = "mlx"; 31 version = "0.21.1"; 32 33 src = fetchFromGitHub { 34 owner = "ml-explore"; 35 repo = "mlx"; 36 rev = "refs/tags/v${version}"; 37 hash = "sha256-wxv9bA9e8VyFv/FMh63sUTTNgkXHGQJNQhLuVynczZA="; 38 }; 39 40 pyproject = true; 41 42 patches = [ 43 # With Darwin SDK 11 we cannot include vecLib/cblas_new.h, this needs to wait for PR #229210 44 # In the meantime, pretend Accelerate is not available and use blas/lapack instead. 45 ./disable-accelerate.patch 46 ]; 47 48 postPatch = '' 49 substituteInPlace CMakeLists.txt \ 50 --replace "/usr/bin/xcrun" "${xcbuild}/bin/xcrun" \ 51 ''; 52 53 dontUseCmakeConfigure = true; 54 55 # updates the wrong fetcher rev attribute 56 passthru.skipBulkUpdate = true; 57 58 env = { 59 PYPI_RELEASE = version; 60 # we can't use Metal compilation with Darwin SDK 11 61 CMAKE_ARGS = toString [ 62 (lib.cmakeBool "MLX_BUILD_METAL" false) 63 (lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_GGUFLIB" "${gguf-tools}") 64 (lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_JSON" "${nlohmann_json}") 65 ]; 66 }; 67 68 nativeBuildInputs = [ 69 cmake 70 pybind11 71 xcbuild 72 zsh 73 gguf-tools 74 nlohmann_json 75 setuptools 76 ]; 77 78 buildInputs = [ 79 blas 80 lapack 81 ]; 82 83 meta = with lib; { 84 homepage = "https://github.com/ml-explore/mlx"; 85 description = "Array framework for Apple silicon"; 86 changelog = "https://github.com/ml-explore/mlx/releases/tag/v${version}"; 87 license = licenses.mit; 88 platforms = [ "aarch64-darwin" ]; 89 maintainers = with maintainers; [ 90 viraptor 91 Gabriella439 92 ]; 93 }; 94}