Registry / ai-ml / torch
library2.13.0pypypi✓ verified 27d ago

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.

pip install torch
INSTALL
IMPORT
SIG · TORCH
T
torch
ai-mlpythonv2.13.0
Install
79.2s avg
Import
Disk
6758MB
Pass rate
1/ 10
Env Coverage1 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.13.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
1/4 runs
py 3.11
✕ timeout
3/4 runs
py 3.12
✕ timeout
✓ 79.23s
py 3.13
✕ build_error
3/4 runs
py 3.9
✕ build_error
✕ timeout
6758MB installed
● package 6758MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

torch.load
# For trusted checkpoints (your own models): model.load_state_dict(torch.load('model.pt', weights_only=True)) # For checkpoints with non-tensor objects (optimizer states, custom classes): checkpoint = torch.load('checkpoint.pt', weights_only=False) # only for trusted files
model.load_state_dict(torch.load('model.pt')) # raises UnpicklingError in 2.6+ — weights_only now defaults to True
torch.load weights_only parameter flipped from False to True default in 2.6. All existing torch.load() calls without explicit weights_only= raise UnpicklingError if the checkpoint contains non-tensor objects.
device
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model = MyModel().to(device) tensor = tensor.to(device)
model = MyModel().cuda() # crashes on CPU-only machines with no CUDA tensor = tensor.cuda()
Always use .to(device) with a device variable rather than hardcoding .cuda(). .cuda() raises RuntimeError on machines without CUDA.

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))
Debug
Known issues
breakingtorch.load() weights_only default changed from False to True in PyTorch 2.6. All existing torch.load() calls without explicit weights_only= will raise UnpicklingError if the checkpoint contains optimizer states, custom classes, or numpy arrays. Broke thousands of projects.
fix
For state_dict-only checkpoints: torch.load(path, weights_only=True). For full checkpoints with optimizer etc: torch.load(path, weights_only=False) — only on trusted files. To allowlist specific types: torch.serialization.add_safe_globals([MyClass]).
affects: >= 2.6
breakingPlain pip install torch installs CPU-only build. CUDA builds require a custom --index-url. LLM-generated install instructions almost never include this. torch.cuda.is_available() returns False after CPU-only install.
fix
Use the PyTorch install selector: https://pytorch.org/get-started/locally/. For CUDA 12.8: pip install torch --index-url https://download.pytorch.org/whl/cu128
affects: all
breakingtorchvision, torchaudio version must exactly match torch version. Installing latest torch with mismatched torchvision versions causes ImportError or silent incorrect behavior.
fix
Install all PyTorch ecosystem packages together with the same --index-url: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
affects: all
deprecatedTorchScript (torch.jit.script, torch.jit.trace) deprecated in PyTorch 2.10. The PyTorch team recommends migrating to torch.export for model deployment.
fix
Migrate to torch.export.export() for export/deployment. torch.jit still works but will receive no new features and will eventually be removed.
affects: >= 2.10
gotchaForgetting model.eval() during inference causes BatchNorm and Dropout layers to behave as if training — different results each run and incorrect predictions.
fix
Always call model.eval() before inference. Pair with torch.no_grad() to disable gradient computation: with torch.no_grad(): output = model(x)
affects: all
gotchaoptimizer.zero_grad() must be called before loss.backward() each step. Forgetting it accumulates gradients across batches — silent training bug.
fix
Call optimizer.zero_grad() at the start of each training step, before the forward pass. Or use optimizer.zero_grad(set_to_none=True) for slightly better memory performance.
affects: all
gotchaTensors on different devices cannot be combined. CPU tensor + CUDA tensor raises RuntimeError. Common when target labels stay on CPU while model outputs are on CUDA.
fix
Move all tensors to the same device: x, y = x.to(device), y.to(device) at the start of each training step.
affects: all
breakingERROR: No matching distribution found for torch often indicates that PyTorch wheels are not available for your specific Python version, operating system, or architecture (e.g., very new Python versions, Alpine Linux, or unusual hardware).
fix
Verify your Python version, OS, and architecture are officially supported by PyTorch. Consult the PyTorch install selector (https://pytorch.org/get-started/locally/) to find the correct installation command, which might involve using a specific `--index-url`, a different Python environment, or a different base image if using Docker.
affects: all
Upgrade
Version history
2.13.0latest on PyPI · released Jul 8, 2026
Audit
Dependencies
torchvisionoptionalVision models and transforms. Must match torch version: torch 2.10 → torchvision 0.25. Install with same --index-url.
torchaudiooptionalAudio processing. Must match torch version. Install with same --index-url.
tritonoptionalRequired for torch.compile on Linux CUDA. Installed automatically on Linux.
Agent activity
101 hits · last 30 days
node
96
Amazon
1
OpenAI (training)
1
Resources
torch — pip install torch · libregistry