This page captures steps to build TensorFlow for windows on arm from source and known issues with the build.
TensorFlow uses Bazel build system so the first step is to compile Bazel for windows on arm.
Build Bazel
Bazel can be either built from scratch or built using Bazel. Building using another Bazel seems to be the easiest option and we have two options for that.
Cross compile from a windows/x64 machine
Build with windows on Arm machine running windows 11 or supporting x64 emulation
The steps given below are similar for above both setups.
Checkout Bazel with windows on arm support
Please check out the following repository for Bazel 4.2.1 source code with win/arm64 support
https://github.com/nsait-linaro/bazel/tree/4.2.1-win_arm64
Download Bazel (x64)
TensorFlow compiles only with Bazel version 4.2.1 or below. To build WoA Bazel 4.2.1 it is recommended to use x64 Bazel 4.2.1.
Download Bazel(x64) 4.2.1: https://github.com/bazelbuild/bazel/releases/download/4.2.1/bazel-4.2.1-windows-x86_64.zip
Add Bazel(x64) to your path and we can use it to build Bazel(arm64).
Install supporting tools for Bazel
You will also need a few other tools for building Bazel. Follow steps given here https://docs.bazel.build/versions/main/install-compile-source.html#bootstrap-windows-bootstrap
You also need to download JDK (win/arm64): https://www.azul.com/downloads/?package=jdk
You should add a few environment variables like the following as mentioned on Bazel build from the source page.
$env:BAZEL_SH="C:\msys64\usr\bin\bash.exe" $env:BAZEL_VC="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC" $env:JAVA_HOME="C:\Users\niysai01\Downloads\zulu17.30.15-ca-jdk17.0.1-win_aarch64\zulu17.30.15-ca-jdk17.0.1-win_aarch64\"
Compile Bazel (Arm64)
And now you are all set to build Bazel. Please use the following command to build
bazel_x64.exe build --subcommands --cpu=x64_arm64_windows //src:bazel.exe
That will generate you an arm64 bazel.exe binary which we can use for the TensorFlow build.
You can add bazel.exe
to your PATH and will use it for the TensorFlow build.
Build TensorFlow
Checkout TensorFlow
See instructions here: https://www.tensorflow.org/install/source
Apply TensorFlow patch to add windows on arm support
Apply the following patch to your TensorFlow repository.
https://github.com/nsait-linaro/tensorflow/commit/91a69d3853e3812506efe48fe96949a4d062683a
Now run python configure.py
and default options should work.
Compile TensorFlow
Please use the following command to build TensorFlow
bazel build --subcommands --config=win_arm64 --compilation_mode=fastbuild //tensorflow/tools/pip_package:build_pip_package
Above will generate an executable build_pip_executable.exe
which can be used to generate a python binary wheel with the following command.
./bazel-bin/tensorflow/tools/pip_package/build_pip_package.exe C:/tmp/tensorflow_package
This will generate the binary python wheel which can be installed with pip install <generated_wheel>.whl
Running TensorFlow Tests
Create a py_test_dir in the TensorFlow directory and add a symlink
mkdir -p py_test_dir cmd /c "mklink /J py_test_dir\tensorflow .\tensorflow"
Create a shell script with following
EXTRA_TEST_FLAGS="" N_JOBS="${NUMBER_OF_PROCESSORS}" PY_TEST_DIR="py_test_dir" TEST_TARGET="//${PY_TEST_DIR}/tensorflow/python/..." bazel test \ --subcommands --config=win_arm64 --compiler=clang-cl --verbose_failures \ --compilation_mode=fastbuild --announce_rc --config=opt -k --test_output=errors \ --experimental_cc_shared_library \ ${EXTRA_TEST_FLAGS} \ --define=no_tensorflow_py_deps=true --test_lang_filters=py \ --test_tag_filters=-no_pip,-no_windows,-no_oss,-gpu,-tpu,-v1only \ --build_tag_filters=-no_pip,-no_windows,-no_oss,-gpu,-tpu --build_tests_only \ --test_size_filters=small,medium \ --jobs="${N_JOBS}" --test_timeout="300,450,1200,3600" \ --flaky_test_attempts=3 \ --output_filter=^$ \ ${TEST_TARGET}
Now tests can be run as
C:\msys64\usr\bin\bash.exe ..\run_test.sh
TensorFlow Test Results
TensorFlow seems to be working fine with examples from https://www.tensorflow.org/tutorials/quickstart/beginner
And running the test suites (using the steps given in the Running TensorFlow tests section
following results are obtained.
Number of tests | |
---|---|
Total | 894 |
Pass | 879 |
Fail | 15 |
Known Issues
There are a few known issues with the TensorFlow build.
Empty
simple_console_for_windows.zip
generated.
Bazel zipper can only handle files < 4 Gb and if the package needs to be generated more than that then an empty zip file is generated as a result of this.
TensorFlow seems to add some redundant zip files and one workaround is to remove them manually and run the zipper manually from bazel-out/x64_arm64_windows-fastbuild/bin/tensorflow/tools/pip_package/simple_console_for_windows.zip-0.params.
Grep for `.zip=`
and remove the entries and run the zipper command again to generate the simple_console_for_windows.zip
external/bazel_tools/tools/zip/zipper/zipper.exe cC bazel-out/x64_arm64_windows-fastbuild/bin/tensorflow/tools/pip_package/simple_console_for_windows.zip @bazel-out/x64_arm64_windows-fastbuild/bin/tensorflow/tools/pip_package/simple_console_for_windows.zip-0.params
Ensure the generated file is not 0 bytes anymore.
2. TensorFlow pip installation might fail due to tensorflow-io-gcs-filesystem package missing.
tensorflow-io-gcs-filesystem is not yet available for win/arm64 and you will have to manually unpack the wheel file and remove the Tensorflow-io entry from
wheel unpack .\tensorflow-2.9.0-cp310-cp310-win_arm64.whl Remove 'Requires-Dist: tensorflow-io-gcs-filesystem (>=0.23.1)' from .\tensorflow-2.9.0\tensorflow-2.9.0.dist-info\METADATA wheel pack .\tensorflow-2.9.0\
2. There are few known issues with clang compiler and we can only build TensorFlow in fastbuild mode. Turning ON all optimization will trigger some errors during compilation. LLVM patches are in progress and should be able to build with LLVM 14 release.
Add Comment