2021-01-10 11:50:33 +01:00
{ stdenv , bazel_3 , buildBazelPackage , isPy3k , lib , fetchFromGitHub , symlinkJoin
2019-10-02 10:32:48 +03:00
, addOpenGLRunpath
2019-07-13 22:42:50 +03:00
# Python deps
2021-01-10 11:50:33 +01:00
, buildPythonPackage , pythonOlder , pythonAtLeast , python
2019-07-13 22:42:50 +03:00
# Python libraries
2021-01-10 11:50:33 +01:00
, numpy , tensorflow-tensorboard_2 , absl-py
, future , setuptools , wheel , keras-preprocessing , google-pasta
2020-08-01 10:20:04 +02:00
, opt-einsum , astunparse , h5py
2019-11-19 22:45:06 +01:00
, termcolor , grpcio , six , wrapt , protobuf , tensorflow-estimator_2
2021-01-10 11:50:33 +01:00
, dill , flatbuffers-python , tblib , typing-extensions
2019-07-13 22:42:50 +03:00
# Common deps
2021-01-10 11:50:33 +01:00
, git , pybind11 , which , binutils , glibcLocales , cython , perl
2019-07-13 22:42:50 +03:00
# Common libraries
2021-01-10 13:40:19 +01:00
, jemalloc , mpi , gast , grpc , sqlite , boringssl , jsoncpp
2021-01-10 11:50:33 +01:00
, curl , snappy , flatbuffers-core , lmdb-core , icu , double-conversion , libpng , libjpeg_turbo , giflib
2019-10-07 10:14:16 +02: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 10:20:04 +02:00
, cudaSupport ? false , cudatoolkit ? null , cudnn ? null , nccl ? null
2019-09-04 15:44:24 -04:00
, mklSupport ? false , mkl ? null
2021-01-10 11:50:33 +01:00
, tensorboardSupport ? true
2018-02-27 03:16:33 +03:00
# XLA without CUDA is broken
, xlaSupport ? cudaSupport
2017-10-15 15:23:56 +03:00
# Default from ./configure script
2020-09-30 13:56:05 +02:00
, cudaCapabilities ? [ " s m _ 3 5 " " s m _ 5 0 " " s m _ 6 0 " " s m _ 7 0 " " s m _ 7 5 " " c o m p u t e _ 8 0 " ]
2020-08-05 02:32:41 +00:00
, sse42Support ? stdenv . hostPlatform . sse4_2Support
, avx2Support ? stdenv . hostPlatform . avx2Support
, fmaSupport ? stdenv . hostPlatform . fmaSupport
2019-11-26 22:15:40 -05:00
# Darwin deps
, Foundation , Security
2017-02-15 12:30:30 +01:00
}:
2020-08-01 10:20:04 +02:00
assert cudaSupport -> cudatoolkit != null
2017-10-15 15:23:56 +03:00
&& cudnn != null ;
2017-02-26 11:03:27 +01:00
# unsupported combination
assert ! ( stdenv . isDarwin && cudaSupport ) ;
2019-09-04 15:44:24 -04:00
assert mklSupport -> mkl != null ;
2017-10-15 15:23:56 +03:00
let
2021-01-10 11:50:33 +01:00
withTensorboard = ( pythonOlder " 3 . 6 " ) || tensorboardSupport ;
2017-02-15 12:30:30 +01:00
2017-10-03 15:50:39 +02:00
cudatoolkit_joined = symlinkJoin {
2019-07-13 22:42:50 +03:00
name = " ${ cudatoolkit . name } - m e r g e d " ;
2019-10-07 10:14:16 +02:00
paths = [
cudatoolkit . lib
cudatoolkit . out
2020-08-19 13:34:18 -05:00
] ++ lib . optionals ( lib . versionOlder cudatoolkit . version " 1 1 " ) [
2019-10-07 10:14:16 +02: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 } / t a r g e t s / ${ stdenv . system } "
] ;
2017-10-15 15:23:56 +03:00
} ;
2017-10-03 15:50:39 +02:00
2019-07-13 22:42:50 +03:00
cudatoolkit_cc_joined = symlinkJoin {
name = " ${ cudatoolkit . cc . name } - m e r g e d " ;
2019-06-20 20:17:13 +02:00
paths = [
cudatoolkit . cc
binutils . bintools # for ar, dwp, nm, objcopy, objdump, strip
] ;
} ;
2019-07-13 22:42:50 +03:00
# Needed for _some_ system libraries, grep INCLUDEDIR.
includes_joined = symlinkJoin {
name = " t e n s o r f l o w - d e p s - m e r g e d " ;
paths = [
jsoncpp
] ;
} ;
2017-10-15 15:23:56 +03:00
tfFeature = x : if x then " 1 " else " 0 " ;
2017-02-15 12:30:30 +01:00
2021-01-10 11:50:33 +01:00
version = " 2 . 4 . 0 " ;
2019-07-13 22:42:50 +03:00
variant = if cudaSupport then " - g p u " else " " ;
2019-06-20 20:17:13 +02:00
pname = " t e n s o r f l o w ${ variant } " ;
2017-11-10 20:07:58 +03:00
2019-08-31 21:02:19 +03:00
pythonEnv = python . withPackages ( _ :
2019-10-07 10:14:16 +02:00
[ # python deps needed during wheel build time (not runtime, see the buildPythonPackage part for that)
2021-01-10 11:50:33 +01:00
# This list can likely be shortened, but each trial takes multiple hours so won't bother for now.
2019-08-31 21:02:19 +03:00
absl-py
2021-01-10 11:50:33 +01:00
astunparse
dill
flatbuffers-python
gast
google-pasta
grpcio
h5py
keras-preprocessing
numpy
opt-einsum
protobuf
2019-08-31 21:02:19 +03:00
setuptools
2021-01-10 11:50:33 +01:00
six
tblib
tensorflow-estimator_2
tensorflow-tensorboard_2
termcolor
typing-extensions
2019-08-31 21:02:19 +03:00
wheel
2021-01-10 11:50:33 +01:00
wrapt
2019-08-31 21:02:19 +03:00
] ) ;
2019-07-13 22:42:50 +03:00
2019-08-13 21:52:01 +00:00
bazel-build = buildBazelPackage {
2019-07-13 22:42:50 +03:00
name = " ${ pname } - ${ version } " ;
2020-08-01 10:20:04 +02:00
bazel = bazel_3 ;
2017-10-15 15:23:56 +03:00
src = fetchFromGitHub {
owner = " t e n s o r f l o w " ;
repo = " t e n s o r f l o w " ;
2019-07-13 22:42:50 +03:00
rev = " v ${ version } " ;
2021-01-10 11:50:33 +01:00
sha256 = " 0 y l 0 6 a y p f x r c s 3 5 8 2 8 x f 0 4 m k i d z 1 x 0 j 8 9 v 0 q 5 h 4 d 2 x p s 1 c b 5 r v 3 f " ;
2017-10-15 15:23:56 +03:00
} ;
2017-11-10 20:07:58 +03:00
patches = [
2021-01-10 11:50:33 +01:00
# Relax too strict Python packages versions dependencies.
2020-12-12 18:51:11 +01:00
./relax-dependencies.patch
2021-01-10 11:50:33 +01:00
# Add missing `io_bazel_rules_docker` dependency.
./workspace.patch
2017-11-10 20:07:58 +03:00
] ;
2017-10-15 15:23:56 +03:00
2019-06-20 20:17:13 +02: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 22:42:50 +03:00
nativeBuildInputs = [
2021-01-10 11:50:33 +01:00
which pythonEnv cython perl
2019-10-02 10:32:48 +03:00
] ++ lib . optional cudaSupport addOpenGLRunpath ;
2017-10-15 15:23:56 +03:00
2019-06-20 20:17:13 +02:00
buildInputs = [
jemalloc
2021-01-10 13:40:19 +01:00
mpi
2019-06-20 20:17:13 +02:00
glibcLocales
git
# libs taken from system through the TF_SYS_LIBS mechanism
2020-08-01 10:20:04 +02:00
grpc
2019-07-13 22:42:50 +03:00
sqlite
2021-01-10 11:50:33 +01:00
boringssl
2019-07-13 22:42:50 +03:00
jsoncpp
curl
2021-01-10 11:50:33 +01:00
pybind11
2019-07-13 22:42:50 +03:00
snappy
2021-01-10 11:50:33 +01:00
flatbuffers-core
2019-07-13 22:42:50 +03:00
icu
double-conversion
libpng
2021-01-10 11:50:33 +01:00
libjpeg_turbo
2019-07-13 22:42:50 +03:00
giflib
2021-01-10 11:50:33 +01:00
lmdb-core
2019-06-20 20:17:13 +02:00
] ++ lib . optionals cudaSupport [
cudatoolkit
cudnn
2019-09-04 15:44:24 -04:00
] ++ lib . optionals mklSupport [
mkl
2019-11-26 22:15:40 -05:00
] ++ lib . optionals stdenv . isDarwin [
Foundation
Security
2019-06-20 20:17:13 +02:00
] ;
2019-07-13 22:42:50 +03:00
# arbitrarily set to the current latest bazel version, overly careful
TF_IGNORE_MAX_BAZEL_VERSION = true ;
2019-06-20 20:17:13 +02:00
# Take as many libraries from the system as possible. Keep in sync with
# list of valid syslibs in
2019-07-13 22:42:50 +03:00
# https://github.com/tensorflow/tensorflow/blob/master/third_party/systemlibs/syslibs_configure.bzl
TF_SYSTEM_LIBS = lib . concatStringsSep " , " [
2019-06-20 20:17:13 +02:00
" a b s l _ p y "
" a s t o r _ a r c h i v e "
2020-08-01 10:20:04 +02:00
" a s t u n p a r s e _ a r c h i v e "
2019-06-20 20:17:13 +02:00
" b o r i n g s s l "
2019-07-13 22:42:50 +03:00
# Not packaged in nixpkgs
# "com_github_googleapis_googleapis"
# "com_github_googlecloudplatform_google_cloud_cpp"
2020-08-01 10:20:04 +02:00
" c o m _ g i t h u b _ g r p c _ g r p c "
2021-01-10 11:50:33 +01:00
# Multiple issues with custom protobuf.
# First `com_github_googleapis` fails to configure. Can be worked around by disabling `com_github_googleapis`
# and related functionality, but then the next error is about "dangling symbolic link", and in general
# looks like that's only the beginning: see
# https://stackoverflow.com/questions/55578884/how-to-build-tensorflow-1-13-1-with-custom-protobuf
# "com_google_protobuf"
# Fails with the error: external/org_tensorflow/tensorflow/core/profiler/utils/tf_op_utils.cc:46:49: error: no matching function for call to 're2::RE2::FullMatch(absl::lts_2020_02_25::string_view&, re2::RE2&)'
# "com_googlesource_code_re2"
2019-06-20 20:17:13 +02:00
" c u r l "
" c y t h o n "
2021-01-10 11:50:33 +01:00
" d i l l _ a r c h i v e "
2019-06-20 20:17:13 +02:00
" d o u b l e _ c o n v e r s i o n "
2020-08-01 10:20:04 +02:00
" e n u m 3 4 _ a r c h i v e "
2019-06-20 20:17:13 +02:00
" f l a t b u f f e r s "
2020-08-01 10:20:04 +02:00
" f u n c t o o l s 3 2 _ a r c h i v e "
2019-06-20 20:17:13 +02:00
" g a s t _ a r c h i v e "
2020-08-01 10:20:04 +02:00
" g i f "
2019-06-20 20:17:13 +02:00
" h w l o c "
" i c u "
" j s o n c p p _ g i t "
2020-08-01 10:20:04 +02:00
" l i b j p e g _ t u r b o "
2019-06-20 20:17:13 +02:00
" l m d b "
" n a s m "
# "nsync" # not packaged in nixpkgs
2019-10-07 10:14:16 +02:00
" o p t _ e i n s u m _ a r c h i v e "
2019-07-13 22:42:50 +03:00
" o r g _ s q l i t e "
2019-06-20 20:17:13 +02:00
" p a s t a "
" p c r e "
2020-08-01 10:20:04 +02:00
" p n g "
" p y b i n d 1 1 "
2019-06-20 20:17:13 +02:00
" s i x _ a r c h i v e "
" s n a p p y "
2021-01-10 11:50:33 +01:00
" t b l i b _ a r c h i v e "
2019-06-20 20:17:13 +02:00
" t e r m c o l o r _ a r c h i v e "
2021-01-10 11:50:33 +01:00
" t y p i n g _ e x t e n s i o n s _ a r c h i v e "
2019-06-20 20:17:13 +02:00
" w r a p t "
2020-08-01 10:20:04 +02:00
" z l i b "
2019-06-20 20:17:13 +02:00
] ;
2017-10-15 15:23:56 +03:00
2019-07-13 22:42:50 +03:00
INCLUDEDIR = " ${ includes_joined } / i n c l u d e " ;
2019-08-31 21:02:19 +03:00
PYTHON_BIN_PATH = pythonEnv . interpreter ;
2019-07-13 22:42:50 +03: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 } / b i n " ;
2019-10-02 01:00:22 +03:00
GCC_HOST_COMPILER_PATH = lib . optionalString cudaSupport " ${ cudatoolkit_cc_joined } / b i n / g c c " ;
2019-07-13 22:42:50 +03:00
TF_CUDA_COMPUTE_CAPABILITIES = lib . concatStringsSep " , " cudaCapabilities ;
postPatch = ''
2021-01-10 11:50:33 +01:00
# b a z e l 3 . 3 s h o u l d w o r k j u s t a s w e l l a s b a z e l 3 . 1
r m - f . b a z e l v e r s i o n
'' + lib . optionalString ( ! withTensorboard ) ''
2019-07-13 22:42:50 +03:00
# T e n s o r b o a r d p u l l s i n a b u n c h o f d e p e n d e n c i e s , s o m e o f w h i c h m a y
# i n c l u d e s e c u r i t y v u l n e r a b i l i t i e s . S o w e m a k e i t o p t i o n a l .
# h t t p s : / / g i t h u b . c o m / t e n s o r f l o w / t e n s o r f l o w / i s s u e s / 2 0 2 8 0 # i s s u e c o m m e n t - 4 0 0 2 3 0 5 6 0
2021-01-10 11:50:33 +01:00
s e d - i ' / t e n s o r b o a r d ~ = / d ' t e n s o r f l o w / t o o l s / p i p _ p a c k a g e / s e t u p . p y
2019-07-13 22:42:50 +03:00
'' ;
2021-01-07 15:34:10 +01:00
# https://github.com/tensorflow/tensorflow/pull/39470
NIX_CFLAGS_COMPILE = [ " - W n o - s t r i n g o p - t r u n c a t i o n " ] ;
2019-07-18 13:49:30 +02:00
preConfigure = let
opt_flags = [ ]
++ lib . optionals sse42Support [ " - m s s e 4 . 2 " ]
++ lib . optionals avx2Support [ " - m a v x 2 " ]
++ lib . optionals fmaSupport [ " - m f m a " ] ;
in ''
2017-10-15 15:23:56 +03:00
p a t c h S h e b a n g s c o n f i g u r e
2019-06-20 20:17:13 +02:00
# d u m m y l d c o n f i g
m k d i r d u m m y - l d c o n f i g
e c h o " # ! ${ stdenv . shell } " > d u m m y - l d c o n f i g / l d c o n f i g
c h m o d + x d u m m y - l d c o n f i g / l d c o n f i g
e x p o r t P A T H = " $P W D / d u m m y - l d c o n f i g : $P A T H "
2017-11-10 20:07:58 +03:00
e x p o r t P Y T H O N _ L I B _ P A T H = " $N I X _ B U I L D _ T O P / s i t e - p a c k a g e s "
2019-07-18 13:49:30 +02:00
e x p o r t C C _ O P T _ F L A G S = " ${ lib . concatStringsSep " " opt_flags } "
2017-11-10 20:07:58 +03:00
m k d i r - p " $P Y T H O N _ L I B _ P A T H "
2019-08-31 21:02:19 +03:00
# T o a v o i d m i x i n g P y t h o n 2 a n d P y t h o n 3
u n s e t P Y T H O N P A T H
2017-10-15 15:23:56 +03:00
'' ;
2019-06-20 20:17:13 +02:00
configurePhase = ''
r u n H o o k p r e C o n f i g u r e
. / c o n f i g u r e
r u n H o o k p o s t C o n f i g u r e
'' ;
2019-07-13 22:42:50 +03:00
hardeningDisable = [ " f o r m a t " ] ;
2017-10-15 15:23:56 +03:00
2019-07-18 13:49:30 +02:00
bazelBuildFlags = [
" - - c o n f i g = o p t " # optimize using the flags set in the configure phase
2019-09-04 15:44:24 -04:00
]
++ lib . optionals ( mklSupport ) [ " - - c o n f i g = m k l " ] ;
2017-10-15 15:23:56 +03:00
2019-07-13 22:42:50 +03:00
bazelTarget = " / / t e n s o r f l o w / t o o l s / p i p _ p a c k a g e : b u i l d _ p i p _ p a c k a g e / / t e n s o r f l o w / t o o l s / l i b _ p a c k a g e : l i b t e n s o r f l o w " ;
2017-10-15 15:23:56 +03:00
2020-08-01 10:20:04 +02:00
removeRulesCC = false ;
2021-01-10 11:50:33 +01:00
# Without this Bazel complaints about sandbox violations.
dontAddBazelOpts = true ;
2020-08-01 10:20:04 +02:00
2017-11-10 20:07:58 +03:00
fetchAttrs = {
2019-06-20 20:17:13 +02:00
# cudaSupport causes fetch of ncclArchive, resulting in different hashes
sha256 = if cudaSupport then
2020-12-19 21:10:51 +01:00
" 1 i 7 z 2 a 7 b c 2 q 1 v n 1 h 9 n x 1 x c 6 g 1 r 1 c b y 2 x v b c s 2 0 f j 9 h 6 c 2 f g a w 9 j 4 "
2019-06-20 20:17:13 +02:00
else
2020-12-19 21:10:51 +01:00
" 0 s 8 q 5 r x q 8 a b r 5 0 c 5 j p w v 9 6 n c f c 0 k 8 j w 7 w 7 0 r i 8 v i q y 0 3 1 g 9 v 9 v 4 5 " ;
2017-10-15 15:23:56 +03:00
} ;
2017-11-10 20:07:58 +03:00
buildAttrs = {
2019-07-13 22:42:50 +03:00
outputs = [ " o u t " " p y t h o n " ] ;
2017-11-10 20:07:58 +03:00
preBuild = ''
p a t c h S h e b a n g s .
'' ;
2017-10-15 15:23:56 +03:00
2017-11-10 20:07:58 +03:00
installPhase = ''
2019-07-13 22:42:50 +03:00
m k d i r - p " $o u t "
t a r - x f b a z e l - b i n / t e n s o r f l o w / t o o l s / l i b _ p a c k a g e / l i b t e n s o r f l o w . t a r . g z - C " $o u t "
# W r i t e p k g c o n f i g f i l e .
m k d i r " $o u t / l i b / p k g c o n f i g "
c a t > " $o u t / l i b / p k g c o n f i g / t e n s o r f l o w . p c " < < E O F
N a m e : T e n s o r F l o w
V e r s i o n : ${ version }
D e s c r i p t i o n : L i b r a r y f o r c o m p u t a t i o n u s i n g d a t a f l o w g r a p h s f o r s c a l a b l e m a c h i n e l e a r n i n g
R e q u i r e s :
L i b s : - L $o u t / l i b - l t e n s o r f l o w
C f l a g s : - I $o u t / i n c l u d e / t e n s o r f l o w
E O F
2019-06-20 20:17:13 +02:00
2019-07-13 22:42:50 +03:00
# b u i l d t h e s o u r c e c o d e , t h e n c o p y i t t o $p y t h o n ( b u i l d _ p i p _ p a c k a g e
# a c t u a l l y b u i l d s a s y m l i n k f a r m s o w e m u s t d e r e f e r e n c e t h e m ) .
b a z e l - b i n / t e n s o r f l o w / t o o l s / p i p _ p a c k a g e / b u i l d _ p i p _ p a c k a g e - - s r c " $P W D / d i s t "
c p - L r " $P W D / d i s t " " $p y t h o n "
2017-11-10 20:07:58 +03:00
'' ;
2019-10-02 10:32:48 +03:00
postFixup = lib . optionalString cudaSupport ''
f i n d $o u t - t y p e f \ ( - n a m e ' * . s o ' - o r - n a m e ' * . s o . * ' \ ) | w h i l e r e a d l i b ; d o
a d d O p e n G L R u n p a t h " $l i b "
d o n e
'' ;
2017-11-10 20:07:58 +03:00
} ;
2019-10-02 10:32:40 +03:00
2021-01-11 08:54:33 +01:00
meta = with lib ; {
2019-10-02 10:32:40 +03:00
description = " C o m p u t a t i o n u s i n g d a t a f l o w g r a p h s f o r s c a l a b l e m a c h i n e l e a r n i n g " ;
2020-03-31 21:11:51 -04:00
homepage = " h t t p : / / t e n s o r f l o w . o r g " ;
2019-10-02 10:32:40 +03:00
license = licenses . asl20 ;
maintainers = with maintainers ; [ jyp abbradar ] ;
2019-11-26 22:15:40 -05:00
platforms = with platforms ; linux ++ darwin ;
2021-01-10 11:50:33 +01:00
broken = ! ( xlaSupport -> cudaSupport ) ;
2019-10-02 10:32:40 +03:00
} ;
2017-11-10 20:07:58 +03:00
} ;
2017-10-15 15:23:56 +03:00
2019-08-13 21:52:01 +00:00
in buildPythonPackage {
2019-06-20 20:17:13 +02:00
inherit version pname ;
2021-01-10 11:50:33 +01:00
disabled = ! isPy3k ;
2017-10-15 15:23:56 +03:00
2019-07-13 22:42:50 +03:00
src = bazel-build . python ;
2017-02-15 12:30:30 +01:00
2019-06-20 20:17:13 +02: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 = ''
r m $o u t / b i n / t e n s o r b o a r d
2017-10-15 15:23:56 +03:00
'' ;
2019-08-31 21:02:19 +03:00
setupPyGlobalFlags = [ " - - p r o j e c t _ n a m e ${ pname } " ] ;
2019-07-13 22:42:50 +03:00
2019-06-20 20:17:13 +02:00
# tensorflow/tools/pip_package/setup.py
propagatedBuildInputs = [
absl-py
2021-01-10 11:50:33 +01:00
astunparse
dill
flatbuffers-python
2019-06-20 20:17:13 +02:00
gast
google-pasta
2021-01-10 11:50:33 +01:00
grpcio
h5py
2019-06-20 20:17:13 +02:00
keras-preprocessing
numpy
2021-01-10 11:50:33 +01:00
opt-einsum
2019-06-20 20:17:13 +02:00
protobuf
2021-01-10 11:50:33 +01:00
six
tblib
2019-11-19 22:45:06 +01:00
tensorflow-estimator_2
2019-06-20 20:17:13 +02:00
termcolor
2021-01-10 11:50:33 +01:00
typing-extensions
2019-06-20 20:17:13 +02:00
wrapt
] ++ lib . optionals withTensorboard [
2019-11-19 22:45:06 +01:00
tensorflow-tensorboard_2
2019-06-20 20:17:13 +02:00
] ;
2017-11-10 20:07:58 +03:00
2019-10-02 10:32:48 +03:00
nativeBuildInputs = lib . optional cudaSupport addOpenGLRunpath ;
postFixup = lib . optionalString cudaSupport ''
f i n d $o u t - t y p e f \ ( - n a m e ' * . s o ' - o r - n a m e ' * . s o . * ' \ ) | w h i l e r e a d l i b ; d o
a d d O p e n G L R u n p a t h " $l i b "
2020-08-01 10:20:04 +02:00
p a t c h e l f - - s e t - r p a t h " ${ cudatoolkit } / l i b : ${ cudatoolkit . lib } / l i b : ${ cudnn } / l i b : ${ nccl } / l i b : $( p a t c h e l f - - p r i n t - r p a t h " $l i b " ) " " $l i b "
2019-10-02 10:32:48 +03:00
d o n e
'' ;
2017-11-10 20:07:58 +03:00
# Actual tests are slow and impure.
2019-06-20 20:17:13 +02:00
# TODO try to run them anyway
# TODO better test (files in tensorflow/tools/ci_build/builds/*test)
2017-11-10 20:07:58 +03:00
checkPhase = ''
2019-11-13 15:25:48 +01:00
${ python . interpreter } < < E O F
# A s i m p l e " H e l l o w o r l d "
i m p o r t t e n s o r f l o w a s t f
h e l l o = t f . c o n s t a n t ( " H e l l o , w o r l d ! " )
2019-11-19 22:45:06 +01:00
t f . p r i n t ( h e l l o )
2019-11-13 15:25:48 +01:00
# F i t a s i m p l e m o d e l t o r a n d o m d a t a
i m p o r t n u m p y a s n p
n p . r a n d o m . s e e d ( 0 )
2019-11-19 22:45:06 +01:00
t f . r a n d o m . s e t _ s e e d ( 0 )
2019-11-13 15:25:48 +01:00
m o d e l = t f . k e r a s . m o d e l s . S e q u e n t i a l ( [
t f . k e r a s . l a y e r s . D e n s e ( 1 , a c t i v a t i o n = " l i n e a r " )
] )
m o d e l . c o m p i l e ( o p t i m i z e r = " s g d " , l o s s = " m s e " )
x = n p . r a n d o m . u n i f o r m ( s i z e = ( 1 , 1 ) )
y = n p . r a n d o m . u n i f o r m ( s i z e = ( 1 , ) )
m o d e l . f i t ( x , y , e p o c h s = 1 )
E O F
2017-10-15 15:23:56 +03:00
'' ;
2019-11-19 22:45:06 +01:00
# Regression test for #77626 removed because not more `tensorflow.contrib`.
2017-11-10 20:07:58 +03:00
2020-05-15 12:01:07 -04:00
passthru = {
deps = bazel-build . deps ;
libtensorflow = bazel-build . out ;
} ;
2019-07-13 22:42:50 +03:00
2019-10-02 10:32:40 +03:00
inherit ( bazel-build ) meta ;
2017-11-10 20:07:58 +03:00
}