- A Conda/Mamba installation. Read this guide on how to set this up.
- A CUDA-compatible GPU. Read here for more information.
- Create a new file with a text editor (Notepad, Atom, Sublime, etc) and copy and paste the following into it.
Create this file if you are using Conda:
CALL conda create --name tf python=3.9
CALL conda activate tf
CALL conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
CALL pip install --upgrade pip
CALL pip install "tensorflow<2.11"
Create this file if you are using Mamba:
CALL mamba create --name tf python=3.9
CALL mamba activate tf
CALL mamba install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
CALL pip install --upgrade pip
CALL pip install "tensorflow<2.11"
- Save this file as tf-script.bat
- Open the Miniforge Prompt and use
cdto navigate to the folder in which the tf-script.bat file has been saved.- Hint: The
dircommand can be used to list the contents of a folder. Enteringdir *.batwill list the files in your folder that have the extension .bat.
- Hint: The
- Run the file by entering its name in the prompt and hitting enter.
- You will see a list of packages that will be installed and asked if you want to confirm the changes. Type 'Y' and then hit Enter.
- After this you will be asked to confirm the installation of
cudatoolkitandcudnn. These are both required for Tensorflow to use the GPU. Like before, typeYand hit Enter.
Now the tf environment should be installed and activated. There will be some brackets on the left of your prompt with tf inside them. This lets us know that the tf environment is activated, and any Python code we use will be run from that environment.
- Type
pythonto start Python in interactive/shell mode. You should have Python 3.9.18 installed as this is the version of Python that is required if we want to use Tensorflow with GPU support enabled.
- Type
import tensorflow as tfto import Tensorflow.
- Test the installation by creating a tensor. We can do this by running the following code:
print(tf.reduce_sum(tf.random.normal([1000, 1000])))
- Test the GPU setup by running the following code:
tf.test.gpu_device_name()
The output lets me know that Tensorflow is able to use my Nvidia GeForce RTX 4070 Laptop GPU.
Now that the environment is installed you may want to rename it. Note: This only works with Conda.
Enter the following command into the Miniforge prompt.
conda rename -n tf new_name







