TensorFlow Build issue with Bazel (Error: cycle in dependency graph)
Hi,
I am opening this as a new issue as suggested by damienmg - the same issue has also been reported as a comment in https://github.com/bazelbuild/bazel/issues/587 and also discussed in https://github.com/bazelbuild/bazel/issues/596
I am building TensorFlow from source. I am using commit 916370e (as suggested in https://github.com/bazelbuild/bazel/issues/596) for Bazel build - Bazel build goes fine.
For building TensorFlow, I had to update the WORKSPACE file (attached) to work-around for known proxy issue (as described in https://github.com/bazelbuild/bazel/issues/587 ) to use "local_repository".
I am using Ubuntu 14.04; From my root (~/tensorflow) I use the following commands to build TensorFlow:
bazel clean --expunge
bazel build -c opt //tensorflow/cc:tutorials_example_trainer
The error that I get from "bazel build ..." command is as follows:
$ bazel build -c opt //tensorflow/cc:tutorials_example_trainer
......
ERROR: /home/ssaharo/.cache/bazel/_bazel_ssaharo/64bf5fcc928610d1fc32c86de697b420/external/png_archive/BUILD:23:1: in genrule rule @png_archive//:configure: cycle in dependency graph:
//tensorflow/cc:tutorials_example_trainer
//tensorflow/core:tensorflow
//tensorflow/core:tensorflow_opensource
//tensorflow/core:core
//tensorflow/core:core_cpu
//tensorflow/core:framework
//tensorflow/core:lib
//tensorflow/core/platform/default/build_config:platformlib
@png_archive//:png
* @png_archive//:configure [self-edge].
ERROR: Loading of target '//tensorflow/cc:tutorials_example_trainer' failed; build aborted.
ERROR: Loading failed; build aborted.
INFO: Elapsed time: 5.852s
============================================
Attached are the WORKSPACE file that I am using, and also png.BUILD and jpeg.BUILD files that I think are somehow related to this issue - both png.BUILD & jpeg.BUILD are original files that come with download of TensorFlow source.
Any help/suggestion would be very much appreciated
I filed a bug for the underlying cause of that failure: #626. As a workaround, png builds for me if I change the exclude line in png.BUILD to exclude = [prefix_dir + "/config.h", "configure"], (probably have to do something similar for the other ones too).
After changing the .BUILD files, make sure to do a bazel shutdown because of #566.
Also, I would put the downloaded folders outside of the Bazel workspace (from your paths, it looks like you have them at the top level of the workspace right now). That worked for me in a simple test, but if you try to build //... or something it will likely not, and it might confuse Bazel about when it needs to rebuild things.
As said by Ulf the underlying behavior is working as intended. Each file has a corresponding label and you should not name the genrule configure or not include configure in any glob. Is it from TensorFlow source code?
Hi,
yes, all .BUILD files came from TensorFlow Source download
I followed suggestions from bsilver8192:
- Modified the 'exclude' in png.BUILD and jpeg.BUILD as suggested
- Moved the libpng-1.2.53 and jpeg-9a to the directory above 'tensorflow' and marked the path in my WORKSPACE as needed
- did 'bazel shutdown' and started the buid again
Now the build fails while compiling jpeg because it can't find a file in jpeg-9a/jfdctfst.c which does exist. The error message is as follows: $ bazel build -c opt //tensorflow/cc:tutorials_example_trainer ...... INFO: Found 1 target... ERROR: missing input file '@jpeg_archive//:jpeg-9a/jfdctfst.c'. ERROR: /home/ssaharo/tensorflow/third_party/gpus/cuda/BUILD:143:1: Executing genrule //third_party/gpus/cuda:cuda_config_check failed: bash failed: error executing command /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; touch bazel-out/local_linux-opt/genfiles/third_party/gpus/cuda/cuda.config': com.google.devtools.build.lib.shell.AbnormalTerminationException: java.io.IOException: Stream closed. ERROR: /home/ssaharo/.cache/bazel/_bazel_ssaharo/64bf5fcc928610d1fc32c86de697b420/external/jpeg_archive/BUILD:77:1: @jpeg_archive//:jpeg: missing input file '@jpeg_archive//:jpeg-9a/jfdctfst.c'. Target //tensorflow/cc:tutorials_example_trainer failed to build Use --verbose_failures to see the command lines of failed build steps. ERROR: /home/ssaharo/.cache/bazel/_bazel_ssaharo/64bf5fcc928610d1fc32c86de697b420/external/jpeg_archive/BUILD:77:1 1 input file(s) do not exist. INFO: Elapsed time: 8.098s, Critical Path: 0.11s
I am building CPU version (earlier did not specify GPU while running 'configure' for tensorflow), so I am not sure why the build is executing CUDA build, may be common file!
I am re-attaching the modified WORKSPACE and BUILD files jpeg.BUILD.txt png.BUILD.txt WORKSPACE.txt
by the way, the missing file name changes if I run again after 'bazel shutdown'. As shown below, now its a different file jpeg-9a/jutils.c
$ bazel build -c opt //tensorflow/cc:tutorials_example_trainer ...... INFO: Found 1 target... ERROR: missing input file '@jpeg_archive//:jpeg-9a/jutils.c'. ERROR: /home/ssaharo/.cache/bazel/_bazel_ssaharo/64bf5fcc928610d1fc32c86de697b420/external/jpeg_archive/BUILD:77:1: @jpeg_archive//:jpeg: missing input file '@jpeg_archive//:jpeg-9a/jutils.c'. Target //tensorflow/cc:tutorials_example_trainer failed to build Use --verbose_failures to see the command lines of failed build steps. ERROR: /home/ssaharo/.cache/bazel/_bazel_ssaharo/64bf5fcc928610d1fc32c86de697b420/external/jpeg_archive/BUILD:77:1 1 input file(s) do not exist. INFO: Elapsed time: 7.944s, Critical Path: 0.10s
If you have '/home/ssaharo/jpeg-9a' as the path, then jutils.c should be at /home/ssaharo/jpeg-9a/jpeg-9a/jutils.c (the new_http_archive calls don't use strip_prefix, so the .BUILD files expect that second folder).
Bazel loads the external repositories in parallel, so which one it finds first is not deterministic.
yes, that was it! After moving both libpng-1.2.53 and jpeg-9a directories under /home/ssaharo/libpng-1.2.53 and /home/ssaharo/jpeg-9a,, the build went fine!
Thanks a lot, for your help! This is really great to finally overcome the build issue...
Summary:
- download jpeg.BUILD.txt, png.BUILD.txt, and WORKSPACE.txt from @srsaharoy 's message https://github.com/bazelbuild/bazel/issues/623#issuecomment-158151936 . (the 2nd post with attachments) and place these files in the tensorflow lib without the .txt extension instead of the existing files (in my case ~/git/tensorflow/tensorflow).
- create folder with external source files: ~/git/tensorflow/fix/files/re2 ~/git/tensorflow/fix/files/jpeg-9a/jpeg-9a ~/git/tensorflow/fix/files/gemmlowp ~/git/tensorflow/fix/files/libpng-1.2.53/libpng-1.2.53 ~/git/tensorflow/fix/files/six-1.10.0 Note the dir-in-dir for jpeg-9a and libpng-1.2.53. This is necessary.
- change paths in WORKSPACE file to match the location of the aux source files
- bazel shutdown
- bazel build -c opt //tensorflow/cc:tutorials_example_trainer
EDIT: the path for 'six' in WORKSPACE needs to point to the folder that contains six-1.10.0, e.g.: path = "/home/.../git/tensorflow/fix/files" This is because six.BUILD searches the sources in "six-1.10.0/six.py".
EDIT: (for commit a108da2 16-DEC-2015) download & extract https://bitbucket.org/eigen/eigen/get/3.3-beta1.tar.gz ; change eigen_archive to new_local_repository with path = "/home/.../git/tensorflow/fix/files"
This may be also true for other modules.
Thanks :)
INFO: Found 1 target...
INFO: From Executing genrule @jpeg_archive//:configure [for host]:
unshare failed with EINVAL even after 101 tries, giving up.
ERROR: /root/.cache/bazel/_bazel_root/73f6290c46c3f436a04f635e253824f5/external/jpeg_archive/BUILD:67:1: Executing genrule @jpeg_archive//:configure failed: bash failed: error executing command
(cd /root/.cache/bazel/_bazel_root/73f6290c46c3f436a04f635e253824f5/tensorflow &&
exec env -
PATH=/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:/root/bin
/bin/bash -c 'source tools/genrule/genrule-setup.sh; pushd external/jpeg_archive/jpeg-9a; workdir=$(mktemp -d -t tmp.XXXXXXXXXX); cp -a * $workdir; pushd $workdir; ./configure; popd; popd; cp $workdir/jconfig.h bazel-out/host/genfiles/external/jpeg_archive/jpeg-9a; rm -rf $workdir;'): bash failed: error executing command
(cd /root/.cache/bazel/_bazel_root/73f6290c46c3f436a04f635e253824f5/tensorflow &&
exec env -
PATH=/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:/root/bin
/bin/bash -c 'source tools/genrule/genrule-setup.sh; pushd external/jpeg_archive/jpeg-9a; workdir=$(mktemp -d -t tmp.XXXXXXXXXX); cp -a * $workdir; pushd $workdir; ./configure; popd; popd; cp $workdir/jconfig.h bazel-out/host/genfiles/external/jpeg_archive/jpeg-9a; rm -rf $workdir;').
Target //tensorflow/cc:tutorials_example_trainer failed to build
INFO: Elapsed time: 23.353s, Critical Path: 22.21s
EINVAL after 101 tries -> set --genrule_strategy=standalone --spawn_strategy=standalone
I've added a small correction for the path to 'six' module in my comment https://github.com/bazelbuild/bazel/issues/623#issuecomment-158984782.
Added another correction for eigen_archive (tensorflow commit a108da2)
@uriv Can you elaborate on the eigen changes needed? You mention replacing eigen_archive with a new_local_repository entry. I assume this is in
I went ahead and added the new_local_repository entry into WORKSPACE:
...
new_local_repository(
name = "eigen_archive",
path = "/Users/me/Dev/tensorflow",
build_file = "eigen.BUILD"
)
...
With that, it starts building but now get a different error:
ERROR: /Users/me/Dev/tensorflow/tensorflow/tensorflow/core/BUILD:796:1: undeclared inclusion(s) in rule '//tensorflow/core:android_tensorflow_lib': this rule is missing dependency declarations for the following files included by 'tensorflow/core/framework/bfloat16.cc': '/Users/me/Dev/tensorflow/eigen-eigen-ce5a455b34c0/Eigen/src/plugins/BlockMethods.h' '/Users/me/Dev/tensorflow/eigen-eigen-ce5a455b34c0/Eigen/src/plugins/CommonCwiseUnaryOps.h' '/Users/me/Dev/tensorflow/eigen-eigen-ce5a455b34c0/Eigen/src/plugins/CommonCwiseBinaryOps.h' '/Users/me/Dev/tensorflow/eigen-eigen-ce5a455b34c0/Eigen/src/plugins/MatrixCwiseUnaryOps.h' '/Users/me/Dev/tensorflow/eigen-eigen-ce5a455b34c0/Eigen/src/plugins/MatrixCwiseBinaryOps.h' '/Users/me/Dev/tensorflow/eigen-eigen-ce5a455b34c0/Eigen/src/plugins/ArrayCwiseUnaryOps.h' '/Users/me/Dev/tensorflow/eigen-eigen-ce5a455b34c0/Eigen/src/plugins/ArrayCwiseBinaryOps.h'. Target //tensorflow/examples/android:tensorflow_demo failed to build Use --verbose_failures to see the command lines of failed build steps.
Maybe this problem is specific to the android example build.
My WORKSPACE had an "eigen_archive". Here's the fix I made:
#new_http_archive(
# name = "eigen_archive",
# url = "https://bitbucket.org/eigen/eigen/get/3.3-beta1.tar.gz",
# sha256 = "2d6533e86ed6b54d30ae1d6c10808533b335d1c570c5e4c58ce2f03da99c134b",
# build_file = "eigen.BUILD",
#)
new_local_repository(
name = "eigen_archive",
path = "/home/.../git/tensorflow/fix/files",
build_file = "eigen.BUILD",
)
My problem is fixed after pulling the latest source for Tensorflow and Bazel. I think they removed some redundant eigen library files in latest Tensorflow source and that seems to have fixed my issue.
Hi, I unfortunately do not have access top internet with my linux computer and I got the same error with missing packages libpng, jpegsrc, re2 and gemmlowp as in #587. I followed @uriv advice and copied and pasted his workpsace png and jpeg build files. However could someone explain to me very precisely how to do the second step of @uriv summary that is to say creating a local repo with the sources without internet on the computer and changing the path in the corresponding files ? I donwloaded the packages but I do not know where to install them and how to make this work and do not even know if I need the exact version of the packages mentionned. I am a beginner in Linux and have been trying to install this for a few days and I feel like if I do this it should finally work !
Bonjour jeandut, You should download the source in a directory then replace your WORKSPACE file as @uriv commented (with new_local_repository), replacing the path string with the actual path to your source.
Thank you @damienmg for this quick answer this is what I did and I get:
no such package '@re2//': Could not create a symlink to repository mypath/re2
And the same message for the different other packages it may come from my definition of what a source is. For instance for I just downloaded the zip file for re2 from github the master I unzipped it and renamed the file re2 instead of re2-master is it not the file to which the path must lead ?
Do I need to install it first ? (there is no configure file in re2 files that I got so I am at a loss).
Sorry it is probably a trivial question.
Can you post a hierarchy of what you did? It should be something like that:
/path/tensorflow
/path/re2
/path/eigen
then tensorflow/WORKSPACE should look like:
new_local_repository(
name = "eigen_archive",
path = "/path/eigen",
build_file = "eigen.BUILD",
)
local_repository(
name = "re2",
path = "/path/re2",
)
...
I created a folder named fix and inside a folder named files in which I put the unzipped file re2-master. Fix is at the same level as tensorflow and .BUILD files.
So I have
/path/tensorflow
/path/fix/files/re2
etc.
and in the WORKSPACE file I have the same as you do.
Do I need to move them up not to be in subfolders ?
Is it the file re2-master the right one ?