Merge pull request #286243 from viraptor/init-mlx

python3Packages.mlx: init at 0.1.0

authored by Stanisław Pitucha and committed by GitHub ff2a77ca f4f9d00a

+93
+78
pkgs/development/python-modules/mlx/default.nix
··· 1 + { stdenv 2 + , lib 3 + , fetchFromGitHub 4 + , buildPythonPackage 5 + , python3Packages 6 + , pybind11 7 + , cmake 8 + , xcbuild 9 + , zsh 10 + , darwin 11 + , blas 12 + , lapack 13 + }: 14 + 15 + let 16 + # static dependencies included directly during compilation 17 + gguf-tools = fetchFromGitHub { 18 + owner = "antirez"; 19 + repo = "gguf-tools"; 20 + rev = "af7d88d808a7608a33723fba067036202910acb3"; 21 + hash = "sha256-LqNvnUbmq0iziD9VP5OTJCSIy+y/hp5lKCUV7RtKTvM="; 22 + }; 23 + nlohmann_json = fetchFromGitHub { 24 + owner = "nlohmann"; 25 + repo = "json"; 26 + rev = "v3.11.3"; 27 + hash = "sha256-7F0Jon+1oWL7uqet5i1IgHX0fUw/+z0QwEcA3zs5xHg="; 28 + }; 29 + in 30 + buildPythonPackage rec { 31 + pname = "mlx"; 32 + version = "0.1.0"; 33 + 34 + src = fetchFromGitHub { 35 + owner = "ml-explore"; 36 + repo = "mlx"; 37 + rev = "refs/tags/v${version}"; 38 + hash = "sha256-xNJPG8XGbC0fy6RGcn1cxCsejyHsgnV35PuP8F1I4R4="; 39 + }; 40 + 41 + pyproject = true; 42 + 43 + patches = [ 44 + # With Darwin SDK 11 we cannot include vecLib/cblas_new.h, this needs to wait for PR #229210 45 + # In the meantime, pretend Accelerate is not available and use blas/lapack instead. 46 + ./disable-accelerate.patch 47 + ]; 48 + 49 + postPatch = '' 50 + substituteInPlace CMakeLists.txt \ 51 + --replace "/usr/bin/xcrun" "${xcbuild}/bin/xcrun" \ 52 + ''; 53 + 54 + dontUseCmakeConfigure = true; 55 + 56 + env = { 57 + PYPI_RELEASE = version; 58 + # we can't use Metal compilation with Darwin SDK 11 59 + CMAKE_ARGS = toString [ 60 + (lib.cmakeBool "MLX_BUILD_METAL" false) 61 + (lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_GGUFLIB" "${gguf-tools}") 62 + (lib.cmakeOptionType "filepath" "FETCHCONTENT_SOURCE_DIR_JSON" "${nlohmann_json}") 63 + ]; 64 + }; 65 + 66 + nativeBuildInputs = [ cmake pybind11 xcbuild zsh gguf-tools nlohmann_json ] ++ (with python3Packages; [ setuptools ]); 67 + 68 + buildInputs = [ blas lapack ]; 69 + 70 + meta = with lib; { 71 + homepage = "https://github.com/ml-explore/mlx"; 72 + description = "An array framework for Apple silicon"; 73 + changelog = "https://github.com/ml-explore/mlx/releases/tag/v${version}"; 74 + license = licenses.mit; 75 + platforms = [ "aarch64-darwin" ]; 76 + maintainers = with maintainers; [ viraptor ]; 77 + }; 78 + }
+13
pkgs/development/python-modules/mlx/disable-accelerate.patch
··· 1 + diff --git a/CMakeLists.txt b/CMakeLists.txt 2 + index 2d6bef9..d099673 100644 3 + --- a/CMakeLists.txt 4 + +++ b/CMakeLists.txt 5 + @@ -104,7 +104,7 @@ elseif (MLX_BUILD_METAL) 6 + ${QUARTZ_LIB}) 7 + endif() 8 + 9 + -find_library(ACCELERATE_LIBRARY Accelerate) 10 + +#find_library(ACCELERATE_LIBRARY Accelerate) 11 + if (MLX_BUILD_ARM AND ACCELERATE_LIBRARY) 12 + message(STATUS "Accelerate found ${ACCELERATE_LIBRARY}") 13 + set(MLX_BUILD_ACCELERATE ON)
+2
pkgs/top-level/python-packages.nix
··· 7173 7173 7174 7174 mlrose = callPackage ../development/python-modules/mlrose { }; 7175 7175 7176 + mlx = callPackage ../development/python-modules/mlx { }; 7177 + 7176 7178 mlxtend = callPackage ../development/python-modules/mlxtend { }; 7177 7179 7178 7180 mlt = toPythonModule (pkgs.mlt.override {