Skip to content
AIRepoHub

pytorch

by pytorch

Python framework for building and training neural networks with tensors and GPU acceleration.

Developer ToolsPythonCustom license
Stars
105,711
stars
Forks
31k
forks
Last push
today
Activity
Active
pytorch: quick start
# Run PyTorch in Docker with GPUs$ docker run --gpus all --rm -ti --ipc=host pytorch/pytorch:latest# Check the installation$ python -c "import torch; print(torch.__version__)"

Commands from the project's README. Run them after installing (see below).

Overview

Understand pytorch in 60 seconds

What it does
PyTorch is a Python library for deep learning. It provides tensors like NumPy arrays that run on GPUs, automatic differentiation, and building blocks for neural networks, and it's one of the most widely used frameworks for AI research and production.
The problem it solves
Training neural networks needs fast GPU maths and automatic gradients. PyTorch provides both with a Python-first, imperative style, so models are ordinary Python code you can debug line by line.
Why choose it
Choose it for flexibility and the huge ecosystem of models, tutorials and libraries built on it. For install commands for your exact OS and GPU, use the selector on pytorch.org.
Who should use it
  • Machine learning researchers
  • Engineers training and deploying models
  • Students learning deep learning
  • Developers who need GPU-accelerated tensor maths
Setup difficulty

You'll need:

  • Python (3.11+ when building from source)
  • An NVIDIA, AMD or Intel GPU for acceleration (optional)
  • For source builds: a C++20 compiler, 10 GB free disk and 30 to 60 minutes

How pytorch works

PyTorch is made of several components: torch, a tensor library with strong GPU support; torch.autograd, tape-based automatic differentiation; torch.nn, a neural network library built on autograd; torch.multiprocessing, with shared tensor memory across processes; and torch.utils, including DataLoader.

It is used either as a GPU-powered replacement for NumPy or as a flexible deep learning research platform. Networks are built dynamically, so you can change how a model behaves at runtime, and extensions can be written in Python or C++.

The README sends you to pytorch.org/get-started/locally for the pip and conda install commands for your system. It also documents pre-built Docker images, Jetson wheels and building from source with CUDA, ROCm or Intel GPU support. PyTorch has a BSD-style license.

Features

Key features

GPU tensors

NumPy-like arrays that run on GPUs.

Autograd

Automatic differentiation for any operation.

torch.nn

Neural network layers and losses.

Dynamic graphs

Change model behaviour at runtime.

DataLoader

Utilities for loading data in parallel.

Python and C++ extensions

Write custom ops easily.

Strengths

  • Industry and research standard
  • Huge ecosystem and community
  • Python-first and easy to debug
  • BSD-style license

Limitations

  • Install command depends on your OS and GPU
  • Building from source takes 30 to 60 minutes and 10 GB of disk
  • Docker needs extra shared memory for multi-worker loading

Practical use cases

Train neural networks

Build and train models for vision, language or audio.

Research

Prototype new architectures quickly.

GPU computing

Use tensors as a GPU-accelerated NumPy.

Installation

Install pytorch

Based on official documentation

Commands come from PyTorch's README. AIRepoHub hasn't run them yet. View source

Prerequisites

  • Python
  • Optional GPU drivers

Supported systems

  • Windows
  • macOS
  • Linux
  1. 1

    Get the command for your system

    The README says install commands for pip wheels and conda are on pytorch.org/get-started/locally. Choose your OS, package manager and compute platform there.

Configuration and API keys

SettingWhat it's for

First run

  1. 1

    Check PyTorch imports

    Shell
    python -c "import torch; print(torch.__version__)"

pytorch's documentation doesn't include sample output, so we don't show any. Expect the results in your terminal.

Your first project

Start a GPU-ready PyTorch environment with Docker

Get a working PyTorch setup without installing anything but Docker.

Before you start

  • Docker 23.0 or newer
  • An NVIDIA GPU with drivers (optional)
  1. 1

    Start the container

    Shell
    docker run --gpus all --rm -ti --ipc=host pytorch/pytorch:latest
  2. 2

    Check PyTorch inside it

    Shell
    python -c "import torch; print(torch.__version__)"

What to expect

You get a shell in a container with PyTorch installed, and the check prints the PyTorch version.

Next steps

  • Work through the tutorials at pytorch.org/tutorials
  • Browse the pytorch/examples repository
  • Read the API reference

Costs and requirements

What it costs to run

License
BSD-style.Free
Software
Free and open source.Free
Compute
Training is much faster on GPUs, local or cloud.Depends

Troubleshooting

Common setup issues

Not sure which install command to use

Use the selector at pytorch.org/get-started/locally.

Source: README.md

DataLoader workers crash in Docker

Increase shared memory with --ipc=host or --shm-size.

Source: README.md

Source build fails on Linux

Use gcc 11.3.0 or newer with full C++20 support, and make sure you have 10 GB free.

Source: README.md

Windows build fails

Install Visual Studio or the Visual C++ Build Tools; VS Code doesn't include them.

Source: README.md

Alternatives

Similar AI repositories