Table of Contents
Installation - NEEDS UPDATING
In order to get up and running, we will need an environment for running Python, the Jupyter Notebook, the relevant libraries, and the code needed to run the book itself.
Installing Miniconda
Your simplest option is to install Miniconda. Note that the Python 3.x version is required. You can skip the following steps if your machine already has conda installed.
Visit the Miniconda website and determine the appropriate version for your system based on your Python 3.x version and machine architecture. Suppose that your Python version is 3.9 (our tested version). If you are using macOS, you would download the bash script whose name contains the strings “MacOSX”, navigate to the download location, and execute the installation as follows (taking Intel Macs as an example):
# The file name is subject to changes sh Miniconda3-py39_4.12.0-MacOSX-x86_64.sh -b
A Linux user would download the file whose name contains the strings “Linux” and execute the following at the download location:
# The file name is subject to changes sh Miniconda3-py39_4.12.0-Linux-x86_64.sh -b
A Windows user would download and install Miniconda by following its online instructions. On Windows, you may search for cmd to open the Command Prompt (command-line interpreter) for running commands.
Next, initialize the shell so we can run conda directly.
~/miniconda3/bin/conda init
Then close and reopen your current shell. You should be able to create a new environment as follows:
conda create --name d2l python=3.9 -y
Now we can activate the d2l environment:
conda activate d2l
Installing the Deep Learning Framework and the d2l Package
Before installing any deep learning framework, please first check whether or not you have proper GPUs on your machine (the GPUs that power the display on a standard laptop are not relevant for our purposes). For example, if your computer has NVIDIA GPUs and has installed CUDA, then you are all set. If your machine does not house any GPU, there is no need to worry just yet. Your CPU provides more than enough horsepower to get you through the first few chapters. Just remember that you will want to access GPUs before running larger models.
You can install PyTorch (the specified versions are tested at the time of writing) with either CPU or GPU support as follows:
pip install torch==2.0.0 torchvision==0.15.1
Our next step is to install the d2l package that we developed in order to encapsulate frequently used functions and classes found throughout this book:
pip install d2l==1.0.3
Downloading and Running the Code Locally
Next, you will want to download the notebooks so that you can run each of the book’s code blocks locally. Simply click on the “Notebook” link at the end of each page.
If you do not already have unzip installed, first run sudo apt-get install unzip. Now we can start the Jupyter Notebook server by running:
jupyter notebook
At this point, you can open http://localhost:8888 (it may have already opened automatically) in your web browser. Whenever you open a new command line window, you will need to execute conda activate d2l to activate the runtime environment before running the notebooks, or updating your packages. To exit the environment, run conda deactivate.
pytorch Discussions
