TensorFlow is a open-source software library for machine learning. Orginally developed for Google's own use, it has become a popular training and inference application for deep neural networks. TensorFlow's website where documentation and more examples can be found. Documentation for Python can be found on its official website. Currently, version 1.3 of TensorFlow is available on the clusters.
python
.
Python files end in *.py, and can be run from the command line using
python filename.py
where filename is the name of the Python file.
module load python3/anaconda/2020.02
source activate tensorflow_env
Once the virtual environment is created, it can be launched at any time by ensuring that the python3 module is
loaded, using the command
module load python3/anaconda/2020.02
source activate tensorflow_env
pip install package-name
pip install SQLAlchemy
conda install package-name
conda install NumPy
source deactivate
import tensorflow as tf
# Create hello world tensor
hello = tf.constant("hello world")
# Access tensor with numpy
print(hello.numpy())
# Create a 2D tensor
matrix = [[1,2,3,4,5],
[6,7,8,9,10],
[11,12,13,14,15],
[16,17,18,19,20],
[21,22,23,24,25]]
#Define tensor matrix and type (integer)
tensor = tf.Variable(matrix, dtype=tf.int32)
#print the tensor rank
print(tf.rank(tensor))
#print the tensor shape (row by column)
print(tensor.shape)
3. Prepare the submission script, which is the script that is submitted to the Slurm scheduler as a job in order
to run the Python script. The linked repository provides the script job.sh as an example.
#!/bin/bash
#SBATCH --job-name=tf_test
#SBATCH -o r_out%j.out
#SBATCH -e r_err%j.err
#SBATCH -N 1
#SBATCH --ntasks-per-node=4
#SBATCH -p defq,defq-48core
module purge
module load python3/anaconda/2020.02
source activate tensorflow_env
python example.py
conda deactivate
4. Submit the job using: sbatch job.sh
5. Examine the results.