{"id":396,"date":"2021-06-22T15:59:24","date_gmt":"2021-06-22T15:59:24","guid":{"rendered":"https:\/\/ni.cmu.edu\/computing\/?post_type=ht_kb&#038;p=396"},"modified":"2023-06-08T18:35:29","modified_gmt":"2023-06-08T18:35:29","slug":"installing-tensorflow-using-anaconda3-on-mind","status":"publish","type":"ht_kb","link":"https:\/\/ni.cmu.edu\/computing\/knowledge-base\/installing-tensorflow-using-anaconda3-on-mind\/","title":{"rendered":"Installing TensorFlow using anaconda3 on Mind"},"content":{"rendered":"<p>Anaconda makes it easy to install TensorFlow.  <\/p>\n<h5>\nBelow 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.  <\/h5>\n<p><code>[dpane@mind ~]$ srun -p gpu --cpus-per-task=8  --gres=gpu:1 --mem=20GB --time=4:00:00  --pty $SHELL<br \/>\n[dpane@mind-1-5 ~]$ module avail<br \/>\n[dpane@mind-1-5 ~]$ module load anaconda3-2023.03<br \/>\n[dpane@mind-1-5 ~]$ which python<br \/>\n[dpane@mind-1-5 ~]$ python --version<br \/>\n[dpane@mind-1-5 ~]$ conda create -n dpaneExample -c conda-forge -y<br \/>\n[dpane@mind-1-5 ~]$ source activate dpaneExample<br \/>\n(dpaneExample) [dpane@mind-1-5 ~]$ conda install numpy scipy matplotlib pandas notebook h5py git scikit-image scikit-learn joblib imageio numexpr future<br \/>\n(dpaneExample) [dpane@mind-1-5 ~]$ conda install cudatoolkit psutil pytorch torchvision tensorflow-gpu<br \/>\n(dpaneExample) [dpane@mind-1-5 ~]$ exit<\/code><\/p>\n<h5>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. <\/h5>\n<p><code><br \/>\n[dpane@mind ~]$ srun -p gpu --cpus-per-task=8  --gres=gpu:1 --mem=10GB --time=1:00:00  --pty $SHELL<br \/>\n[dpane@mind-1-5 ~]$ module load anaconda3<br \/>\n[dpane@mind-1-5 ~]$ source activate dpaneExample<br \/>\n(dpaneExample) [dpane@mind-1-5 ~]$ cd dp_tf\/<br \/>\n(dpaneExample) [dpane@mind-1-5 dp_tf]$ cat script3.py<br \/>\n(dpaneExample) [dpane@mind-1-5 dp_tf]$ which python<br \/>\n(dpaneExample) [dpane@mind-1-5 dp_tf]$ python -V<br \/>\n(dpaneExample) [dpane@mind-1-5 dp_tf]$ python<br \/>\n(dpaneExample) [dpane@mind-1-5 dp_tf]$ python script3.py<br \/>\n(dpaneExample) [dpane@mind-1-5 dp_tf]$ python<br \/>\n(dpaneExample) [dpane@mind-1-5 dp_tf]$ exit<br \/>\n[dpane@mind ~]$<br \/>\n<\/code><\/p>\n<h5>Here is the example <em>script3.py<\/em>:<\/h5>\n<p><code><br \/>\n#### Import tensorflow<br \/>\nimport tensorflow as tf<br \/>\n#### version of tensorflow installed<br \/>\nprint(tf.__version__)<br \/>\n#### Initialize two constants<br \/>\nx1 = tf.constant([1,2,3,4])<br \/>\nx2 = tf.constant([5,6,7,8])<br \/>\n#### Multiply<br \/>\nresult = tf.multiply(x1, x2)<br \/>\n#### Print the result<br \/>\nprint(result)<br \/>\n<\/code><\/p>\n<h5>Results (output) of running the scrip in the environment above.  ( <mark>In the below output, I have highlighted in yellow, the results of the print statements in the script.<\/mark>) <\/h5>\n<p><code><br \/>\n(dpaneExample) [dpane@mind-1-1 dp_tf]$ python script3.py<br \/>\n2023-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<br \/>\nTo enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.<br \/>\n<mark>2.11.1<\/mark><br \/>\n2023-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<br \/>\nTo enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.<br \/>\n2023-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<br \/>\n<mark>tf.Tensor([ 5 12 21 32], shape=(4,), dtype=int32)<\/mark><br \/>\n(dpaneExample) [dpane@mind-1-1 dp_tf]$<br \/>\n<\/mark><\/p>\n<h5>If you want to remove your environment, you can use this command while in your environment.<\/h5>\n<p><code>(daveExample) [dpane@mind-1-7 ~]$ conda clean --all<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[11],"ht-kb-tag":[],"class_list":["post-396","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-software"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb\/396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/comments?post=396"}],"version-history":[{"count":33,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb\/396\/revisions"}],"predecessor-version":[{"id":595,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb\/396\/revisions\/595"}],"wp:attachment":[{"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/media?parent=396"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb-category?post=396"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/ni.cmu.edu\/computing\/wp-json\/wp\/v2\/ht-kb-tag?post=396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}