Repository navigation
Description
Thanks for making this Java API to Tensorflow! Would you kindly help me understand this error from mvn install:
[INFO] Reactor Summary for TensorFlow Java Parent 0.2.0-SNAPSHOT:
[INFO]
[INFO] TensorFlow Java Parent ............................. SUCCESS [ 1.774 s]
[INFO] TensorFlow NdArray Library ......................... SUCCESS [02:47 min]
[INFO] TensorFlow Core Parent ............................. SUCCESS [ 0.187 s]
[INFO] TensorFlow Core Annotation Processor ............... SUCCESS [ 3.157 s]
[INFO] TensorFlow Core API Library ........................ FAILURE [05:15 min]
[INFO] TensorFlow Core API Library Platform ............... SKIPPED
[INFO] TensorFlow Framework Library ....................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 08:09 min
[INFO] Finished at: 2020-08-01T04:56:29Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.bytedeco:javacpp:1.5.3:build (javacpp-build) on project tensorflow-core-api: Execution javacpp-build of goal org.bytedeco:javacpp:1.5.3:build failed: Process exited with an error: 132 -> [Help 1]utionException: Failed to execute goal org.bytedeco:javacpp:1.5.3:build (javacpp-build) on project tensorflow-core-api: Execution javacpp-build of goal org.bytedeco:javacpp:1.5.3:build failed: Process exited with an error: 132r.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution javacpp-build of goal org.bytedeco:javacpp:1.5.3:build failed: Process exited with an error: 132
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.RuntimeException: Process exited with an error: 132
at org.bytedeco.javacpp.tools.Builder.build (Builder.java:1026)
at org.bytedeco.javacpp.tools.BuildMojo.execute (BuildMojo.java:411)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
My 'uname -a' is 'Linux 4.9.0-7-amd64 #1 SMP Debian 4.9.110-3+deb9u2 (2018-08-13) x86_64 GNU/Linux'. I'm running in Docker, w/ Java 11. Happy to use Java 8 instead if that helps.
I run CPU-only. Old CPU. No AVX. CPU flags are (from /proc/cpuinfo):
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes rdrand lahf_lm 3dnowprefetch epb kaiser tpr_shadow vnmi flexpriority ept vpid tsc_adjust smep erms dtherm ida arat
I have a custom .whl file for my Tensorflow build from source, which excludes AVX instructions. However, tensorflow-java's 'mvn install' seems to build its own Tensorflow, and I'm not sure AVX is excluded. Moreover, my /var/log/messages shows an invalid opcode error during 'mvn install', so I suspect AVX issues etc:
Aug 1 00:56:28 kernel: [6829864.802276] traps: java_op_generat[5990] trap invalid opcode ip:7fe3188f1a40 sp:7ffe8f916cb8 error:0
Aug 1 00:56:28 kernel: [6829864.802289] in libtensorflow_framework.so.2.2.0[7fe317356000+1ab9000]
I'd prefer to tell tensorflow-java to use the Tensorflow w/o AVX that I built and installed, rather than use tensorflow-java's mvn-install-built Java Parent Tensorflow. Is this possible? Please let me know if this is a reasonable fix, or what I should do. Not sure how to interpret the error messages. Thanks for your time and insights!
Activity
aday00 commentedon Aug 3, 2020
Looking a bit earlier in the
mvn install -e -Xoutput, we see an illegal instruction [AVX?] and core dump in the line/tmp/docker-share/tensorflow-java/tensorflow-core/tensorflow-core-api/build.sh: line 80: 31711 Illegal instruction (core dumped) $BAZEL_BIN/java_op_generator --output_dir=$GEN_SRCS_DIR --api_dirs=$BAZEL_SRCS/external/org_tensorflow/tensorflow/core/api_def/base_api,src/bazel/api_def $TENSORFLOW_LIBkarllessard commentedon Aug 4, 2020
Hi @aday00 ,
You are right, TF Java will build its own binaries of the TensorFlow runtime. Looking at your trace though, this build seems to be successful. What is failing is when we try to generate the operation wrappers for Java from our custom binary. That code is purely in C++ so it is unrelated with the version of JDK you are using.
Maybe disabling AVX left some operation definitions in a unexpected state, it is hard to say without seeing details of the core dump. Maybe you can rebuild only the generator in debug mode and see at which line it fails and for which op? i.e. invoking bazel for rebuilding
:java_op_generatorwith-c dbgand reexecuting the binary like in the bash script in a debugger to output some trace?saudet commentedon Aug 4, 2020
Have you tried to remove all the AVX flags in the build.sh script and rebuild from scratch?
aday00 commentedon Aug 5, 2020
Thanks for your guidance @karllessard and @saudet! It seems to me we get the core dump from this build.sh line:
Like
build.sh, the core dump is in tensorflow-core-api:Starting
gdbon that core dump, we see the SIGILL and illegal instruction message....A short backtrace from
gdb...And getting the full backtrace from
gdb...aday00 commentedon Aug 5, 2020
To remove AVX from build.sh, kindly advise if I should make this change? My CPU also lacks FMA, so I should probably remove that too? This is not my expertise.
karllessard commentedon Aug 5, 2020
Thanks @aday00 , so it looks like the illegal instruction is happening in the core library, not the generator code itself, which is good news. So it is probably an incompatibility with machine and the compilation options when building the library, the changes you propose in the build script seem accurate.
aday00 commentedon Aug 6, 2020
Thanks @karllessard and @saudet! That builds.
I'm fine closing this, but do you want a patch to compile with the right flags, depending on /proc/cpuinfo? The patched build.sh could compile with AVX512 if available, and not compile with AVX if unavailable. I won't propose an AVX512-related patch unless I can test it, and I may have access to a CPU w/ AVX512 in a few weeks, but not sure yet.
Thanks again for this great project, and all your help!
karllessard commentedon Aug 6, 2020
Wonderful, good luck!
saudet commentedon Aug 6, 2020
I think it makes sense to autodetect AVX, but maybe we can disable it from the plain build and let MKL-DNN/DNNL do the rest? That would make the binaries useful to all those users using these cheap embedded chips. @karllessard
karllessard commentedon Aug 6, 2020
Good idea @saudet , let’s do this, at least we have a build that is safe on all CPUs.
aday00 commentedon Aug 8, 2020
For what it's worth, Tensorflow by default builds w/ AVX (and is therefore broken for my cheap CPU w/o AVX), so Tensorflow-Java is no worse than Tensorflow itself: tensorflow/tensorflow#18689
The AVX build decision is probably more important for Tensorflow, because Google distributes a CPU-only
.whlpackage that is intended to work for most environments. I have a cheap CPU as a test environment, before scaling up.Soon I'll run on multi-CPU-socket & quad-GPU dev systems, and it would be nice if
mvn installdetected if AVX2 or AVX512 were available and did the right thing, since we're going through the trouble of building from source rather than relying on a pre-built.whlpackage. It's good to be fast and use AVX2 or AVX512 if available, because I'll probably make CPU-only kernels in Tensorflow-Java for preprocessing data, before GPU-based Tensorflow handles deep learning.I'm not familiar with Intel MKL/BLAS/LAPACK. I'm not sure if users should be expected to pull in that dependency to use AVX. I don't know how much slower Tensorflow-Java becomes by disabling AVX, but I wouldn't want to slow things down for almost everyone else just because I'm testing on a cheap CPU at the moment. Thanks for letting me share my uninformed perspective!
Auto-detect if CPU supports AVX, and build Tensorflow accordingly.
aday00 commentedon Aug 18, 2020
I made a fork, with a branch to auto-detect AVX for this ticket and @karllessard's session-based model save code (#100) https://github.com/aday00/java/tree/session_saved_model.
Currently this branch just auto-detects AVX aday00@d9a4105.
Will test session-based model save soon, with some minor code cleanup. Thanks again!
aday00 commentedon Aug 22, 2020
Tested on a better build server which supports AVX. AVX was detected in
/proc/cpuinfo, and used duringmvn installas expected , e.g.-mavx:That's good, but should
--copt=-mavx2 --copt=-mfmabe used as well (?), since cpuflags are: