🐍

Getting Started with PyTorch

Oct 20, 2024

PyTorch Tutorial Series

Overview

  • Introduction to PyTorch
  • Popular machine learning and deep learning framework
  • Focus on practical applications
  • Aim to cover the necessary basics

Installation of PyTorch

  1. Official Website

    • Go to pytorch.org
    • Click on "Get started"
    • Select the newest PyTorch build (currently version 1.3)
  2. Select Operating System

    • Choose your OS (example: Mac)
    • Recommended package manager: Anaconda
    • If Anaconda is not installed, watch the tutorial provided in the description
  3. Select Python Version

    • Use the newest Python version (example: Python 3.7)
    • Note: On Mac, only CPU version is available
  4. GPU Support (Linux/Windows)

    • Install the CUDA toolkit for GPU support
    • Requires an NVIDIA GPU
    • Visit NVIDIA CUDA Downloads
      • Important: Latest supported CUDA version by PyTorch is CUDA 10.1
      • For latest CUDA version, go to legacy releases and download CUDA 10.1
      • Follow instructions for installation

Creating a Virtual Environment

  • Open terminal
  • Create a conda environment with: conda create -n pytorch python=3.7
  • Activate the environment: conda activate pytorch

Installing PyTorch

  • Copy the installation command from the PyTorch site
  • Paste the command in the terminal
  • Wait for the installation to complete

Verification

  1. Start Python in the activated environment: python
  2. Import the torch module: import torch
    • If installation is correct, no error should occur
  3. Create a tensor: x = torch.rand(3) print(x)
  4. Check if CUDA is available: torch.cuda.is_available()
    • Returns false on non-GPU setups; should return true if CUDA toolkit and GPU support are correctly installed

Conclusion

  • PyTorch installation is complete
  • Ready to begin working with PyTorch in upcoming tutorials
  • Encouragement to enjoy the learning process
  • See you in the next tutorial!