Hello, I'm Justin with Liquid Web.
PyTorch is a machine learning library used
by developers to make software like
natural language processors. In this
tutorial we are going to take a look at
how to install a PyTorch on an Ubuntu 16.04 server
Before we get started,
there are a couple of things to keep in mind,
first I am working as the root user.
Additionally all of the commands used in
this tutorial can be found in the video description.
Let's get started.
First, we, are going to cover how to install
PyTorch via anaconda. As a best
practice let's get our packages updated by running
apt-get update - y. After that, we need to
pull down the anaconda command line installer script with the following curl command
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
Now that we have the installer script, we need to run it:
bash Miniconda3-latest-Linux-x86_64.sh
During installation, we will need to accept the
user license agreement and accept the
default configuration options presented.
Once the installation is complete we
need to refresh our terminal session by
running source ~/.bashrc
We can now see "(base)" (base) root@ubuntu1604
precedes our normal command prompt
This indicates the Anaconda
environment is active and we can move
forward with installing PyTorch.
In order to do, so run the following command:
conda install pytorch torchvision cpuonly -c pytorch
Be sure to enter Y at the prompt.
That's it!
PyTorch is now installed and ready to use.
To verify the installation, we can
hop into a Python shell by entering the
command 'Python'. Once there, copy and paste
the Python snippet in the video
description into the Python shell and hit enter.
Next, we are going to cover how to
install PyTorch with the Python
package installer pip. First, to exit the
Python shell, hold the ctrl key and press the D key. (Ctrl+D).
Next, deactivate the anaconda
base environment by running the command
'conda deactivate'. Once that's finished,
we need to install python3-venv by
running apt-get install -y python3-venv
Now, we can go ahead and create
a directory to house our new Python
virtual environment and changing to it
by running mkdir pytorch_awesome cd pytorch_awesome
You're welcome to name the directory whatever you prefer.
Now it's time to create a virtual Python environment to work with by running the command
python3 -m venv pytorch-awesome
once that's finished, we can activate the virtual environment by running
source pytorch-awesome/bin/activate
again in this case, you can name the virtual environment whatever you prefer.
Now that the virtual environment is activated,
let's install PyTorch by running the following pip command:
pip install torch==1.3.0+cpu torchvision==0.4.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
Awesome! PyTorch is installed. In order to verify
we can now make use of PyTorch.
We can run the same snippet of Python code we
ran during the anaconda installation.
First, drop into a Python shell by running 'python'.
Now that the Python shell is active
paste in the snippet from the description of this video and hit enter
import torch x = torch.rand(3, 7) print(x)
There you have it. You now know how to
install PyTorch via anaconda and pip
on an ubuntu 16.04 LTS server.
Thanks for watching!
For more information visit our knowledge base at liquid web.com/kb, or our youtube channel at youtube.com/user/liquidwebInc