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 torchVerified import paths — ran on the pinned version, not inferred.
Standard training loop and inference pattern. Always use model.eval() + torch.no_grad() for inference.
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]).
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
Install all PyTorch ecosystem packages together with the same --index-url: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
Migrate to torch.export.export() for export/deployment. torch.jit still works but will receive no new features and will eventually be removed.
Always call model.eval() before inference. Pair with torch.no_grad() to disable gradient computation: with torch.no_grad(): output = model(x)
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.
Move all tensors to the same device: x, y = x.to(device), y.to(device) at the start of each training step.
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.