Added content explaining what operators are and expanded on tensor description.

jhelsby
2024-08-31 14:32:34 +01:00
parent 015df5bb66
commit 922059ad9b

@ -1,14 +1,15 @@
## Scope
* Understand what a tensor is (including stride, dtype, and layout)
* Understand what an operator is in PyTorch
* Understand what a Tensor is (including stride, dtype, and layout)
* Understand what views are
* Understand how to author an operator in PyTorch
* Understand how to test operators in PyTorch
* Understand what TensorIterator is
## What is a tensor?
## What is a Tensor?
Tensors are a specialized data structure that are very similar to arrays and matrices. In PyTorch, we use tensors to encode the inputs and outputs of a model, as well as the models parameters. Tensors are similar to [NumPys](https://numpy.org/) ndarrays, except that tensors can run on GPUs or other hardware accelerators. In fact, tensors and NumPy arrays can often share the same underlying memory, eliminating the need to copy data. Tensors are also optimized for automatic differentiation. (Source: [PyTorch Basics Tutorial](https://pytorch.org/tutorials/beginner/basics/tensorqs_tutorial.html).)
A Tensor [consists of](https://github.com/pytorch/pytorch/blob/2d6fd22e241763da67e8076a8d3443d988215f32/c10/core/TensorImpl.cpp#L84-L90):
@ -17,6 +18,18 @@ A Tensor [consists of](https://github.com/pytorch/pytorch/blob/2d6fd22e241763da6
* some *strides* metadata
* a storage offset
## What is an operator?
A kernel is a function that accepts Tensors and/or raw pointers to memory and performs a useful computation (for example, matrix multiplication, attention, etc).
An operator is glue code for the PyTorch runtime that tells it about the computation. A single operator can be associated with multiple kernels (for example, torch.add has a kernel for CPU and a kernel for CUDA). The glue code is necessary to get PyTorch subsystems (like torch.compile and torch.autograd) to compose with the computation.
Standalone kernels may work directly with PyTorch but will not compose with the majority of PyTorch subsystems. In order to get them to compose, please register an operator for them.
(Source: [The Custom Operator Manual](https://docs.google.com/document/d/1_W62p8WJOQQUzPsJYa7s701JXt0qf2OfLub2sbkHOaU/edit#heading=h.xubfq3tg8kyy), provided in the official [PyTorch Custom Operators](https://pytorch.org/tutorials/advanced/custom_ops_landing_page.html) documentation.)
## How to author an operator
[Comprehensive guide](https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/README.md)