This section provides the information you need to set up the zentf plugin for TensorFlow Java. This setup enables Java applications to exploit zentf in DNN inference using TensorFlow.
Prerequisites
Before building the project, ensure you have installed the following:
- Maven 3.6 or higher
- Java Development Kit (JDK) 11 or higher
- Environment variable
JAVA_HOMEset to your JDK installation path - GLIBC v2.33 or higher
Note that you may need to set JAVA_HOME to the
appropriate path to build this project with Maven. For example, set JAVA_HOME to the path: /usr/lib/jvm/java-<java-version>-openjdk-amd64.
For example:
- For Ubuntu
OS:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 - For RHEL
OS:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk export PATH=$JAVA_HOME/bin:$PATH
Set up zentf Plugin for TensorFlow Java
Currently (as of v1.0.0 of TensorFlow Java), plugins are not supported. Hence, you cannot use TensorFlow Java builds available publicly.
Complete the following steps to enable the zentf plugin for TensorFlow-Java:
- Build TensorFlow-Java from source with changes for plugin.
- Set up zentf plugin.
Build TensorFlow Java from Source with Changes for Plugin
Run the script: build_tf_java.sh to get the
source code of TensorFlow Java, and apply the source code changes to support the plugin.
Build and install TensorFlow Java from source.
We reproduce the following steps from build_tf_java.sh for easy
reference.
git clone https://github.com/tensorflow/java.git tf_java.git
wget https://patch-diff.githubusercontent.com/raw/tensorflow/java/pull/605.patch
cd $current_dir/tf_java
git apply ../605.patch
mvn clean install
cd <Path to zentf plugin parent folder>/ZenDNN_TensorFlow_Plugin/scripts/java
bash build_tf_java.sh
Set up the zentf Plugin
- Download the zentf C++ plugin package v5.1.0 from the AMD Developer Forum.
- Set the environment variable
LD_LIBRARY_PATHto the zentf plugin libraries path.unzip ZENTF_v5.1.0_C++_API.zip export LD_LIBRARY_PATH=<Path to zentf C++ parent folder>/ZENTF_v5.1.0_C++_API/lib-tensorflow-plugins - Source the script to set the ZenDNN specific environment variables as shown
here:
cd <Path to zentf C++ parent folder>/ZENTF_v5.1.0_C++_API source zentf_env_setup.sh java
Example
To try a setup on an example inference application, refer to the README file available at the ./examples/java folder.
Here is an example of how to run the WideDeepLarge model.
- Download the
model.
wget https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_8/wide_deep_fp32_pretrained_model.pb cd <Path to zentf plugin parent folder>/ZenDNN_TensorFlow_Plugin/examples/java mvn clean package - Run the
model.
java -cp target/tensorflow-benchmark-0.1-jar-with-dependencies.jar org.tensorflow.benchmark.RunWideDeeplarge <path to wide deep large .pb model> <batch size> - On successful execution, the output would be as shown
here:
Batch Size = <batch size> Output: 0 End of execution.