1. Home
  2. NI Cluster
  3. Software
  4. Installing TensorFlow using anaconda3 on Mind

Installing TensorFlow using anaconda3 on Mind

Anaconda makes it easy to install TensorFlow.

Below are the steps that I used when I built a Anaconda environment with Tensorflow as an example. I also included a short script to test and show that it is working. You may want to modify what you install, depending on your needs.

[dpane@mind ~]$ srun -p gpu --cpus-per-task=8 --gres=gpu:1 --mem=20GB --time=4:00:00 --pty $SHELL
[dpane@mind-1-5 ~]$ module avail
[dpane@mind-1-5 ~]$ module load anaconda3-2023.03
[dpane@mind-1-5 ~]$ which python
[dpane@mind-1-5 ~]$ python --version
[dpane@mind-1-5 ~]$ conda create -n dpaneExample -c conda-forge -y
[dpane@mind-1-5 ~]$ source activate dpaneExample
(dpaneExample) [dpane@mind-1-5 ~]$ conda install numpy scipy matplotlib pandas notebook h5py git scikit-image scikit-learn joblib imageio numexpr future
(dpaneExample) [dpane@mind-1-5 ~]$ conda install cudatoolkit psutil pytorch torchvision tensorflow-gpu
(dpaneExample) [dpane@mind-1-5 ~]$ exit

After the installation above, anytime you want to run your environment (in an interactive session) you can do the following. You may need to modify the resources you request depending on your script. You can also activate your environment in a script when using it in a batch (non-interactive) SLURM job.


[dpane@mind ~]$ srun -p gpu --cpus-per-task=8 --gres=gpu:1 --mem=10GB --time=1:00:00 --pty $SHELL
[dpane@mind-1-5 ~]$ module load anaconda3
[dpane@mind-1-5 ~]$ source activate dpaneExample
(dpaneExample) [dpane@mind-1-5 ~]$ cd dp_tf/
(dpaneExample) [dpane@mind-1-5 dp_tf]$ cat script3.py
(dpaneExample) [dpane@mind-1-5 dp_tf]$ which python
(dpaneExample) [dpane@mind-1-5 dp_tf]$ python -V
(dpaneExample) [dpane@mind-1-5 dp_tf]$ python
(dpaneExample) [dpane@mind-1-5 dp_tf]$ python script3.py
(dpaneExample) [dpane@mind-1-5 dp_tf]$ python
(dpaneExample) [dpane@mind-1-5 dp_tf]$ exit
[dpane@mind ~]$

Here is the example script3.py:


#### Import tensorflow
import tensorflow as tf
#### version of tensorflow installed
print(tf.__version__)
#### Initialize two constants
x1 = tf.constant([1,2,3,4])
x2 = tf.constant([5,6,7,8])
#### Multiply
result = tf.multiply(x1, x2)
#### Print the result
print(result)

Results (output) of running the scrip in the environment above. ( In the below output, I have highlighted in yellow, the results of the print statements in the script.)


(dpaneExample) [dpane@mind-1-1 dp_tf]$ python script3.py
2023-06-08 14:22:18.752372: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2.11.1
2023-06-08 14:22:21.557600: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-06-08 14:22:22.071388: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1613] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 11507 MB memory: -> device: 0, name: NVIDIA GeForce GTX TITAN X, pci bus id: 0000:83:00.0, compute capability: 5.2
tf.Tensor([ 5 12 21 32], shape=(4,), dtype=int32)
(dpaneExample) [dpane@mind-1-1 dp_tf]$

If you want to remove your environment, you can use this command while in your environment.

(daveExample) [dpane@mind-1-7 ~]$ conda clean --all

Updated on June 8, 2023
Was this article helpful?

Related Articles

Need Help?
Can't find the answer you're looking for?
Contact NI Support