PyTorch Cheat Sheet
PyTorch Cheat Sheet
Imports
General
from torch.jit import script, trace # hybrid frontend decorator and tracing jit
See autograd, nn, functional and optim
See Torchscript
ONNX
# IR is well formed
See onnx
Vision
# architectures &
# transforms
See torchvision
Distributed Training
See distributed and multiprocessing
Tensors
https://pytorch.org/tutorials/beginner/ptcheat.html 1/3
Creation
torch.cuda.is_available # check for cuda
else: #
args.device = torch.device('cpu') #
# (gpu, cpu)
See cuda
Deep Learning
# m to n units
# (notation as above)
See nn
Loss Functions
# MarginRankingLoss, HingeEmbeddingLoss,
# MultiLabelMarginLoss, SmoothL1Loss,
# SoftMarginLoss, MultiLabelSoftMarginLoss,
# CosineEmbeddingLoss, MultiMarginLoss,
# or TripletMarginLoss
See loss functions
Activation Functions
See activation functions
Optimizers
https://pytorch.org/tutorials/beginner/ptcheat.html 2/3
See optimizers