← All open source projects

PyTorch

pytorch/pytorch

PyTorch is an open framework for tensor computation and deep learning in Python, with dynamic neural networks and GPU support.

Forks 27,959
Author pytorch
Language Python
License NOASSERTION
Synced 2026-06-09

What it is

PyTorch is a framework for tensor computation and deep learning. Its core idea is to let developers write models in normal Python style instead of building a static graph first. That made PyTorch especially popular in research, teaching, and fast experiments.

The repository contains the framework core: tensor operations, autograd, neural network modules, CPU and GPU infrastructure, build system, tests, and a lot of low-level code. The user-facing surface can look simple, but it sits on a large performance and compatibility layer.

What is inside and how people use it

PyTorch became a foundation for modern work in computer vision, natural language processing, recommender systems, generative models, and reinforcement learning. Many machine-learning libraries use it because it combines Python ergonomics with accelerator access.

Minimal model

This example shows the basic PyTorch mechanics: layers, input tensor, forward pass, and output shape.

Language: Python
import torch
from torch import nn

model = nn.Sequential(
    nn.Linear(4, 16),
    nn.ReLU(),
    nn.Linear(16, 2),
)

x = torch.randn(8, 4)
y = model(x)
print(y.shape)  # torch.Size([8, 2])

A typical scenario starts with tensors and nn.Module: data flows through a model, a loss is computed, autograd builds gradients, and an optimizer updates parameters. The same pattern is understandable for students and scalable to serious research work.

Strengths and limitations

The strength of PyTorch is flexibility and ecosystem size. It is well suited for experiments where the model, inputs, and training process change directly in code.

The limitation appears at scale. Distributed training, GPU memory, reproducibility, and optimization require separate engineering discipline. The framework does not make a model good by itself; it provides the tools to build one.