1{ stdenv 2, config 3, lib 4, buildPythonPackage 5, fetchPypi 6, python 7, pythonOlder 8, pythonAtLeast 9, openssl_1_1 10, zlib 11, setuptools 12, cudaSupport ? config.cudaSupport or false 13, cudaPackages_11 ? {} 14, addOpenGLRunpath 15# runtime dependencies 16, httpx 17, numpy 18, protobuf 19, pillow 20, decorator 21, astor 22, paddle-bfloat 23, opt-einsum 24}: 25 26let 27 pname = "paddlepaddle" + lib.optionalString cudaSupport "-gpu"; 28 version = "2.5.0"; 29 format = "wheel"; 30 pyShortVersion = "cp${builtins.replaceStrings ["."] [""] python.pythonVersion}"; 31 allHashAndPlatform = import ./binary-hashes.nix; 32 hash = allHashAndPlatform."${stdenv.system}"."${if cudaSupport then "gpu" else "cpu"}"."${pyShortVersion}"; 33 platform = allHashAndPlatform."${stdenv.system}".platform; 34 src = fetchPypi ({ 35 inherit version format hash platform; 36 pname = builtins.replaceStrings [ "-" ] [ "_" ] pname; 37 dist = pyShortVersion; 38 python = pyShortVersion; 39 abi = pyShortVersion; 40 }); 41in 42buildPythonPackage { 43 inherit pname version format src; 44 45 disabled = pythonOlder "3.9" || pythonAtLeast "3.11"; 46 47 libraryPath = lib.makeLibraryPath ( 48 # TODO: remove openssl_1_1 and zlib, maybe by building paddlepaddle from 49 # source as suggested in the following comment: 50 # https://github.com/NixOS/nixpkgs/pull/243583#issuecomment-1641450848 51 [ openssl_1_1 zlib ] ++ lib.optionals cudaSupport (with cudaPackages_11; [ 52 cudatoolkit.lib 53 cudatoolkit.out 54 cudnn 55 ]) 56 ); 57 58 postFixup = lib.optionalString stdenv.isLinux '' 59 function fixRunPath { 60 p=$(patchelf --print-rpath $1) 61 patchelf --set-rpath "$p:$libraryPath" $1 62 ${lib.optionalString cudaSupport '' 63 addOpenGLRunpath $1 64 ''} 65 } 66 fixRunPath $out/${python.sitePackages}/paddle/fluid/libpaddle.so 67 ''; 68 69 nativeBuildInputs = [ 70 addOpenGLRunpath 71 ]; 72 73 propagatedBuildInputs = [ 74 setuptools 75 httpx 76 numpy 77 protobuf 78 pillow 79 decorator 80 astor 81 paddle-bfloat 82 opt-einsum 83 ]; 84 85 pythonImportsCheck = [ "paddle" ]; 86 87 # no tests 88 doCheck = false; 89 90 meta = with lib; { 91 description = "PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice &"; 92 homepage = "https://github.com/PaddlePaddle/Paddle"; 93 license = licenses.asl20; 94 maintainers = with maintainers; [ happysalada ]; 95 platforms = [ "x86_64-linux" ] ++ optionals (!cudaSupport) [ "x86_64-darwin" "aarch64-darwin" ]; 96 }; 97}