Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:services:application_services:high_performance_computing:software:tensorflow [2021/04/22 15:35] (current)
mboden created
Line 1: Line 1:
 +====== TensorFlow ======
 +[[https://​www.tensorflow.org|TensorFlow]] is a open-source machine learning framework mainly developed by Google. It can be used for verious machine learning tasks, e.g. deep learning. TensorFlow provides a high level API in python and other languages and is can run on CPUs as well as GPUs.
  
 +==== Installing TensorFlow ====
 +It is recommended to use Anaconda to create a virtual python environment and install the desired version of tensorflow within that environment.
 +<code bash>
 +module load anaconda3
 +source $ANACONDA3_ROOT/​etc/​profile.d/​conda.sh
 +conda create -n myenv python=3.8.8
 +conda activate myenv
 +conda install tensorflow-gpu==2.2.0
 +</​code>​
 +If you do not want to use GPUs simply replace the last line with <code bash>​conda install tensorflow==2.2.0</​code>​
 +
 +==== Testing the installation ====
 +To run TensorFlow on GPUs, load the correct modules and submit a job to the gpu partition.
 +<file bash jobscript.sh>​
 +#!/bin/bash
 +#SBATCH -p gpu
 +#SBATCH -t 1
 +#SBATCH --gpus-per-node 1
 +
 +module load anaconda3
 +
 +source $ANACONDA3_ROOT/​etc/​profile.d/​conda.sh
 +conda activate myenv
 + 
 +python tftest.py
 +</​file>​
 +
 +<file python tftest.py>​
 +import tensorflow as tf
 +tf.compat.v1.disable_eager_execution()
 +hello = tf.constant('​Hello,​ TensorFlow!'​)
 +sess = tf.compat.v1.Session()
 +print(sess.run(hello))
 +</​file>​
 +And then submit the job using Slurm: <code bash>
 +sbatch jobscript.sh</​code>​
 +
 +The output file should contain
 +<​code>​
 +The output (if any) follows:
 +
 +b'​Hello,​ TensorFlow!'</​code>​
 +and also information about the GPUs selected.
 +
 +=== Testing CPU only installation ===
 +If you want to test a CPU only installation,​ you can just run the tftest.py on a login node.
 +
 +==== Using TensorFlow ====
 +You can now use TensorFlow in your python scripts. Please read [[en:​services:​application_services:​high_performance_computing:​running_jobs_slurm#​gpu_selection]] for more information about GPU usage.