PyTorch

2.10.0 · active · verified Wed Mar 25

Deep learning framework with GPU-accelerated tensor operations. Current version is 2.10.0 (Jan 2026). Install command varies by CUDA version — plain pip install torch gives CPU-only build. torch.load weights_only default changed to True in 2.6, breaking thousands of existing checkpoints. TorchScript deprecated in 2.10.

Warnings

Install

Imports

Quickstart

Standard training loop and inference pattern. Always use model.eval() + torch.no_grad() for inference.

import torch
import torch.nn as nn

# Device setup
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

# Simple model
model = nn.Sequential(
    nn.Linear(10, 64),
    nn.ReLU(),
    nn.Linear(64, 1)
).to(device)

# Training step
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
loss_fn = nn.MSELoss()

model.train()
for x, y in dataloader:
    x, y = x.to(device), y.to(device)
    optimizer.zero_grad()
    loss = loss_fn(model(x), y)
    loss.backward()
    optimizer.step()

# Inference
model.eval()
with torch.no_grad():
    predictions = model(test_x.to(device))

# Save / load
torch.save(model.state_dict(), 'model.pt')
model.load_state_dict(torch.load('model.pt', weights_only=True))

view raw JSON →