Einops tutorial, part 1: basics - Einops
einops supports widely used tensor packages (such as numpy, pytorch, chainer, gluon, tensorflow), and extends them. transposition is very common and useful, but let's move to other capabilities provided by einops In einops-land you don't need to guess what happened Because you write what the operation does if axis is not present in the output — you guessed it — axis was reduced. You can write 1 to create a new axis of length 1. Similarly you can remove such axis. There is also a synonym () that you can use. That's a composition of zero axes and it also has a unit length. Third operation we introduce is repeat Note: repeat operation covers functionality identical to numpy.repeat, numpy.tile and actually more than that. reduce and repeat are like opposite of each other: first one reduces amount of elements, second one increases. In the following example each image is repeated first, then we reduce over new axis to get back original tensor. Notice that operation patterns are "reverse" of
Einops tutorial, part 1: basics ¶ --> Welcome to einops-land! ¶ We don't write y = x . transpose ( 0 , 2 , 3 , 1 ) We write comprehensible code y = rearrange ( x , 'b c h w -> b h w c' ) einops supports widely used tensor packages (such as numpy , pytorch , jax , tensorflow ), and extends them. What's in this tutorial? ¶ fundamentals: reordering, composition and decomposition of axes operations: rearrange , reduce , repeat how much you can do with a single operation! Preparations ¶ In [1]: Copied! # we need some libraries for this demo % pip install einops numpy pillow - q # we need some libra
Explore this link on the map →related reading
- Einops: Powerful library for tensor operations in deep learning | Oxford Protein Informatics Groupblopig.com
- Chapter 0: Fundamentals - ARENAlearn.arena.education
- Einsum is easy and usefulejenner.com
- Computing sharding with einsum : ezyang's blogblog.ezyang.com
- Tim Rocktäschelrockt.github.io
- Tim Rocktäschelrockt.ai
- PyTorch internals : ezyang's blogblog.ezyang.com
- Chapter 0: Fundamentals - ARENAlearn.arena.education
- Tensors — PyTorch Tutorials 2.12.0+cu130 documentationpytorch.org
- Tensor Considered Harmfulnlp.seas.harvard.edu
- torch.reshape — PyTorch 2.12 documentationdocs.pytorch.org
- Redirecting…docs.pytorch.org