Outils pour utilisateurs

Outils du site


linux_compiler_tensorflow_avec_bazel

Ceci est une ancienne révision du document !


Linux Compiler Tensorflow avec Bazel

L'objectif est de compiler Tensorflow avec les options AVX2 et FMA et sans GPU
Voir MoveNet

La version Intel de Tensorflow

intel-tensorflow

python3 -m pip install intel-tensorflow

Donne toujours le message AVX2 et FMA, et ça ne va pas plus vite !

Ressources

Installation de Bazel

Bazel est le compilateur de Google.

# Bazel
sudo apt install apt-transport-https curl gnupg
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
sudo mv bazel.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
sudo apt update
sudo apt install bazel-4.2.1

Sans GPU sur Debian

Désinstaller les packages python tensorflow si ils sont installés.

pip3 list
# Dans la list, chercher ce qu'il faut désinstaller ...
python3 -m pip uninstall tensorflow intel-tensorflow
...

Installation du nécessaire:

python3 -m pip install numpy wheel protobuf
python3 -m pip install keras_preprocessing --no-deps

Récupération des sources de tensorflow:

cd /votre/dossier/src
git clone https://github.com/tensorflow/tensorflow 
./configure

Cela génère un fichier .tf_configure.bazelrc dans le dossier tensorflow (c'est un fichier caché: Ctrl+h).
Répondre entrée ou N partout, nous allons corriger le fichier à la main:

build --action_env PYTHON_BIN_PATH="/usr/bin/python3"
build --action_env PYTHON_LIB_PATH="/usr/lib/python3/dist-packages"
build --python_path="/usr/bin/python3"
build:opt --copt=-march=native
build:opt --host_copt=-march=native
test --flaky_test_attempts=3
test --test_size_filters=small,medium
test:v1 --test_tag_filters=-benchmark-test,-no_oss,-gpu,-oss_serial
test:v1 --build_tag_filters=-benchmark-test,-no_oss,-gpu
test:v2 --test_tag_filters=-benchmark-test,-no_oss,-gpu,-oss_serial,-v1only
test:v2 --build_tag_filters=-benchmark-test,-no_oss,-gpu,-v1only

Compilation de tensorflow

sudo ln -s /usr/bin/python3 /usr/bin/python
bazel build -j 4  --copt=-mavx2 --copt=-mfma  //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /media/data/tensorflow_pkg

Consommation mémoire

Sur un i5 à 8 threads et 8 Go de Ram: -j 2 pour limiter la consommation de mémoire, sinon Swap de 8 Go insuffisante.

Stop et reprise

Bazel reprend là où il s'est arrêté. Pour nettoyer avant de reprendre: bazel clean

Success

INFO: Elapsed time: 19106.040s, Critical Path: 196.86s
5.3 heures
INFO: 11460 processes: 1325 internal, 10135 local.
INFO: Build completed successfully, 11460 total actions

Nettoyage pour recommencer

bazel clean

Installation

cd /media/data/3D/projets/grande_echelle_move
source mon_env/bin/activate
python3 -m pip uninstall tensorflow
python3 -m pip install /media/data/src/tensorflow-2.8.0-cp38-cp38-linux_x86_64.whl

Utilisation

Le message d'info AVX2 et FMA est toujours là ! Le FPS est le même.

linux_compiler_tensorflow_avec_bazel.1639764952.txt.gz · Dernière modification : 2021/12/17 18:15 de serge