Docsity

Tensorflow tensorflow, Exercices de intelligence Artificielle

Toggle sidebar
bg1
T E N S O R F L O W O N M A R C C
Te ns or Fl ow o ff er s an e xc el le nt f ra me wo rk f or e xe cu ti ng m at he ma ti ca l op er at io ns . Eq ui pp ed w it h Te n
ma ny c om pl ic at ed m ac hi ne l ea rn in g mo de ls , as w el l as g en er al m at he ma ti ca l pr ob le ms c ou ld b e pr o
ea si ly a nd l au nc he d to h ie ra rc hi ca l an d ef fi ci en t ar ch it ec tu re s (m ul ti -C PU s an d mu lt i- GP Us ). H ow ev e
Te ns or Fl ow i s pr et ty b ra nd -n ew a nd i t is o pe n- so ur ce d fo r no t to o lo ng . Bu il di ng T en so rF lo w on a " n
st an da rd " pl at fo rm i s pr ov en t o be a d if fi cu lt t as k. T hi s pa ge p ro vi de s al l ne ce ss ar y mo di fi ca ti on o n t
CR OS ST OO L se tt in gs a nd w or ka ro un ds f or b ui ld in g Te ns or Fl ow o n MA RC C. E ve n th ou gh M AR CC h as a
ar ch it ec tu re , ma ny s et ti ng s an d wo rk ar ou nd s ca n sh ed l ig ht s on o th er d if fe re nt e nv ir on me nt s as w e
No e xt ra d ep en de nc ie s (G CC l ib s, l ib st dc ++ , cu da , cu dn n an d et c) a re n ee de d to b e co mp il ed i n th is p
We a re o nl y us in g th e ex is ti ng M AR CC l ib ra ri es . He re i s th e li br ar ie s we u se :
GC C 5. 2. 0
li bs td c+ + (c om e wi th G CC 5 .2 .0 )
CU DA 8 .0
CU DN N 5. 1
py th on /3 .6 .0
Bi nu ti ls 2 .2 5
Ja va 1 .8 .0 _1 12
Tr an sl at e to t he M AR CC s cr ip t:
1 . B U I L D B A Z E L ( L A T E S T - 0 . 5 . 4 )
2 . B U I L D T E N S O R F L O W ( L A T E S T R E L E A S E - 1 . 3 . 0 )
H O M E M E N U
pf3
pf4
pf5
pf8

Aperçu partiel du texte

Télécharge Tensorflow tensorflow et plus Exercices au format PDF de intelligence Artificielle sur Docsity uniquement!

T E N S O R F L O W O N M A R C C

TensorFlow offers an excellent framework for executing mathematical operations. Equipped with Ten

many complicated machine learning models, as well as general mathematical problems could be pro

easily and launched to hierarchical and efficient architectures (multi-CPUs and multi-GPUs). Howeve

TensorFlow is pretty brand-new and it is open-sourced for not too long. Building TensorFlow on a "n

standard" platform is proven to be a difficult task. This page provides all necessary modification on t

CROSSTOOL settings and workarounds for building TensorFlow on MARCC. Even though MARCC has a

architecture, many settings and workarounds can shed lights on other different environments as we

No extra dependencies (GCC libs, libstdc++, cuda, cudnn and etc) are needed to be compiled in this p

We are only using the existing MARCC libraries. Here is the libraries we use:

GCC 5.2.

libstdc++ (come with GCC 5.2.0)

CUDA 8.

CUDNN 5.

python/3.6.

Binutils 2.

Java 1.8.0_

Translate to the MARCC script:

1. B U I L D B A Z E L ( L A T E S T - 0. 5. 4 )

2. B U I L D T E N S O R F L O W ( L A T E S T R E L E A S E - 1. 3. 0 )

H O M E M E N U

module load binutils/2. module load gcc/5.2. module load cuda/8. module load cudnn/5. module load python/3.6. module load java/1.8.0_

This protocol is nothing but passing the correct environment variables to Bazel and TensorFlow. All c

be built successfully by using the correct ENVs.

B U I L D B A Z E L

TensorFlow should be built with Bazel. In other words, Bazel is the only build tool that is provided by

TensorFlow. This is true for all linux/darwin platform. We need to build Bazel prior to building Tenso

Essentially, Bazel is the open-source version of Google's internal build tool. Bazel is a rather new pro

well so that the cross-platform support of Bazel is also not elegant. However, Bazel is a really good b

for its scalability.

D O W N L O A D T H E L A T E S T B A Z E L A N D U N C O M P R E S S I T

Go to the Bazel's Github release page and check out the latest release (version 0.5.4).

wget https://github.com/bazelbuild/bazel/releases/download/0.5.4/bazel-0.5.4-dist.zip mkdir -p bazel-0.5. cd bazel-0.5.4 && unzip ../bazel-0.5.4-dist.zip

Note that please checkout the "dist.zip" version for a release build. After version 0.3.2, Bazel's sourc

release is only for building a developer version. There are a few issues discussed on Bazel's Github I

B E A W A R E O F O U R E N V I R O N M E N T S E T T I N G S

In current Bazel release, the c++ compiler tool chain is hard-coded in the code base. In future Bazel

this should be improved but now we should change the cc_tool_chain rule in Bazel's CROSSTOOL file

provide correct paths (envs).

To build Bazel, you should load the above modules (CUDNN not needed here)

H O M E M E N U

Change cxx_builtin_include_library right under tool_path of gcc to:

cxx_builtin_include_directory: "/cm/shared/apps/gcc/5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/include" cxx_builtin_include_directory: "/cm/shared/apps/gcc/5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/include-f cxx_builtin_include_directory: "/cm/shared/apps/gcc/5.2.0/include/c++/5.2.0"

In the tools/cpp/unix_cc_configure.bzl file, do the following modification:

Replace all occurence of "-B/usr/bin" to "-B/cm/shared/apps/binutils/2.25/src/bin/"

B U I L D B A Z E L

Run the following:

On a interactive job (apply one node for fast build by interact -n 1 -c 28 -p bw-parallel -t 2:0:0 )

entering a new node, don't forget to reload all the modules.

Some suggestions:

1. If you get some compilation errors, you can add "-s --verbose_failures" in the EXTRA_BAZEL_ARGS

will show you the compiler error.

2. Sometimes, bazel has problems with some certain type of JVM(JREs). You will get "server failed wit

code errors". Instead of struggling with this problem, try to use batch mode of bazel instead of its

server/client mode by adding the startup options. --batch --batch_cpu_scheduling

3. JVM usually takes a huge amount of memory. If your machine doesn't have enough memory, you c

job numbers by '--job 24'.

A successful built should have a final output like this

export EXTRA_BAZEL_ARGS='--ignore_unsupported_sandboxing --genrule_strategy=standalone --spawn_strategy=stand ./compile.sh

Target //src:bazel up-to-date: bazel-bin/src/bazel INFO: Elapsed time: 85.311s, Critical Path: 72.74s WARNING: /tmp/bazel_t7vQ9Fsh/out/external/bazel_tools/WORKSPACE:1: Workspace name in /tmp/bazel_t7vQ9Fsh/ou

H O M E M E N U

Bazel is a fully statically linked binary. It has a huge size as binary as well (~100M). It is quite portabl

just need to copy it to your local default PATH, for example, $HOME/opt/bin.

B U I L D T E N S O R F L O W

D O W N L O A D T E N S O R F L O W ( G I T H U B M A S T E R )

Run this command in any directory you prefer.

git clone https://github.com/tensorflow/tensorflow.git

L O A D A L L N E C E S S A R Y M O D U L E S

Note that you need to load this each time you log in a new machine/node.

module load use.own module load binutils/2.

gcc/5.2 is buggy so use gcc/5.4 instead.

generally gcc/5.4 is available in /cm/shared/gcc/

module load gcc/5. module load cuda/8.0 (No need if compile with CPU only) module load cudnn/6.0 (No need if compile with CPU only) module load python/3.6. module load java/1.8.0_

M O D I F Y T H E C R O S S T O O L F I L E.

Again, same problem as building Bazel. We should modify the CROSSTOOL file of TensorFlow to pass

correct ENVs to the compiler tool chain. Since we are building TensorFlow with GPU support, we sho

the CROSSTOOL file in third_party/gpus/crosstool.

Modifications in third_party/gpus/crosstool/CROSSTOOL_nvcc.tpl ,

Again, look for the toolchain block marked as toolchain_identifier: "local_linux"

Build successful! Binary is here: /home-4/[email protected]/scratch/bazel-0.4.4/output/bazel

H O M E M E N U

M O D I F Y T H E T E N S O R F L O W. B Z L F I L E T O S W I G S U C C E S S F U L L Y.

For details, go and read the last comment of adding use_default_shell_env=True , in ctx.action o

rule. https://github.com/tensorflow/tensorflow/issues/706.

C O N F I G U R A T I O N

Then, run ./configure. When running ./configure

Request an interactive job using interact -n 1 -c 28 -p bw-gpu -g 4. Don't forget to load all the m

the new allocated instance.

P R O B L E M W I T H J E M A L L O C ( I F Y O U U S E J E M A L L O C )

We don't use jemalloc because it cannot compile with huge pages support on marcc (with linux kerne

MADV_HUGEPAGE macro is only supported with linux kernel version > 2.6.38. And if you delete that p

MARCC's glibc is too old to support some system functions used by jemalloc.

C O M P I L E T E N S O R F L O W F O R C P U O N L Y ( W I T H S I M D A V X 2 - 2 5 6 E N A B L E D )

Run bazel build -c opt --copt=-mavx2 --ignore_unsupported_sandboxing --genrule_strategy=standalon

spawn_strategy=standalone --linkopt '-lrt -lm' //tensorflow/tools/pip_package:build_pip_package

Do NOT add any flag like --copt="-DGPR_BACKWARDS_COMPATIBILITY_MODE" --conlyopt="-std=c99" , some

will not compile under old c99 standard. And also, if you do exactly as above, you can add the -s -

verbose_failures to get a faster non-verbose compilation. In addition, as stated above, if bazel has

with server/client mode, just simply switch it to batch mode using "bazel --batch --batch_cpu_schedu

c opt..". During the compilation, there are lots of warnings showing up. It doesn't matter since the of

(see Jenkins on Github/TensorFlow) has many warnings printed out in their console log as well.

I built TensorFlow on gpu058. Finally I got

Target //tensorflow/tools/pip_package:build_pip_package up-to-date: bazel-bin/tensorflow/tools/pip_package/build_pip_package INFO: Elapsed time: 366.047s, Critical Path: 263.93s

It only took ~15 mins to build the entire TensorFlow with 28 CPUs.

In addition, if you build TF with GPU support, all the procedures are the same but you just need to a

config=cuda" in the bazel build command. I recommend doing the entire procedure (configuration - f

external dependencies - build) on a gpu instance allocated using interact -n 1 -c 28 -p bw-gpu -g 4

P O S T B U I L D - I N S T A L L T E N S O R F L O W ' S P Y T H O N B I N D I N G T O L O C A L

H O M E M E N U

Simply do the following step:

bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/tensorflow_pkg

pip install --user ~/tensorflow_pkg/*

We add the --user to pip is because we want to install this Python package to local directory, mos

$HOME/.cache/pip. We upgrade pip before we install tensorflow packages since the pip version on M

not the latest. If your local pip has the latest version (9.0.1), you do not need to do this step.

M A J O R R E F E R E N C E

This page has been viewed 1 time(s).

© Y U N L O N G L I U D E S I G N : H T M L 5 U P

H O M E M E N U