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
下载:v0.8.2: full MLX backend, rely on torch.compile, set python 3.9 as minimumv0.8.2 ↓0.8.22026-01-26
+1
日增长
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
#84Generic einops function which infers which operation to call18 comments · 2020-10-27#22Ellipsis not mentioned in docs14 comments · 2018-12-01#194[Feature suggestion] einops for array indexing12 comments · 2022-06-23#185Missing einops.layers.....Repeat6 comments · 2022-04-26#168[Feature suggestion] Add a simple shape assertion in einops-style notation6 comments · 2022-01-21#88do einops' operations account for contiguous memory layout?5 comments · 2020-11-16#107einops and tensorboard graphs4 comments · 2021-04-07#20Why differently shaped tensors can't be concatenated with rearrange?4 comments · 2018-11-20
Discussions
#404einops.rearrange optimization1 comments · 2026-02-21#380argmin, argmax, argwhere2 comments · 2025-07-15#311Improving the expressivity of einsum with lambda operators2 comments · 2024-03-06#310Optimizing order of operations1 comments · 2024-03-04#307Is it possible to look at `numpy` representation of concrete `einops` function?1 comments · 2024-02-05#301Masking in Einops1 comments · 2024-01-10#291Assign to diagonal2 comments · 2023-11-06#280Something like np.outer1 comments · 2023-09-15
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