1  PyTorch Introduction and Installation

1.1 What is PyTorch

Pytorch logo.

PyTorch is an open-source machine learning library for Python, based on the Torch library, used for applications such as deep learning and GPU based acceleration. It is primarily developed by Facebook’s artificial intelligence research group. PyTorch provides a high-level interface for working with large-scale machine learning models. It allows developers to define and train neural networks in a fast, flexible, and dynamic way.

Some key features of PyTorch include:

  • Tensor computations with GPU acceleration: PyTorch includes GPU acceleration out of the box, allowing you to train your models on a single or multiple GPUs with ease.
  • Dynamic computation graphs: PyTorch allows you to define your computations as a dynamic graph, which allows you to change the structure of the graph on the fly and enables you to use dynamic control flow.
  • Easy model building: PyTorch provides a wide range of predefined layers and architectures that you can use to build your models, making it easy to get started with machine learning.
  • Ecosystem support: PyTorch has a large and active community of users, and there are many tools and libraries available that are built on top of PyTorch, such as visualization tools, data loaders, and more.

Overall, PyTorch is a powerful and flexible tool for working with large-scale machine learning models and is widely used in research and industry.

On a personal note, I have used many different Deep learning frameworks and I find Pytorch to be the most intuitive. It blends nicely with regular Python and have really good ecosystem. I am also big fan of FastAI library which is written on top of Pytorch and is one of the best framework to do deep learning based project.

1.2 Installation

Since Pytorch is under active development and the new version keeps getting released. You want to visit this website for the latest Pytorch installation instruction.

Fig 1.1: Pytorch Installation page.

The above interface is what you will typically see on the installation page, based on your OS and other selection, it will produce a command you can run on your command line interface and install Pytorch. I recommend installing through conda as it will take care of the dependencies automatically.

1.3 Checking Installation

Let’s run the import command and see if we have Pytorch setup correctly.

import torch

It is recommended to use a machine with a GPU when working with PyTorch because it is typically used for GPU-accelerated computations. If you are running PyTorch on a machine with a GPU and want to verify that it has access to the GPU, you can run the following command-


If PyTorch is installed on a machine with a GPU, the above command will return True otherwise it will return False.