1{ stdenv, bazel_5, buildBazelPackage, lib, fetchFromGitHub, symlinkJoin
2, addOpenGLRunpath, fetchpatch, fetchzip, linkFarm
3# Python deps
4, buildPythonPackage, pythonOlder, python
5# Python libraries
6, numpy, tensorboard, abseil-cpp, absl-py
7, packaging, setuptools, wheel, keras-preprocessing, google-pasta
8, opt-einsum, astunparse, h5py
9, termcolor, grpcio, six, wrapt, protobuf-python, tensorflow-estimator-bin
10, dill, flatbuffers-python, portpicker, tblib, typing-extensions
11# Common deps
12, git, pybind11, which, binutils, glibcLocales, cython, perl
13# Common libraries
14, jemalloc, mpi, gast, grpc, sqlite, boringssl, jsoncpp, nsync
15, curl, snappy, flatbuffers-core, icu, double-conversion, libpng, libjpeg_turbo, giflib, protobuf-core
16# Upstream by default includes cuda support since tensorflow 1.15. We could do
17# that in nix as well. It would make some things easier and less confusing, but
18# it would also make the default tensorflow package unfree. See
19# https://groups.google.com/a/tensorflow.org/forum/#!topic/developers/iRCt5m4qUz0
20, config
21, cudaSupport ? config.cudaSupport
22, cudaPackages ? { }
23, cudaCapabilities ? cudaPackages.cudaFlags.cudaCapabilities
24, mklSupport ? false, mkl
25, tensorboardSupport ? true
26# XLA without CUDA is broken
27, xlaSupport ? cudaSupport
28, sse42Support ? stdenv.hostPlatform.sse4_2Support
29, avx2Support ? stdenv.hostPlatform.avx2Support
30, fmaSupport ? stdenv.hostPlatform.fmaSupport
31# Darwin deps
32, Foundation, Security, cctools, llvmPackages_11
33}:
34
35let
36 originalStdenv = stdenv;
37in
38let
39 # Tensorflow looks at many toolchain-related variables which may diverge.
40 #
41 # Toolchain for cuda-enabled builds.
42 # We want to achieve two things:
43 # 1. NVCC should use a compatible back-end (e.g. gcc11 for cuda11)
44 # 2. Normal C++ files should be compiled with the same toolchain,
45 # to avoid potential weird dynamic linkage errors at runtime.
46 # This may not be necessary though
47 #
48 # Toolchain for Darwin:
49 # clang 7 fails to emit a symbol for
50 # __ZN4llvm11SmallPtrSetIPKNS_10AllocaInstELj8EED1Ev in any of the
51 # translation units, so the build fails at link time
52 stdenv =
53 if cudaSupport then cudaPackages.backendStdenv
54 else if originalStdenv.isDarwin then llvmPackages_11.stdenv
55 else originalStdenv;
56 inherit (cudaPackages) cudatoolkit nccl;
57 # use compatible cuDNN (https://www.tensorflow.org/install/source#gpu)
58 # cudaPackages.cudnn led to this:
59 # https://github.com/tensorflow/tensorflow/issues/60398
60 cudnn = cudaPackages.cudnn_8_6;
61 gentoo-patches = fetchzip {
62 url = "https://dev.gentoo.org/~perfinion/patches/tensorflow-patches-2.12.0.tar.bz2";
63 hash = "sha256-SCRX/5/zML7LmKEPJkcM5Tebez9vv/gmE4xhT/jyqWs=";
64 };
65 protobuf-extra = linkFarm "protobuf-extra" [
66 { name = "include"; path = protobuf-core.src; }
67 ];
68in
69
70assert cudaSupport -> cudatoolkit != null
71 && cudnn != null;
72
73# unsupported combination
74assert ! (stdenv.isDarwin && cudaSupport);
75
76let
77 withTensorboard = (pythonOlder "3.6") || tensorboardSupport;
78
79 # FIXME: migrate to redist cudaPackages
80 cudatoolkit_joined = symlinkJoin {
81 name = "${cudatoolkit.name}-merged";
82 paths = [
83 cudatoolkit.lib
84 cudatoolkit.out
85 ] ++ lib.optionals (lib.versionOlder cudatoolkit.version "11") [
86 # for some reason some of the required libs are in the targets/x86_64-linux
87 # directory; not sure why but this works around it
88 "${cudatoolkit}/targets/${stdenv.system}"
89 ];
90 };
91
92 # Tensorflow expects bintools at hard-coded paths, e.g. /usr/bin/ar
93 # The only way to overcome that is to set GCC_HOST_COMPILER_PREFIX,
94 # but that path must contain cc as well, so we merge them
95 cudatoolkit_cc_joined = symlinkJoin {
96 name = "${stdenv.cc.name}-merged";
97 paths = [
98 stdenv.cc
99 binutils.bintools # for ar, dwp, nm, objcopy, objdump, strip
100 ];
101 };
102
103 # Needed for _some_ system libraries, grep INCLUDEDIR.
104 includes_joined = symlinkJoin {
105 name = "tensorflow-deps-merged";
106 paths = [
107 jsoncpp
108 ];
109 };
110
111 tfFeature = x: if x then "1" else "0";
112
113 version = "2.13.0";
114 variant = lib.optionalString cudaSupport "-gpu";
115 pname = "tensorflow${variant}";
116
117 pythonEnv = python.withPackages (_:
118 [ # python deps needed during wheel build time (not runtime, see the buildPythonPackage part for that)
119 # This list can likely be shortened, but each trial takes multiple hours so won't bother for now.
120 absl-py
121 astunparse
122 dill
123 flatbuffers-python
124 gast
125 google-pasta
126 grpcio
127 h5py
128 keras-preprocessing
129 numpy
130 opt-einsum
131 packaging
132 protobuf-python
133 setuptools
134 six
135 tblib
136 tensorboard
137 tensorflow-estimator-bin
138 termcolor
139 typing-extensions
140 wheel
141 wrapt
142 ]);
143
144 rules_cc_darwin_patched = stdenv.mkDerivation {
145 name = "rules_cc-${pname}-${version}";
146
147 src = _bazel-build.deps;
148
149 prePatch = "pushd rules_cc";
150 patches = [
151 # https://github.com/bazelbuild/rules_cc/issues/122
152 (fetchpatch {
153 name = "tensorflow-rules_cc-libtool-path.patch";
154 url = "https://github.com/bazelbuild/rules_cc/commit/8c427ab30bf213630dc3bce9d2e9a0e29d1787db.diff";
155 hash = "sha256-C4v6HY5+jm0ACUZ58gBPVejCYCZfuzYKlHZ0m2qDHCk=";
156 })
157
158 # https://github.com/bazelbuild/rules_cc/pull/124
159 (fetchpatch {
160 name = "tensorflow-rules_cc-install_name_tool-path.patch";
161 url = "https://github.com/bazelbuild/rules_cc/commit/156497dc89100db8a3f57b23c63724759d431d05.diff";
162 hash = "sha256-NES1KeQmMiUJQVoV6dS4YGRxxkZEjOpFSCyOq9HZYO0=";
163 })
164 ];
165 postPatch = "popd";
166
167 dontConfigure = true;
168 dontBuild = true;
169
170 installPhase = ''
171 runHook preInstall
172
173 mv rules_cc/ "$out"
174
175 runHook postInstall
176 '';
177 };
178 llvm-raw_darwin_patched = stdenv.mkDerivation {
179 name = "llvm-raw-${pname}-${version}";
180
181 src = _bazel-build.deps;
182
183 prePatch = "pushd llvm-raw";
184 patches = [
185 # Fix a vendored config.h that requires the 10.13 SDK
186 ./llvm_bazel_fix_macos_10_12_sdk.patch
187 ];
188 postPatch = ''
189 touch {BUILD,WORKSPACE}
190 popd
191 '';
192
193 dontConfigure = true;
194 dontBuild = true;
195
196 installPhase = ''
197 runHook preInstall
198
199 mv llvm-raw/ "$out"
200
201 runHook postInstall
202 '';
203 };
204 bazel-build = if stdenv.isDarwin then _bazel-build.overrideAttrs (prev: {
205 bazelFlags = prev.bazelFlags ++ [
206 "--override_repository=rules_cc=${rules_cc_darwin_patched}"
207 "--override_repository=llvm-raw=${llvm-raw_darwin_patched}"
208 ];
209 preBuild = ''
210 export AR="${cctools}/bin/libtool"
211 '';
212 }) else _bazel-build;
213
214 _bazel-build = buildBazelPackage.override { inherit stdenv; } {
215 name = "${pname}-${version}";
216 bazel = bazel_5;
217
218 src = fetchFromGitHub {
219 owner = "tensorflow";
220 repo = "tensorflow";
221 rev = "refs/tags/v${version}";
222 hash = "sha256-Rq5pAVmxlWBVnph20fkAwbfy+iuBNlfFy14poDPd5h0=";
223 };
224
225 # On update, it can be useful to steal the changes from gentoo
226 # https://gitweb.gentoo.org/repo/gentoo.git/tree/sci-libs/tensorflow
227
228 nativeBuildInputs = [
229 which pythonEnv cython perl protobuf-core protobuf-extra
230 ] ++ lib.optional cudaSupport addOpenGLRunpath;
231
232 buildInputs = [
233 jemalloc
234 mpi
235 glibcLocales
236 git
237
238 # libs taken from system through the TF_SYS_LIBS mechanism
239 abseil-cpp
240 boringssl
241 curl
242 double-conversion
243 flatbuffers-core
244 giflib
245 grpc
246 # Necessary to fix the "`GLIBCXX_3.4.30' not found" error
247 (icu.override { inherit stdenv; })
248 jsoncpp
249 libjpeg_turbo
250 libpng
251 (pybind11.overridePythonAttrs (_: { inherit stdenv; }))
252 snappy
253 sqlite
254 ] ++ lib.optionals cudaSupport [
255 cudatoolkit
256 cudnn
257 ] ++ lib.optionals mklSupport [
258 mkl
259 ] ++ lib.optionals stdenv.isDarwin [
260 Foundation
261 Security
262 ] ++ lib.optionals (!stdenv.isDarwin) [
263 nsync
264 ];
265
266 # arbitrarily set to the current latest bazel version, overly careful
267 TF_IGNORE_MAX_BAZEL_VERSION = true;
268
269 LIBTOOL = lib.optionalString stdenv.isDarwin "${cctools}/bin/libtool";
270
271 # Take as many libraries from the system as possible. Keep in sync with
272 # list of valid syslibs in
273 # https://github.com/tensorflow/tensorflow/blob/master/third_party/systemlibs/syslibs_configure.bzl
274 TF_SYSTEM_LIBS = lib.concatStringsSep "," ([
275 "absl_py"
276 "astor_archive"
277 "astunparse_archive"
278 "boringssl"
279 "com_google_absl"
280 # Not packaged in nixpkgs
281 # "com_github_googleapis_googleapis"
282 # "com_github_googlecloudplatform_google_cloud_cpp"
283 "com_github_grpc_grpc"
284 "com_google_protobuf"
285 # 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&)'
286 # "com_googlesource_code_re2"
287 "curl"
288 "cython"
289 "dill_archive"
290 "double_conversion"
291 "flatbuffers"
292 "functools32_archive"
293 "gast_archive"
294 "gif"
295 "hwloc"
296 "icu"
297 "jsoncpp_git"
298 "libjpeg_turbo"
299 "nasm"
300 "opt_einsum_archive"
301 "org_sqlite"
302 "pasta"
303 "png"
304 "pybind11"
305 "six_archive"
306 "snappy"
307 "tblib_archive"
308 "termcolor_archive"
309 "typing_extensions_archive"
310 "wrapt"
311 "zlib"
312 ] ++ lib.optionals (!stdenv.isDarwin) [
313 "nsync" # fails to build on darwin
314 ]);
315
316 INCLUDEDIR = "${includes_joined}/include";
317
318 # This is needed for the Nix-provided protobuf dependency to work,
319 # as otherwise the rule `link_proto_files` tries to create the links
320 # to `/usr/include/...` which results in build failures.
321 PROTOBUF_INCLUDE_PATH = "${protobuf-core}/include";
322
323 PYTHON_BIN_PATH = pythonEnv.interpreter;
324
325 TF_NEED_GCP = true;
326 TF_NEED_HDFS = true;
327 TF_ENABLE_XLA = tfFeature xlaSupport;
328
329 CC_OPT_FLAGS = " ";
330
331 # https://github.com/tensorflow/tensorflow/issues/14454
332 TF_NEED_MPI = tfFeature cudaSupport;
333
334 TF_NEED_CUDA = tfFeature cudaSupport;
335 TF_CUDA_PATHS = lib.optionalString cudaSupport "${cudatoolkit_joined},${cudnn},${nccl}";
336 TF_CUDA_COMPUTE_CAPABILITIES = lib.concatStringsSep "," cudaCapabilities;
337
338 # Needed even when we override stdenv: e.g. for ar
339 GCC_HOST_COMPILER_PREFIX = lib.optionalString cudaSupport "${cudatoolkit_cc_joined}/bin";
340 GCC_HOST_COMPILER_PATH = lib.optionalString cudaSupport "${cudatoolkit_cc_joined}/bin/cc";
341
342 patches = [
343 "${gentoo-patches}/0002-systemlib-Latest-absl-LTS-has-split-cord-libs.patch"
344 "${gentoo-patches}/0005-systemlib-Updates-for-Abseil-20220623-LTS.patch"
345 "${gentoo-patches}/0007-systemlibs-Add-well_known_types_py_pb2-target.patch"
346 # https://github.com/conda-forge/tensorflow-feedstock/pull/329/commits/0a63c5a962451b4da99a9948323d8b3ed462f461
347 (fetchpatch {
348 name = "fix-layout-proto-duplicate-loading.patch";
349 url = "https://raw.githubusercontent.com/conda-forge/tensorflow-feedstock/0a63c5a962451b4da99a9948323d8b3ed462f461/recipe/patches/0001-Omit-linking-to-layout_proto_cc-if-protobuf-linkage-.patch";
350 hash = "sha256-/7buV6DinKnrgfqbe7KKSh9rCebeQdXv2Uj+Xg/083w=";
351 })
352 ./com_google_absl_add_log.patch
353 ./absl_py_argparse_flags.patch
354 ./protobuf_python.patch
355 ./pybind11_protobuf_python_runtime_dep.patch
356 ./pybind11_protobuf_newer_version.patch
357 ] ++ lib.optionals (stdenv.hostPlatform.system == "aarch64-darwin") [
358 ./absl_to_std.patch
359 ];
360
361 postPatch = ''
362 # bazel 3.3 should work just as well as bazel 3.1
363 rm -f .bazelversion
364 patchShebangs .
365 '' + lib.optionalString (stdenv.hostPlatform.system == "x86_64-darwin") ''
366 cat ${./com_google_absl_fix_macos.patch} >> third_party/absl/com_google_absl_fix_mac_and_nvcc_build.patch
367 '' + lib.optionalString (!withTensorboard) ''
368 # Tensorboard pulls in a bunch of dependencies, some of which may
369 # include security vulnerabilities. So we make it optional.
370 # https://github.com/tensorflow/tensorflow/issues/20280#issuecomment-400230560
371 sed -i '/tensorboard ~=/d' tensorflow/tools/pip_package/setup.py
372 '';
373
374 # https://github.com/tensorflow/tensorflow/pull/39470
375 env.NIX_CFLAGS_COMPILE = toString [ "-Wno-stringop-truncation" ];
376
377 preConfigure = let
378 opt_flags = []
379 ++ lib.optionals sse42Support ["-msse4.2"]
380 ++ lib.optionals avx2Support ["-mavx2"]
381 ++ lib.optionals fmaSupport ["-mfma"];
382 in ''
383 patchShebangs configure
384
385 # dummy ldconfig
386 mkdir dummy-ldconfig
387 echo "#!${stdenv.shell}" > dummy-ldconfig/ldconfig
388 chmod +x dummy-ldconfig/ldconfig
389 export PATH="$PWD/dummy-ldconfig:$PATH"
390
391 export PYTHON_LIB_PATH="$NIX_BUILD_TOP/site-packages"
392 export CC_OPT_FLAGS="${lib.concatStringsSep " " opt_flags}"
393 mkdir -p "$PYTHON_LIB_PATH"
394
395 # To avoid mixing Python 2 and Python 3
396 unset PYTHONPATH
397 '';
398
399 configurePhase = ''
400 runHook preConfigure
401 ./configure
402 runHook postConfigure
403 '';
404
405 hardeningDisable = [ "format" ];
406
407 bazelBuildFlags = [
408 "--config=opt" # optimize using the flags set in the configure phase
409 ]
410 ++ lib.optionals stdenv.cc.isClang [
411 "--cxxopt=-x" "--cxxopt=c++"
412 "--host_cxxopt=-x" "--host_cxxopt=c++"
413
414 # workaround for https://github.com/bazelbuild/bazel/issues/15359
415 "--spawn_strategy=sandboxed"
416 ]
417 ++ lib.optionals (mklSupport) [ "--config=mkl" ];
418
419 bazelTargets = [ "//tensorflow/tools/pip_package:build_pip_package //tensorflow/tools/lib_package:libtensorflow" ];
420
421 removeRulesCC = false;
422 # Without this Bazel complaints about sandbox violations.
423 dontAddBazelOpts = true;
424
425 fetchAttrs = {
426 sha256 = {
427 x86_64-linux = if cudaSupport
428 then "sha256-5VFMNHeLrUxW5RTr6EhT3pay9nWJ5JkZTGirDds5QkU="
429 else "sha256-KzgWV69Btr84FdwQ5JI2nQEsqiPg1/+TWdbw5bmxXOE=";
430 aarch64-linux = "sha256-9btXrNHqd720oXTPDhSmFidv5iaZRLjCVX8opmrMjXk=";
431 x86_64-darwin = "sha256-gqb03kB0z2pZQ6m1fyRp1/Nbt8AVVHWpOJSeZNCLc4w=";
432 aarch64-darwin = "sha256-WdgAaFZU+ePwWkVBhLzjlNT7ELfGHOTaMdafcAMD5yo=";
433 }.${stdenv.hostPlatform.system} or (throw "unsupported system ${stdenv.hostPlatform.system}");
434 };
435
436 buildAttrs = {
437 outputs = [ "out" "python" ];
438
439 # need to rebuild schemas since we use a different flatbuffers version
440 preBuild = ''
441 (cd tensorflow/lite/schema;${flatbuffers-core}/bin/flatc --gen-object-api -c schema.fbs)
442 (cd tensorflow/lite/schema;${flatbuffers-core}/bin/flatc --gen-object-api -c conversion_metadata.fbs)
443 (cd tensorflow/lite/acceleration/configuration;${flatbuffers-core}/bin/flatc -o configuration.fbs --proto configuration.proto)
444 sed -i s,tflite.proto,tflite,g tensorflow/lite/acceleration/configuration/configuration.fbs/configuration.fbs
445 (cd tensorflow/lite/acceleration/configuration;${flatbuffers-core}/bin/flatc --gen-compare --gen-object-api -c configuration.fbs/configuration.fbs)
446 cp -r tensorflow/lite/acceleration/configuration/configuration.fbs tensorflow/lite/experimental/acceleration/configuration
447 (cd tensorflow/lite/experimental/acceleration/configuration;${flatbuffers-core}/bin/flatc -c configuration.fbs/configuration.fbs)
448 (cd tensorflow/lite/delegates/gpu/cl;${flatbuffers-core}/bin/flatc -c compiled_program_cache.fbs)
449 (cd tensorflow/lite/delegates/gpu/cl;${flatbuffers-core}/bin/flatc -I $NIX_BUILD_TOP/source -c serialization.fbs)
450 (cd tensorflow/lite/delegates/gpu/common;${flatbuffers-core}/bin/flatc -I $NIX_BUILD_TOP/source -c gpu_model.fbs)
451 (cd tensorflow/lite/delegates/gpu/common/task;${flatbuffers-core}/bin/flatc -c serialization_base.fbs)
452 patchShebangs .
453 '';
454
455 installPhase = ''
456 mkdir -p "$out"
457 tar -xf bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz -C "$out"
458 # Write pkgconfig file.
459 mkdir "$out/lib/pkgconfig"
460 cat > "$out/lib/pkgconfig/tensorflow.pc" << EOF
461 Name: TensorFlow
462 Version: ${version}
463 Description: Library for computation using data flow graphs for scalable machine learning
464 Requires:
465 Libs: -L$out/lib -ltensorflow
466 Cflags: -I$out/include/tensorflow
467 EOF
468
469 # build the source code, then copy it to $python (build_pip_package
470 # actually builds a symlink farm so we must dereference them).
471 bazel-bin/tensorflow/tools/pip_package/build_pip_package --src "$PWD/dist"
472 cp -Lr "$PWD/dist" "$python"
473 '';
474
475 postFixup = lib.optionalString cudaSupport ''
476 find $out -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib; do
477 addOpenGLRunpath "$lib"
478 done
479 '';
480
481 requiredSystemFeatures = [
482 "big-parallel"
483 ];
484 };
485
486 meta = with lib; {
487 changelog = "https://github.com/tensorflow/tensorflow/releases/tag/v${version}";
488 description = "Computation using data flow graphs for scalable machine learning";
489 homepage = "http://tensorflow.org";
490 license = licenses.asl20;
491 maintainers = with maintainers; [ abbradar ];
492 platforms = with platforms; linux ++ darwin;
493 broken = stdenv.isDarwin || !(xlaSupport -> cudaSupport);
494 } // lib.optionalAttrs stdenv.isDarwin {
495 timeout = 86400; # 24 hours
496 maxSilent = 14400; # 4h, double the default of 7200s
497 };
498 };
499
500in buildPythonPackage {
501 inherit version pname;
502 disabled = pythonOlder "3.8";
503
504 src = bazel-build.python;
505
506 # Adjust dependency requirements:
507 # - Drop tensorflow-io dependency until we get it to build
508 # - Relax flatbuffers and gast version requirements
509 # - The purpose of python3Packages.libclang is not clear at the moment and we don't have it packaged yet
510 # - keras and tensorlow-io-gcs-filesystem will be considered as optional for now.
511 postPatch = ''
512 sed -i setup.py \
513 -e '/tensorflow-io-gcs-filesystem/,+1d' \
514 -e "s/'flatbuffers[^']*',/'flatbuffers',/" \
515 -e "s/'gast[^']*',/'gast',/" \
516 -e "/'libclang[^']*',/d" \
517 -e "/'keras[^']*')\?,/d" \
518 -e "/'tensorflow-io-gcs-filesystem[^']*',/d" \
519 -e "s/'protobuf[^']*',/'protobuf',/" \
520 '';
521
522 # Upstream has a pip hack that results in bin/tensorboard being in both tensorflow
523 # and the propagated input tensorboard, which causes environment collisions.
524 # Another possibility would be to have tensorboard only in the buildInputs
525 # https://github.com/tensorflow/tensorflow/blob/v1.7.1/tensorflow/tools/pip_package/setup.py#L79
526 postInstall = ''
527 rm $out/bin/tensorboard
528 '';
529
530 setupPyGlobalFlags = [ "--project_name ${pname}" ];
531
532 # tensorflow/tools/pip_package/setup.py
533 propagatedBuildInputs = [
534 absl-py
535 abseil-cpp
536 astunparse
537 flatbuffers-python
538 gast
539 google-pasta
540 grpcio
541 h5py
542 keras-preprocessing
543 numpy
544 opt-einsum
545 packaging
546 protobuf-python
547 six
548 tensorflow-estimator-bin
549 termcolor
550 typing-extensions
551 wrapt
552 ] ++ lib.optionals withTensorboard [
553 tensorboard
554 ];
555
556 nativeBuildInputs = lib.optionals cudaSupport [ addOpenGLRunpath ];
557
558 postFixup = lib.optionalString cudaSupport ''
559 find $out -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib; do
560 addOpenGLRunpath "$lib"
561
562 patchelf --set-rpath "${cudatoolkit}/lib:${cudatoolkit.lib}/lib:${cudnn}/lib:${nccl}/lib:$(patchelf --print-rpath "$lib")" "$lib"
563 done
564 '';
565
566 # Actual tests are slow and impure.
567 # TODO try to run them anyway
568 # TODO better test (files in tensorflow/tools/ci_build/builds/*test)
569 # TEST_PACKAGES in tensorflow/tools/pip_package/setup.py
570 nativeCheckInputs = [
571 dill
572 portpicker
573 tblib
574 ];
575 checkPhase = ''
576 ${python.interpreter} <<EOF
577 # A simple "Hello world"
578 import tensorflow as tf
579 hello = tf.constant("Hello, world!")
580 tf.print(hello)
581
582 tf.random.set_seed(0)
583 width = 512
584 choice = 48
585 t_in = tf.Variable(tf.random.uniform(shape=[width]))
586 with tf.GradientTape() as tape:
587 t_out = tf.slice(tf.nn.softmax(t_in), [choice], [1])
588 diff = tape.gradient(t_out, t_in)
589 assert(0 < tf.reduce_min(tf.slice(diff, [choice], [1])))
590 assert(0 > tf.reduce_max(tf.slice(diff, [1], [choice - 1])))
591 EOF
592 '';
593 # Regression test for #77626 removed because not more `tensorflow.contrib`.
594
595 passthru = {
596 inherit cudaPackages;
597 deps = bazel-build.deps;
598 libtensorflow = bazel-build.out;
599 };
600
601 inherit (bazel-build) meta;
602}