Python guides
Every published Python guide, newest first, with practical examples you can copy into your own project.
3,965 guides across 14 topics
Topics
Popular Python guides
Most readLatest Python guides
Page 34 of 179Combining Dropout, Batch Normalization, and Learning Rate Schedulers in PyTorch
Learn how to combine dropout, batch normalization, and learning rate schedulers in PyTorch, including layer placement, train/eval modes, scheduler timing, and common pitfalls.
PyTorch Inference: model.eval() vs torch.no_grad() vs torch.inference_mode()
Learn how model.eval(), torch.no_grad(), and torch.inference_mode() affect PyTorch inference, when to combine them, and which context to choose.
How to Save and Load PyTorch state_dict and Checkpoints
Learn how to save and load PyTorch models with state_dict and full checkpoints, including optimizer state, epoch, and safe device handling.
PyTorch Training and Validation Loops in Python
Learn how to structure PyTorch training and validation loops, handle device placement, manage gradients, and avoid common pitfalls.
PyTorch Dataset and DataLoader for Custom Datasets
Implement custom PyTorch datasets with __getitem__ and __len__, then use DataLoader for batching, shuffling, and parallel loading.
PyTorch Loss Functions and Optimizers: Adam vs SGD
python pytorch loss functions optimizers adam and sgd: How to pair loss functions with optimizers in PyTorch, and how Adam and SGD differ in update behavior, memory us...
PyTorch torch.nn Layers and Activation Functions: A Practical Guide
Build PyTorch neural networks with torch.nn layers and activation functions. Covers nn.Linear, nn.Conv2d, nn.Sequential, custom nn.Module models, initialization, and the functional API.
Python PyTorch Autograd: requires_grad and backward
Understand how PyTorch's autograd engine uses requires_grad and backward() to compute gradients, including graph construction, detach(), no_grad(), and common pitfalls.
Managing CUDA Devices and GPU Tensors in PyTorch
Learn how PyTorch manages CUDA devices and GPU tensors: check availability, move tensors with .to(), write device-agnostic code, handle multiple GPUs, and avoid device mismatch errors.
PyTorch Tensor Creation, Indexing, and NumPy Conversion
Learn how to create PyTorch tensors, index and slice them effectively, and convert between tensors and NumPy arrays while avoiding common memory-sharing pitfalls.