TensorFlow Guide V2
What is TensorFlow?
TensorFlow is an open-source software library designed for high-performance numerical computation. Developed by the Google Brain team, TensorFlow excels in handling deep learning and machine learning algorithms, making it particularly useful for tasks involving artificial intelligence, such as neural networks. Its flexible architecture allows for easy computation across a variety of platforms (CPUs, GPUs, and TPUs), making it accessible for users with different levels of computing resources. TensorFlow's ability to execute complex calculations with minimal code makes it an excellent tool for both beginners and advanced researchers in the field of computational science.
How to use TensorFlow on Storrs HPC?
First, we need to create a custom conda environment. If you are not familiar:
Miniconda Environment Set Up - Storrs HPC - UConn Knowledge Base
The following steps sets up an environment for tensor flow with GPU support:
Connect to gpu
(base) [netid@login4 ~]$ srun --x11 -N 1 -n 12 -p general-gpu --gres=gpu:1 --pty bash
Create a Custom Conda Environment
(base) [netid@gpu33 ~]$ conda create -n tf-gpu
(base) [netid@gpu33 ~]$ conda activate tf-gpu
Install Packages
(tf-gpu) [netid@gpu33 ~]$ conda install python=3.12.1
(tf-gpu) [netid@gpu33 ~]$ conda install nvidia::cuda
(tf-gpu) [netid@gpu33 ~]$ conda install conda-forge::python=3.12.1 cudnn tensorflow
To install a specific version of cuda (11.6.0 as an example):
For a full cuda installation:
Check Installation
Use python3 to check if tensorflow is installed and working (you can ignore the warnings).
Check version.
Detect GPU.
Run TensorFlow
A simple TensorFlow operation:
The following script creates two constants and computes their sum using TensorFlow. This operation verifies that TensorFlow can execute computations.
Enter the following into the script:
Save and run the script.
Running TensorFlow on Jupyter
There are two options:
Use VSCode (Jupyter on VSCode - Storrs HPC - UConn Knowledge Base)
Use JupyteHub (Jupyter Guide - Storrs HPC - UConn Knowledge Base)
Please do not hesitate to reach out if you have any questions or if issue arise.
Happy TensorFlowing!
~
Storrs HPC