2020-08-01 09:20:04 +01:00
|
|
|
{ stdenv, pkgs, bazel_3, buildBazelPackage, lib, fetchFromGitHub, fetchpatch, symlinkJoin
|
2019-10-02 08:32:48 +01:00
|
|
|
, addOpenGLRunpath
|
2019-07-13 20:42:50 +01:00
|
|
|
# Python deps
|
2020-03-18 19:04:55 +00:00
|
|
|
, buildPythonPackage, isPy3k, isPy27, pythonOlder, pythonAtLeast, python
|
2019-07-13 20:42:50 +01:00
|
|
|
# Python libraries
|
2019-11-19 21:45:06 +00:00
|
|
|
, numpy, tensorflow-tensorboard_2, backports_weakref, mock, enum34, absl-py
|
2019-07-13 20:42:50 +01:00
|
|
|
, future, setuptools, wheel, keras-preprocessing, keras-applications, google-pasta
|
2019-10-07 09:14:16 +01:00
|
|
|
, functools32
|
2020-08-01 09:20:04 +01:00
|
|
|
, opt-einsum, astunparse, h5py
|
2019-11-19 21:45:06 +00:00
|
|
|
, termcolor, grpcio, six, wrapt, protobuf, tensorflow-estimator_2
|
2019-07-13 20:42:50 +01:00
|
|
|
# Common deps
|
|
|
|
, git, swig, which, binutils, glibcLocales, cython
|
|
|
|
# Common libraries
|
|
|
|
, jemalloc, openmpi, astor, gast, grpc, sqlite, openssl, jsoncpp, re2
|
|
|
|
, curl, snappy, flatbuffers, icu, double-conversion, libpng, libjpeg, giflib
|
2019-10-07 09:14:16 +01:00
|
|
|
# Upsteam by default includes cuda support since tensorflow 1.15. We could do
|
|
|
|
# that in nix as well. It would make some things easier and less confusing, but
|
|
|
|
# it would also make the default tensorflow package unfree. See
|
|
|
|
# https://groups.google.com/a/tensorflow.org/forum/#!topic/developers/iRCt5m4qUz0
|
2020-08-01 09:20:04 +01:00
|
|
|
, cudaSupport ? false, cudatoolkit ? null, cudnn ? null, nccl ? null
|
2019-09-04 20:44:24 +01:00
|
|
|
, mklSupport ? false, mkl ? null
|
2018-02-27 00:16:33 +00:00
|
|
|
# XLA without CUDA is broken
|
|
|
|
, xlaSupport ? cudaSupport
|
2017-10-15 13:23:56 +01:00
|
|
|
# Default from ./configure script
|
|
|
|
, cudaCapabilities ? [ "3.5" "5.2" ]
|
2020-08-05 03:32:41 +01:00
|
|
|
, sse42Support ? stdenv.hostPlatform.sse4_2Support
|
|
|
|
, avx2Support ? stdenv.hostPlatform.avx2Support
|
|
|
|
, fmaSupport ? stdenv.hostPlatform.fmaSupport
|
2019-11-27 03:15:40 +00:00
|
|
|
# Darwin deps
|
|
|
|
, Foundation, Security
|
2017-02-15 11:30:30 +00:00
|
|
|
}:
|
|
|
|
|
2020-08-01 09:20:04 +01:00
|
|
|
assert cudaSupport -> cudatoolkit != null
|
2017-10-15 13:23:56 +01:00
|
|
|
&& cudnn != null;
|
2017-02-26 10:03:27 +00:00
|
|
|
|
|
|
|
# unsupported combination
|
|
|
|
assert ! (stdenv.isDarwin && cudaSupport);
|
|
|
|
|
2019-09-04 20:44:24 +01:00
|
|
|
assert mklSupport -> mkl != null;
|
|
|
|
|
2017-10-15 13:23:56 +01:00
|
|
|
let
|
|
|
|
withTensorboard = pythonOlder "3.6";
|
2017-02-15 11:30:30 +00:00
|
|
|
|
2017-10-03 14:50:39 +01:00
|
|
|
cudatoolkit_joined = symlinkJoin {
|
2019-07-13 20:42:50 +01:00
|
|
|
name = "${cudatoolkit.name}-merged";
|
2019-10-07 09:14:16 +01:00
|
|
|
paths = [
|
|
|
|
cudatoolkit.lib
|
|
|
|
cudatoolkit.out
|
2020-08-19 19:34:18 +01:00
|
|
|
] ++ lib.optionals (lib.versionOlder cudatoolkit.version "11") [
|
2019-10-07 09:14:16 +01:00
|
|
|
# for some reason some of the required libs are in the targets/x86_64-linux
|
|
|
|
# directory; not sure why but this works around it
|
|
|
|
"${cudatoolkit}/targets/${stdenv.system}"
|
|
|
|
];
|
2017-10-15 13:23:56 +01:00
|
|
|
};
|
|
|
|
|
2019-07-13 20:42:50 +01:00
|
|
|
cudatoolkit_cc_joined = symlinkJoin {
|
|
|
|
name = "${cudatoolkit.cc.name}-merged";
|
2019-06-20 19:17:13 +01:00
|
|
|
paths = [
|
|
|
|
cudatoolkit.cc
|
|
|
|
binutils.bintools # for ar, dwp, nm, objcopy, objdump, strip
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2019-07-13 20:42:50 +01:00
|
|
|
# Needed for _some_ system libraries, grep INCLUDEDIR.
|
|
|
|
includes_joined = symlinkJoin {
|
|
|
|
name = "tensorflow-deps-merged";
|
|
|
|
paths = [
|
|
|
|
pkgs.protobuf
|
|
|
|
jsoncpp
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2017-10-15 13:23:56 +01:00
|
|
|
tfFeature = x: if x then "1" else "0";
|
|
|
|
|
2020-08-01 09:20:04 +01:00
|
|
|
version = "2.3.0";
|
2019-07-13 20:42:50 +01:00
|
|
|
variant = if cudaSupport then "-gpu" else "";
|
2019-06-20 19:17:13 +01:00
|
|
|
pname = "tensorflow${variant}";
|
2017-11-10 17:07:58 +00:00
|
|
|
|
2019-08-31 19:02:19 +01:00
|
|
|
pythonEnv = python.withPackages (_:
|
2019-10-07 09:14:16 +01:00
|
|
|
[ # python deps needed during wheel build time (not runtime, see the buildPythonPackage part for that)
|
2019-08-31 19:02:19 +01:00
|
|
|
numpy
|
|
|
|
keras-preprocessing
|
|
|
|
protobuf
|
|
|
|
wrapt
|
|
|
|
gast
|
|
|
|
astor
|
|
|
|
absl-py
|
|
|
|
termcolor
|
|
|
|
keras-applications
|
|
|
|
setuptools
|
|
|
|
wheel
|
|
|
|
] ++ lib.optionals (!isPy3k)
|
|
|
|
[ future
|
2019-10-07 09:14:16 +01:00
|
|
|
functools32
|
2019-08-31 19:02:19 +01:00
|
|
|
mock
|
|
|
|
]);
|
2019-07-13 20:42:50 +01:00
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
bazel-build = buildBazelPackage {
|
2019-07-13 20:42:50 +01:00
|
|
|
name = "${pname}-${version}";
|
2020-08-01 09:20:04 +01:00
|
|
|
bazel = bazel_3;
|
2017-10-15 13:23:56 +01:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "tensorflow";
|
|
|
|
repo = "tensorflow";
|
2019-07-13 20:42:50 +01:00
|
|
|
rev = "v${version}";
|
2020-08-01 09:20:04 +01:00
|
|
|
sha256 = "1dd5fgyiazyfy7y2iv4v42qnap51fr6dzwb26inrsj7aaas06j71";
|
2017-10-15 13:23:56 +01:00
|
|
|
};
|
|
|
|
|
2017-11-10 17:07:58 +00:00
|
|
|
patches = [
|
2019-07-13 20:42:50 +01:00
|
|
|
# Fixes for NixOS jsoncpp
|
2019-11-19 21:45:06 +00:00
|
|
|
../system-jsoncpp.patch
|
2019-06-20 19:17:13 +01:00
|
|
|
|
2020-08-01 09:20:04 +01:00
|
|
|
./lift-gast-restriction.patch
|
|
|
|
|
|
|
|
# see https://github.com/tensorflow/tensorflow/issues/40688
|
2020-02-25 16:00:44 +00:00
|
|
|
(fetchpatch {
|
2020-08-01 09:20:04 +01:00
|
|
|
url = "https://github.com/tensorflow/tensorflow/commit/75ea0b31477d6ba9e990e296bbbd8ca4e7eebadf.patch";
|
|
|
|
sha256 = "1xp1icacig0xm0nmb05sbrf4nw4xbln9fhc308birrv8286zx7wv";
|
2020-02-25 16:00:44 +00:00
|
|
|
})
|
2019-10-17 13:48:28 +01:00
|
|
|
|
2020-08-01 09:20:04 +01:00
|
|
|
# see https://github.com/tensorflow/tensorflow/issues/40884
|
2019-11-12 15:28:54 +00:00
|
|
|
(fetchpatch {
|
2020-08-01 09:20:04 +01:00
|
|
|
url = "https://github.com/tensorflow/tensorflow/pull/41867/commits/65341f73d110bf173325768947343e1bb8f699fc.patch";
|
|
|
|
sha256 = "18ykkycaag1pcarz53bz6ydxjlah92j4178qn58gcayx1fy7hvh3";
|
2019-11-12 15:28:54 +00:00
|
|
|
})
|
2017-11-10 17:07:58 +00:00
|
|
|
];
|
2017-10-15 13:23:56 +01:00
|
|
|
|
2019-06-20 19:17:13 +01:00
|
|
|
# On update, it can be useful to steal the changes from gentoo
|
|
|
|
# https://gitweb.gentoo.org/repo/gentoo.git/tree/sci-libs/tensorflow
|
|
|
|
|
2019-07-13 20:42:50 +01:00
|
|
|
nativeBuildInputs = [
|
2019-08-31 19:02:19 +01:00
|
|
|
swig which pythonEnv
|
2019-10-02 08:32:48 +01:00
|
|
|
] ++ lib.optional cudaSupport addOpenGLRunpath;
|
2017-10-15 13:23:56 +01:00
|
|
|
|
2019-06-20 19:17:13 +01:00
|
|
|
buildInputs = [
|
|
|
|
jemalloc
|
|
|
|
openmpi
|
|
|
|
glibcLocales
|
|
|
|
git
|
|
|
|
|
|
|
|
# libs taken from system through the TF_SYS_LIBS mechanism
|
2020-08-01 09:20:04 +01:00
|
|
|
grpc
|
2019-07-13 20:42:50 +01:00
|
|
|
sqlite
|
|
|
|
openssl
|
|
|
|
jsoncpp
|
|
|
|
pkgs.protobuf
|
|
|
|
curl
|
|
|
|
snappy
|
|
|
|
flatbuffers
|
|
|
|
icu
|
|
|
|
double-conversion
|
|
|
|
libpng
|
|
|
|
libjpeg
|
|
|
|
giflib
|
|
|
|
re2
|
|
|
|
pkgs.lmdb
|
2019-06-20 19:17:13 +01:00
|
|
|
] ++ lib.optionals cudaSupport [
|
|
|
|
cudatoolkit
|
|
|
|
cudnn
|
2019-09-04 20:44:24 +01:00
|
|
|
] ++ lib.optionals mklSupport [
|
|
|
|
mkl
|
2019-11-27 03:15:40 +00:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
Foundation
|
|
|
|
Security
|
2019-06-20 19:17:13 +01:00
|
|
|
];
|
|
|
|
|
2019-07-13 20:42:50 +01:00
|
|
|
# arbitrarily set to the current latest bazel version, overly careful
|
|
|
|
TF_IGNORE_MAX_BAZEL_VERSION = true;
|
|
|
|
|
2019-06-20 19:17:13 +01:00
|
|
|
# Take as many libraries from the system as possible. Keep in sync with
|
|
|
|
# list of valid syslibs in
|
2019-07-13 20:42:50 +01:00
|
|
|
# https://github.com/tensorflow/tensorflow/blob/master/third_party/systemlibs/syslibs_configure.bzl
|
|
|
|
TF_SYSTEM_LIBS = lib.concatStringsSep "," [
|
2019-06-20 19:17:13 +01:00
|
|
|
"absl_py"
|
|
|
|
"astor_archive"
|
2020-08-01 09:20:04 +01:00
|
|
|
"astunparse_archive"
|
2019-06-20 19:17:13 +01:00
|
|
|
"boringssl"
|
2019-07-13 20:42:50 +01:00
|
|
|
# Not packaged in nixpkgs
|
|
|
|
# "com_github_googleapis_googleapis"
|
|
|
|
# "com_github_googlecloudplatform_google_cloud_cpp"
|
2020-08-01 09:20:04 +01:00
|
|
|
"com_github_grpc_grpc"
|
2019-06-20 19:17:13 +01:00
|
|
|
"com_google_protobuf"
|
|
|
|
"com_googlesource_code_re2"
|
|
|
|
"curl"
|
|
|
|
"cython"
|
|
|
|
"double_conversion"
|
2020-08-01 09:20:04 +01:00
|
|
|
"enum34_archive"
|
2019-06-20 19:17:13 +01:00
|
|
|
"flatbuffers"
|
2020-08-01 09:20:04 +01:00
|
|
|
"functools32_archive"
|
2019-06-20 19:17:13 +01:00
|
|
|
"gast_archive"
|
2020-08-01 09:20:04 +01:00
|
|
|
"gif"
|
2019-06-20 19:17:13 +01:00
|
|
|
"hwloc"
|
|
|
|
"icu"
|
|
|
|
"jsoncpp_git"
|
2020-08-01 09:20:04 +01:00
|
|
|
"libjpeg_turbo"
|
2019-06-20 19:17:13 +01:00
|
|
|
"lmdb"
|
|
|
|
"nasm"
|
|
|
|
# "nsync" # not packaged in nixpkgs
|
2019-10-07 09:14:16 +01:00
|
|
|
"opt_einsum_archive"
|
2019-07-13 20:42:50 +01:00
|
|
|
"org_sqlite"
|
2019-06-20 19:17:13 +01:00
|
|
|
"pasta"
|
|
|
|
"pcre"
|
2020-08-01 09:20:04 +01:00
|
|
|
"png"
|
|
|
|
"pybind11"
|
2019-06-20 19:17:13 +01:00
|
|
|
"six_archive"
|
|
|
|
"snappy"
|
|
|
|
"swig"
|
|
|
|
"termcolor_archive"
|
|
|
|
"wrapt"
|
2020-08-01 09:20:04 +01:00
|
|
|
"zlib"
|
2019-06-20 19:17:13 +01:00
|
|
|
];
|
2017-10-15 13:23:56 +01:00
|
|
|
|
2019-07-13 20:42:50 +01:00
|
|
|
INCLUDEDIR = "${includes_joined}/include";
|
|
|
|
|
2019-08-31 19:02:19 +01:00
|
|
|
PYTHON_BIN_PATH = pythonEnv.interpreter;
|
|
|
|
|
2019-07-13 20:42:50 +01:00
|
|
|
TF_NEED_GCP = true;
|
|
|
|
TF_NEED_HDFS = true;
|
|
|
|
TF_ENABLE_XLA = tfFeature xlaSupport;
|
|
|
|
|
|
|
|
CC_OPT_FLAGS = " ";
|
|
|
|
|
|
|
|
# https://github.com/tensorflow/tensorflow/issues/14454
|
|
|
|
TF_NEED_MPI = tfFeature cudaSupport;
|
|
|
|
|
|
|
|
TF_NEED_CUDA = tfFeature cudaSupport;
|
|
|
|
TF_CUDA_PATHS = lib.optionalString cudaSupport "${cudatoolkit_joined},${cudnn},${nccl}";
|
|
|
|
GCC_HOST_COMPILER_PREFIX = lib.optionalString cudaSupport "${cudatoolkit_cc_joined}/bin";
|
2019-10-01 23:00:22 +01:00
|
|
|
GCC_HOST_COMPILER_PATH = lib.optionalString cudaSupport "${cudatoolkit_cc_joined}/bin/gcc";
|
2019-07-13 20:42:50 +01:00
|
|
|
TF_CUDA_COMPUTE_CAPABILITIES = lib.concatStringsSep "," cudaCapabilities;
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
# Tensorboard pulls in a bunch of dependencies, some of which may
|
|
|
|
# include security vulnerabilities. So we make it optional.
|
|
|
|
# https://github.com/tensorflow/tensorflow/issues/20280#issuecomment-400230560
|
|
|
|
sed -i '/tensorboard >=/d' tensorflow/tools/pip_package/setup.py
|
2020-08-01 09:20:04 +01:00
|
|
|
|
|
|
|
# numpy 1.19 added in https://github.com/tensorflow/tensorflow/commit/75ea0b31477d6ba9e990e296bbbd8ca4e7eebadf.patch
|
|
|
|
sed -i 's/numpy >= 1.16.0, < 1.19.0/numpy >= 1.16.0/' tensorflow/tools/pip_package/setup.py
|
|
|
|
|
|
|
|
# bazel 3.3 should work just as well as bazel 3.1
|
|
|
|
rm -f .bazelversion
|
2019-07-13 20:42:50 +01:00
|
|
|
'';
|
|
|
|
|
2019-07-18 12:49:30 +01:00
|
|
|
preConfigure = let
|
|
|
|
opt_flags = []
|
|
|
|
++ lib.optionals sse42Support ["-msse4.2"]
|
|
|
|
++ lib.optionals avx2Support ["-mavx2"]
|
|
|
|
++ lib.optionals fmaSupport ["-mfma"];
|
|
|
|
in ''
|
2017-10-15 13:23:56 +01:00
|
|
|
patchShebangs configure
|
|
|
|
|
2019-06-20 19:17:13 +01:00
|
|
|
# dummy ldconfig
|
|
|
|
mkdir dummy-ldconfig
|
|
|
|
echo "#!${stdenv.shell}" > dummy-ldconfig/ldconfig
|
|
|
|
chmod +x dummy-ldconfig/ldconfig
|
|
|
|
export PATH="$PWD/dummy-ldconfig:$PATH"
|
|
|
|
|
2017-11-10 17:07:58 +00:00
|
|
|
export PYTHON_LIB_PATH="$NIX_BUILD_TOP/site-packages"
|
2019-07-18 12:49:30 +01:00
|
|
|
export CC_OPT_FLAGS="${lib.concatStringsSep " " opt_flags}"
|
2017-11-10 17:07:58 +00:00
|
|
|
mkdir -p "$PYTHON_LIB_PATH"
|
2019-08-31 19:02:19 +01:00
|
|
|
|
|
|
|
# To avoid mixing Python 2 and Python 3
|
|
|
|
unset PYTHONPATH
|
2017-10-15 13:23:56 +01:00
|
|
|
'';
|
|
|
|
|
2019-06-20 19:17:13 +01:00
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
|
|
|
./configure
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
2019-07-13 20:42:50 +01:00
|
|
|
hardeningDisable = [ "format" ];
|
2017-10-15 13:23:56 +01:00
|
|
|
|
2019-07-18 12:49:30 +01:00
|
|
|
bazelBuildFlags = [
|
|
|
|
"--config=opt" # optimize using the flags set in the configure phase
|
2019-09-04 20:44:24 +01:00
|
|
|
]
|
|
|
|
++ lib.optionals (mklSupport) [ "--config=mkl" ];
|
2017-10-15 13:23:56 +01:00
|
|
|
|
2019-07-13 20:42:50 +01:00
|
|
|
bazelTarget = "//tensorflow/tools/pip_package:build_pip_package //tensorflow/tools/lib_package:libtensorflow";
|
2017-10-15 13:23:56 +01:00
|
|
|
|
2020-08-01 09:20:04 +01:00
|
|
|
removeRulesCC = false;
|
|
|
|
|
2017-11-10 17:07:58 +00:00
|
|
|
fetchAttrs = {
|
2019-08-27 00:43:32 +01:00
|
|
|
# So that checksums don't depend on these.
|
|
|
|
TF_SYSTEM_LIBS = null;
|
2017-10-15 13:23:56 +01:00
|
|
|
|
2019-06-20 19:17:13 +01:00
|
|
|
# cudaSupport causes fetch of ncclArchive, resulting in different hashes
|
|
|
|
sha256 = if cudaSupport then
|
2020-08-01 09:20:04 +01:00
|
|
|
"0pf8128chkm6fxnhd4956n6gvijlj00mjmvry33gq3xx3bayhs9g"
|
2019-06-20 19:17:13 +01:00
|
|
|
else
|
2020-08-01 09:20:04 +01:00
|
|
|
"0mkgss2nyk21zlj8hp24cs3dmpdnxk8qi6qq4hyc18lp82p09xwa";
|
2017-11-10 17:07:58 +00:00
|
|
|
};
|
2017-10-15 13:23:56 +01:00
|
|
|
|
2017-11-10 17:07:58 +00:00
|
|
|
buildAttrs = {
|
2019-07-13 20:42:50 +01:00
|
|
|
outputs = [ "out" "python" ];
|
|
|
|
|
2017-11-10 17:07:58 +00:00
|
|
|
preBuild = ''
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2019-07-13 20:42:50 +01:00
|
|
|
mkdir -p "$out"
|
|
|
|
tar -xf bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz -C "$out"
|
|
|
|
# Write pkgconfig file.
|
|
|
|
mkdir "$out/lib/pkgconfig"
|
|
|
|
cat > "$out/lib/pkgconfig/tensorflow.pc" << EOF
|
|
|
|
Name: TensorFlow
|
|
|
|
Version: ${version}
|
|
|
|
Description: Library for computation using data flow graphs for scalable machine learning
|
|
|
|
Requires:
|
|
|
|
Libs: -L$out/lib -ltensorflow
|
|
|
|
Cflags: -I$out/include/tensorflow
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# build the source code, then copy it to $python (build_pip_package
|
|
|
|
# actually builds a symlink farm so we must dereference them).
|
|
|
|
bazel-bin/tensorflow/tools/pip_package/build_pip_package --src "$PWD/dist"
|
|
|
|
cp -Lr "$PWD/dist" "$python"
|
2017-11-10 17:07:58 +00:00
|
|
|
'';
|
2019-10-02 08:32:48 +01:00
|
|
|
|
|
|
|
postFixup = lib.optionalString cudaSupport ''
|
|
|
|
find $out -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib; do
|
|
|
|
addOpenGLRunpath "$lib"
|
|
|
|
done
|
|
|
|
'';
|
2017-11-10 17:07:58 +00:00
|
|
|
};
|
2019-10-02 08:32:40 +01:00
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
|
|
|
description = "Computation using data flow graphs for scalable machine learning";
|
2020-04-01 02:11:51 +01:00
|
|
|
homepage = "http://tensorflow.org";
|
2019-10-02 08:32:40 +01:00
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ jyp abbradar ];
|
2019-11-27 03:15:40 +00:00
|
|
|
platforms = with platforms; linux ++ darwin;
|
2019-11-13 14:27:06 +00:00
|
|
|
# The py2 build fails due to some issue importing protobuf. Possibly related to the fix in
|
|
|
|
# https://github.com/akesandgren/easybuild-easyblocks/commit/1f2e517ddfd1b00a342c6abb55aef3fd93671a2b
|
|
|
|
broken = !(xlaSupport -> cudaSupport) || !isPy3k;
|
2019-10-02 08:32:40 +01:00
|
|
|
};
|
2017-11-10 17:07:58 +00:00
|
|
|
};
|
2017-10-15 13:23:56 +01:00
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
in buildPythonPackage {
|
2019-06-20 19:17:13 +01:00
|
|
|
inherit version pname;
|
2020-08-01 09:20:04 +01:00
|
|
|
disabled = isPy27;
|
2017-10-15 13:23:56 +01:00
|
|
|
|
2019-07-13 20:42:50 +01:00
|
|
|
src = bazel-build.python;
|
2017-02-15 11:30:30 +00:00
|
|
|
|
2019-06-20 19:17:13 +01:00
|
|
|
# Upstream has a pip hack that results in bin/tensorboard being in both tensorflow
|
|
|
|
# and the propagated input tensorflow-tensorboard, which causes environment collisions.
|
|
|
|
# Another possibility would be to have tensorboard only in the buildInputs
|
|
|
|
# https://github.com/tensorflow/tensorflow/blob/v1.7.1/tensorflow/tools/pip_package/setup.py#L79
|
|
|
|
postInstall = ''
|
|
|
|
rm $out/bin/tensorboard
|
2017-10-15 13:23:56 +01:00
|
|
|
'';
|
|
|
|
|
2019-08-31 19:02:19 +01:00
|
|
|
setupPyGlobalFlags = [ "--project_name ${pname}" ];
|
2019-07-13 20:42:50 +01:00
|
|
|
|
2019-06-20 19:17:13 +01:00
|
|
|
# tensorflow/tools/pip_package/setup.py
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
absl-py
|
|
|
|
astor
|
|
|
|
gast
|
|
|
|
google-pasta
|
|
|
|
keras-applications
|
|
|
|
keras-preprocessing
|
|
|
|
numpy
|
|
|
|
six
|
|
|
|
protobuf
|
2019-11-19 21:45:06 +00:00
|
|
|
tensorflow-estimator_2
|
2019-06-20 19:17:13 +01:00
|
|
|
termcolor
|
|
|
|
wrapt
|
|
|
|
grpcio
|
2019-10-07 09:14:16 +01:00
|
|
|
opt-einsum
|
2020-08-01 09:20:04 +01:00
|
|
|
astunparse
|
|
|
|
h5py
|
2019-06-20 19:17:13 +01:00
|
|
|
] ++ lib.optionals (!isPy3k) [
|
|
|
|
mock
|
2019-10-07 09:14:16 +01:00
|
|
|
future
|
2019-11-13 14:25:19 +00:00
|
|
|
functools32
|
2019-06-20 19:17:13 +01:00
|
|
|
] ++ lib.optionals (pythonOlder "3.4") [
|
|
|
|
backports_weakref enum34
|
|
|
|
] ++ lib.optionals withTensorboard [
|
2019-11-19 21:45:06 +00:00
|
|
|
tensorflow-tensorboard_2
|
2019-06-20 19:17:13 +01:00
|
|
|
];
|
2017-11-10 17:07:58 +00:00
|
|
|
|
2019-10-02 08:32:48 +01:00
|
|
|
nativeBuildInputs = lib.optional cudaSupport addOpenGLRunpath;
|
|
|
|
|
|
|
|
postFixup = lib.optionalString cudaSupport ''
|
|
|
|
find $out -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib; do
|
|
|
|
addOpenGLRunpath "$lib"
|
2020-08-01 09:20:04 +01:00
|
|
|
|
|
|
|
patchelf --set-rpath "${cudatoolkit}/lib:${cudatoolkit.lib}/lib:${cudnn}/lib:${nccl}/lib:$(patchelf --print-rpath "$lib")" "$lib"
|
2019-10-02 08:32:48 +01:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2017-11-10 17:07:58 +00:00
|
|
|
# Actual tests are slow and impure.
|
2019-06-20 19:17:13 +01:00
|
|
|
# TODO try to run them anyway
|
|
|
|
# TODO better test (files in tensorflow/tools/ci_build/builds/*test)
|
2017-11-10 17:07:58 +00:00
|
|
|
checkPhase = ''
|
2019-11-13 14:25:48 +00:00
|
|
|
${python.interpreter} <<EOF
|
|
|
|
# A simple "Hello world"
|
|
|
|
import tensorflow as tf
|
|
|
|
hello = tf.constant("Hello, world!")
|
2019-11-19 21:45:06 +00:00
|
|
|
tf.print(hello)
|
2019-11-13 14:25:48 +00:00
|
|
|
|
|
|
|
# Fit a simple model to random data
|
|
|
|
import numpy as np
|
|
|
|
np.random.seed(0)
|
2019-11-19 21:45:06 +00:00
|
|
|
tf.random.set_seed(0)
|
2019-11-13 14:25:48 +00:00
|
|
|
model = tf.keras.models.Sequential([
|
|
|
|
tf.keras.layers.Dense(1, activation="linear")
|
|
|
|
])
|
|
|
|
model.compile(optimizer="sgd", loss="mse")
|
|
|
|
|
|
|
|
x = np.random.uniform(size=(1,1))
|
|
|
|
y = np.random.uniform(size=(1,))
|
|
|
|
model.fit(x, y, epochs=1)
|
|
|
|
EOF
|
2017-10-15 13:23:56 +01:00
|
|
|
'';
|
2019-11-19 21:45:06 +00:00
|
|
|
# Regression test for #77626 removed because not more `tensorflow.contrib`.
|
2017-11-10 17:07:58 +00:00
|
|
|
|
2020-05-15 17:01:07 +01:00
|
|
|
passthru = {
|
|
|
|
deps = bazel-build.deps;
|
|
|
|
libtensorflow = bazel-build.out;
|
|
|
|
};
|
2019-07-13 20:42:50 +01:00
|
|
|
|
2019-10-02 08:32:40 +01:00
|
|
|
inherit (bazel-build) meta;
|
2017-11-10 17:07:58 +00:00
|
|
|
}
|