PyTorch - Packages in torch & torchvision

Packages in torch


PyTorch Documentation: https://pytorch.org/docs/stable/index.html

To learn how to use PyTorch, we can start from knowing what does it contain.
Here we list out modules in torch package and torchvision package.


torch package contain data structure and mathematical operations for multi-dimensional tensors. Some useful utilities are also included (random & sampling, serialization, get/set basic config in parallelism, disable/enable gradient computation).

Tensor

Multi-dimensional matrix containing elements of a single data type.
(It contains not only data structure for tensor but also many tensor attributes and type information)

sparse (experimental API)

Spare tensor in Coordinate Format (COO).
https://scipy-lectures.org/advanced/scipy_sparse/coo_matrix.html

cuda

Support for CUDA tensor types

Storage

Contiguous 1D array of single data type.

nn

Neural network modules (parameters, containers, layers, utilities).

nn.functional

Common used functions in neural network.

nn.init

Common functions to initialize tensor.

optim

Common optimization algorithms.

autograd

Classes and functinos implementing automatic differentiation of arbitrary scalar valued functions.

distributed

Distributed communication backend.

distributions

Parameterizable probability distributions and sampling functions.

hub

Pre-trained model repository.

jit

PyTorch JIT compiler support. (create serializable and optimizable models from PyTorch code by TorchScript)

multiprocessing

A wrapper around the native Python multiprocessing module. (manage multiple process and shared memory)

random

Config random number generator.

utils.bottleneck

Tool to summarize runs of your script with Python profiler and PyTorch's autograd profiler.

utils.checkpoint

Modules to trade compute for memory (to save memory).
https://blog.csdn.net/ONE_SIX_MIX/article/details/93937091

utils.cpp_extension

Build and distribute Python (PyTorch) package to C++ or CUDA extension.
https://pytorch.org/tutorials/advanced/cpp_extension.html

utils.data

Data loading utility.

utils.dlpack

Convert between dlpack (standard to store tensor) and tensor.

utils.model_zoo

Moved to torch.hub.

utils.tensorboard

Visualize PyTorch models and metrics within TensorBoard UI.

utils.onnx

Export PyTorch model to ONNX.
For import, https://github.com/pytorch/pytorch/issues/21683

 

 

Packages in torchvision


datasets

Load common dataset. 

io

Read and write video. (for image and other data, use torch.utils.data)

models

Definition of common models for different tasks. (VGG, ResNet, ...)

ops

Operators are specific for Computer Vision.

transforms

Common image transformations.

utils

make_grid() and save_image().

 

There are also torchaudio and torchtext.