arogozhnikov /einops

Flexible and powerful tensor operations for readable and reliable code (for pytorch, jax, TF and others)

★ 9,637⑂ 409👁 60⑃ 201● 207▤ 17
PythonMITCreated 2018-09-22einops.rocks
Download: v0.8.2: full MLX backend, rely on torch.compile, set python 3.9 as minimumv0.8.2 ↓0.8.22026-01-26
+1
Daily
9,637
stars
409
forks
60
watchers
201
prs
207
issues
17
releases

README

This video in high quality (mp4)
  


--



https://user-images.githubusercontent.com/6318811/177030658-66f0eb5d-e136-44d8-99c9-86ae298ead5b.mp4




 einops 



!Supported python versions


Flexible and powerful tensor operations for readable and reliable code. 
Supports numpy, pytorch, jax, mlx and others.

 Recent updates:

- 0.9.0: overhaul of typing in einops
- einops playground can run 2 of 4 example notebooks right in your browser
- 0.8.2: MLX backend added
- 0.8.0: tinygrad backend added, small fixes
- 0.7.0: no-hassle torch.compile, support of array api standard and more
- 10'000🎉: github reports that more than 10k project use einops
- einops 0.6 introduces packing and unpacking



Previous updates
- einops 0.5: einsum is now a part of einops
- Einops paper is accepted for oral presentation at ICLR 2022 (yes, it worth reading).
  Talk recordings are available
- flax and oneflow backend added
- torch.jit.script is supported for pytorch layers
- powerful EinMix added to einops. Einmix tutorial notebook 



  
  
 --


 Tweets 

 In case you need convincing arguments for setting aside time to learn about einsum and einops...
Tim Rocktäschel

 Writing better code with PyTorch and einops 👌
Andrej Karpathy

 Slowly but surely, einops is seeping in to every nook and cranny of my code. If you find yourself shuffling around bazillion dimensional tensors, this might change your life
Nasim Rahaman

More testimonials


 Contents

- Installation
- Documentation
- Tutorial
- API micro-reference
- Why use einops
- Supported frameworks
- Citing
- Repository and discussions

 Installation  

Plain and simple:
bash
pip install einops


(uv pip install einops works as well)

 Tutorials 

Tutorials are the most convenient way to see einops in action

- part 1: einops fundamentals
- part 2: einops for deep learning
- part 3: packing and unpacking
- part 4: improve pytorch code with einops

Kapil Sachdeva recorded a small intro to einops.

 API 

einops has a minimalistic yet powerful API.

Three core operations provided (einops tutorial
shows those cover stacking, reshape, transposition, squeeze/unsqueeze, repeat, tile, concatenate, view and numerous reductions)

python
from einops import rearrange, reduce, repeat
 rearrange elements according to the pattern
output_tensor = rearrange(input_tensor, 't b c - b c t')
 combine rearrangement and reduction
output_tensor = reduce(input_tensor, 'b c (h h2) (w w2) - b h w c', 'mean', h2=2, w2=2)
 copy along a new axis
output_tensor = repeat(input_tensor, 'h w - h w c', c=3)


Later additions to the family are pack and unpack functions (better than stack/split/concatenate):

python
from einops import pack, unpack
 pack and unpack allow reversibly 'packing' multiple tensors into one.
 Packed tensors may be of different dimensionality:
packed,  ps = pack([class_token_bc, image_tokens_bhwc, text_tokens_btc], 'b  c')
class_emb_bc, image_emb_bhwc, text_emb_btc = unpack(transformer(packed), ps, 'b  c')


Finally, einops prov

Top issues

Discussions

Latest release

v0.8.2: full MLX backend, rely on torch.compile, set python 3.9 as minimum v0.8.2 2026-01-26
- torch.compile: previously we relied on registration of einops in torch.compile. This registration was called by torch. Now with torch = 2.8 torch.compile engine can compile einops operations without additional hints/registrations.
- recommended backend for MLX is still einops.array_api., but since community asked multiple times for support of einops.einsum, there is now MLX backend in einops, so einops. would also work with MLX.
- minor improvements to docs, and mention of several related projects.






 What's Changed
 Update README.md by @arogozhnikov in https://github.com/arogo

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON