Last active
September 17, 2023 06:11
-
-
Save davidecavestro/26ae89e97a278b62234c4bf6dc9c2277 to your computer and use it in GitHub Desktop.
Use TF SIG Build image to compile Tensorflow without AVX (for Celeron on NAS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/tf_sig_build_dockerfiles | |
TF_TAG=v2.13.0 | |
BUILDER_TAG=2.13-python3.8 | |
# clonse sources | |
git clone --depth 1 --branch $TF_TAG https://github.com/tensorflow/tensorflow.git | |
# output folder | |
mkdir packages | |
# cache folder | |
mkdir bazelcache | |
# start the builder container | |
docker run --name tf -w /tf/tensorflow -it -d \ | |
-v "$(pwd)/packages:/tf/pkg" \ | |
-v "$(pwd)/tensorflow:/tf/tensorflow" \ | |
-v "$(pwd)/bazelcache:/tf/cache" \ | |
tensorflow/build:$BUILDER_TAG \ | |
bash | |
# adapt config | |
docker exec tf /bin/bash cp /usertools/cpu.bazelrc /usertools/cpu.bazelrc.mine | |
# alt: simply remove avx-related flags | |
#docker exec tf /bin/bash -c 'sed -i s/build\ --copt=-mavx\ --host_copt=-mavx/build\ --copt=\ --host_copt=/g /usertools/cpu.bazelrc.mine' | |
# alt: supply specific flags to activate available optimizations e turn off missing ones (i.e. avx instruction set) | |
docker exec tf /bin/bash -c 'sed -i s/build\ --copt=-mavx\ --host_copt=-mavx/build\ --copt=-march=core2\ --copt=-mno-avx\ --copt=-mno-avx2\ --copt=-mno-fma\ --copt=-msse4.1\ --copt=-msse4.2\ --copt=-mno-bmi\ --copt=-mno-bmi2\ --host_copt=-march=core2\ --host_copt=-mno-avx\ --host_copt=-mno-avx2\ --host_copt=-mno-fma\ --host_copt=-msse4.1\ --host_copt=-msse4.2\ --host_copt=-mno-bmi\ --host_copt=-mno-bmi2=/g /usertools/cpu.bazelrc.mine' | |
# cleanup Bazel stuff (if changes result in incompatible cached stuff) | |
#docker exec tf bazel clean | |
# build the sources with Bazel | |
docker exec tf bazel --bazelrc=/usertools/cpu.bazelrc \ | |
build --config=sigbuild_local_cache \ | |
tensorflow/tools/pip_package:build_pip_package | |
# construct the pip package | |
docker exec tf \ | |
./bazel-bin/tensorflow/tools/pip_package/build_pip_package \ | |
/tf/pkg \ | |
--cpu | |
# rename the wheels | |
docker exec tf /usertools/rename_and_verify_wheels.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment