Installation from Source Code
This section provides four compilation methods for installing different versions of TensorFlow 2.13.0: basic version, ACL-enabled version, TensorFlow v1.x-matched version, and NUMA-enabled version. Run the compilation commands for each specific version.
- Obtain the TensorFlow 2.13.0 source code.
- Download the TensorFlow source code using your local browser.
https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.13.0.zip
The source package name is tensorflow-2.13.0.zip.
- Upload the source package to the server.
If the server is connected to the Internet, you can run the wget command on the server to download the source package.
1wget -O tensorflow-2.13.0.zip https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.13.0.zip --no-check-certificate
- Download the TensorFlow source code using your local browser.
- Install the dependencies.
1 2 3 4 5 6 7
yum install patchelf perl python3-devel pip3 install numpy==1.24.3 pip3 install packaging pip3 install requests pip3 install wheel export C_INCLUDE_PATH=/usr/include/python3.9:$C_INCLUDE_PATH export CPLUS_INCLUDE_PATH=/usr/include/python3.9:$CPLUS_INCLUDE_PATH
In the preceding commands for configuring environment variables, /usr/include/python3.9 is the directory where Python.h is located. Replace it with the actual directory in the compilation environment.
- Decompress the TensorFlow installation package.
1unzip tensorflow-2.13.0.zipThe directory generated after the decompression is tensorflow-2.13.0.
- Go to the tensorflow-2.13.0 directory.
1cd tensorflow-2.13.0
- Run configure to set the configuration options.
1./configure
The configuration procedure is as follows:
- Confirm the location of the Python executable program.
1Please specify the location of python. [Default is /usr/bin/python3]:
If the Python 3 path is the same as the preceding default path, press Enter. Otherwise, enter the correct Python 3 path.
- Confirm the location of the Python library.
1Please input the desired Python library path to use. Default is [/home/xxx/test]
If the Python library path is the same as the preceding default path, press Enter. Otherwise, enter the correct Python library path.
- Determine whether to enable the ROCm feature.
The AMD ROCm platform is an open source software platform designed to facilitate high-performance computing (HPC) using AMD graphics processing units (GPUs). If TensorFlow runs on AMD GPUs, enter y. Otherwise, enter N.
1Do you wish to build TensorFlow with ROCm support? [y/N]:
In this document, enter N.
1No ROCm support will be enabled for TensorFlow.
- Determine whether to enable the CUDA feature.
CUDA is a parallel computing platform and programming model developed by NVIDIA for general computing on GPUs. It accelerates applications such as scientific computing, graphics processing, and deep learning. If you want to use CUDA in the build, enter y. Otherwise, enter N.
1Do you wish to build TensorFlow with CUDA support? [y/N]:
In this document, enter N.
1No CUDA support will be enabled for TensorFlow.
- Determine whether to use the latest Clang compiler.
If the Clang compiler exists in the compilation environment, enter N. Otherwise, enter y.
1Do you wish to download a fresh release of clang? (Experimental) [y/N]:
In this document, enter N.
1Clang will not be downloaded.
- Configure compilation options.
1Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]:
Press Enter to confirm.
- When building an Android application, determine whether to set a workspace.
To build a non-Android application, enter N. Otherwise, enter y.
1"Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]:"In this document, enter N.
1Not configuring the WORKSPACE for Android builds.
- Confirm the location of the Python executable program.
- Build TensorFlow.
Table 1 Parameters of some extended features (For details, see the .bazelrc file in the source code directory.) config Parameter
Description
--config=mkl_aarch64
Integrates oneDNN and the Arm Compute Library (ACL).
--config=numa
Integrates the NUMA feature.
--config=v1
Replaces TensorFlow 2.x APIs with TensorFlow 1.x APIs.
- When TensorFlow is built from the source code, temporary compilation files are generated in the /root/.cache/bazel directory. Ensure that the remaining space of the root directory is greater than or equal to 8 GB.
- Building TensorFlow from source code requires substantial memory. For memory-constrained systems, add the --local_ram_resources option to the build command. For example, --local_ram_resources=2048 indicates that the maximum memory overhead allowed is 2048 MB.
- Building TensorFlow from source code requires substantial CPU power. You can add the --local_cpu_resources option to the build command to limit the CPU resource usage. For example, --local_cpu_resource=4 indicates that four CPUs are used. (Run the lscpu command on the terminal to check the number of CPUs and set local_cpu_resources based on your requirements.)
The following describes four build methods. Select the one that best suits your requirements.
- Build the basic version.
1bazel build //tensorflow/tools/pip_package:build_pip_package

If the command output displays the preceding information, the build is successful.
- Compile the version in which mkl_aarch64 is enabled.
1bazel build //tensorflow/tools/pip_package:build_pip_package --config=mkl_aarch64

If the command output displays the preceding information, the build is successful.
- Compile the version that matches TensorFlow v1.x.
1bazel build //tensorflow/tools/pip_package:build_pip_package --config=v1

If the command output displays the preceding information, the build is successful.
- Compile the version in which NUMA is enabled.
1bazel build //tensorflow/tools/pip_package:build_pip_package --config=numa

If the command output displays the preceding information, the build is successful.
- During the build process, a message may be displayed indicating that the certificate verification fails. For details about how to resolve this problem, see Failed to Verify the Certificate When Compiling TensorFlow 2.13.0 Source Code.
- Source packages of many dependencies will be downloaded during TensorFlow build. If the network connection is unstable, the build may fail. In that case, ensure that the network connection is normal and try again, or see Failed to Download go_sdk During TensorFlow 2.13.0 Compilation.
- If the hwloc dependency fails to be compiled when building NUMA-enabled TensorFlow 2.13.0 (error information: "external/hwloc/hwloc/topology.c:49:10: fatal error: sys/sysctl.h: No such file or directory"), see Failed to Compile the hwloc Dependency When Compiling TensorFlow 2.13.0.
- Build the TensorFlow pip software package.
1./bazel-bin/tensorflow/tools/pip_package/build_pip_package ./output
The generated pip software package is stored in the ./output directory.
Alarms may be generated during the build. For details about how to handle the alarms, see Alarm Reported When Building the TensorFlow pip Software Package.
- Install the TensorFlow pip software package.
1pip3 install ./output/tensorflow-2.13.0-cp39-cp39-linux_aarch64.whl