If you’re unfamiliar with it, Jupyter Notebook is a powerful IDE that lets you create scripts for data analysis, web scraping, machine learning, and tons of other use cases. For the average coder who’s into data science, Jupyter Notebook serves as the perfect companion as it lets you create interactive documents for everything from jotting down notes to compiling complex codes. While this IDE can be installed on pretty much any modern laptop, you’re going to have a tough time if you try to train AI algorithms on a CPU.
As such, you can configure Jupyter Notebook to relegate the demanding deep-learning workloads to your powerful graphics card instead of the processor. However, you’ll have to go through several steps, including setting up Python libraries, creating coding environments, and installing drivers before you can run Jupyter Notebook on your graphics card.
How to use Jupyter Notebook on Windows, Linux, and macOS
Want to get the most out of learning Python? Get familiar with Jupyter Notebooks
Installing Python
This step may sound redundant if you’re already knee-deep into programming, but you’ll need to install Python on your PC to use GPU-accelerated AI in Jupyter Notebook. Simply download the Python.exe file from the official website and click on the install button after granting admin privileges to the installer.
How to install Python on Windows, Linux, and macOS
If you want to install Python and get started with development, we have a handy quick-start guide to run you through the basics.
For most users, I recommend choosing the Disable Path Length Limit to avoid future headaches caused by the 260-character limit on the length of file paths set by Windows 11.
Installing Miniconda
Miniconda is a toolkit that contains important Python libraries, environments, and packages necessary to enable your GPU. It also lets you create a Jupyter Notebook.
- Download the setup.exe file from the official website and run it with admin privileges.
- Choose the I Agree option when the installer asks you to agree to the licensing terms and hit Next.
- Choose the directory where you wish to install Miniconda, and click on the Next button.
- Hit the Install button and press Finish once the installation is complete.
Setting up a Conda environment
Now that you’ve installed Python and Miniconda, it’s time to configure a coding environment for your machine learning projects. I recommend creating a separate enviroment as we’ll be using older packages in this tutorial.
Since the latest version of TensorFlow doesn’t work on Windows 11 systems that don’t have WSL pre-configured, you’ll have to install a build that’s older than TensorFlow v2.11. The same goes for Python, so you’ll have to downgrade to Python 3.9 in the new Conda environment.
- Type miniconda in the Windows Search Bar and pick the Run as Administrator option under the Anaconda Powershell Prompt.
- Paste the following code into the terminal and press enter:
conda create --name my_env python=3.9 -y
- Activate the newly created environment using the following command:
conda activate my_env
- Run this command to install the cuDNN library and CUDA drivers:
conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0 -y
- Install the TensorFlow library by running the following command:
pip install "tensorflow<2.11"
Installing Jupyter Notebook
Finally, you can set up a local Jupyter Notebook server containing all your project files.
- Run this code inside the Anaconda Powershell Prompt:
pip install jupyter notebook -y
- Open the Jupyter Notebook server by typing:
jupyter notebook
You can check if the Miniconda coding environment works with the GPU. To do so,
- Click on the New button and choose Notebook.
- Select Python 3 (ipykernel) as the kernel.
- Copy these lines of code inside the newly created Notebook:
-
import tensorflow as tf
-
gpus = tf.config.list_physical_devices("GPU")
-
if gpus:
-
for gpu in gpus:
-
print("Found a GPU with the name:", gpu)
-
else:
-
print("Failed to detect a GPU.")
-
- Press the Run button.
If Jupyter Notebook displays a graphics card as the output, it means the process was successful!
Running Jupyter Notebook on a GPU
Once you’ve verified that the graphics card works with Jupyter Notebook, you can use the import tensorflow code snippet to leverage your GPU in all your machine-learning projects. In case Jupyter Notebook is unable to detect your graphics card, you can retry the same procedure in another Conda environment. Be sure to install the same versions of the CUDA drivers and the cuDNN and TensorFlow libraries as I’ve used in this tutorial to avoid running into compatibility issues.
If your projects take eons to compile, your graphics card could be lacking in horsepower. Upgrading to a better GPU is an easy fix that will give your PC the much-needed boost to run complex AI and deep learning algorithms.
Best GPUs for deep learning in 2024
Whether you want to get started with image generation or tackling huge datasets, we’ve got you covered with the GPU you need for deep learning tasks.
Be the first to comment