einops

A readable, framework-independent notation for tensor rearrangement, reduction, and repetition.

Library
PyPI
v0.8.2
9,605 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
61 /100 Good
Development Activity 52
Maintenance 36
Community 56
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
85 /100 Excellent
Architecture 86
Code Quality 85
Innovation 90
Learning Curve 80

einops gives NumPy, PyTorch, TensorFlow, JAX, and other array libraries a single, explicit notation for tensor operations that are normally expressed with error-prone chains of reshape, transpose, squeeze, and framework-specific tile/repeat calls. Its core rearrange, reduce, repeat, pack, and unpack functions take a plain-text pattern describing input and output axes, so the intent of a tensor operation is visible directly in the code instead of buried in index arithmetic.

Because the same pattern-based API works identically across supported backends (NumPy, PyTorch, TensorFlow, JAX, CuPy, PaddlePaddle, and any framework implementing the Python array API standard), einops code is portable between frameworks without behavioral surprises — e.g. flatten() producing different shapes in different libraries. It also ships framework-specific layers (Rearrange, Reduce, EinMix) for dropping the same notation directly into PyTorch, TensorFlow, or Flax model definitions.

What You Get

  • rearrange, reduce, and repeat functions covering stacking, reshaping, transposition, squeeze/unsqueeze, tiling, and reductions with one consistent pattern syntax
  • pack/unpack for reversibly combining tensors of different shapes into one, replacing manual stack/split/concatenate logic
  • An einsum wrapper supporting multi-lettered axis names with the pattern specified last, unlike NumPy’s positional einsum
  • Framework-specific layers (Rearrange, Reduce, EinMix) for PyTorch, TensorFlow, Flax, and PaddlePaddle model definitions
  • Support for any framework implementing the Python array API standard (NumPy 2.0+, MLX, sparse, cubed) via einops.array_api

Common Use Cases

  • Replacing chains of .view()/.transpose()/.reshape() calls in a PyTorch model with a single, self-documenting rearrange pattern
  • Writing tensor-manipulation code once that runs unchanged across NumPy, PyTorch, JAX, and TensorFlow backends
  • Building MLP-Mixer-style architectures with EinMix, a generic linear layer expressed in einops notation
  • Combining and splitting multi-modal tensors (e.g. class tokens, image patches, text tokens) reversibly with pack/unpack

Under The Hood

Architecture - The core lives in einops/einops.py (the rearrange/reduce/repeat implementations), einops/parsing.py (parses the text pattern into an axis-transformation plan), and einops/packing.py (pack/unpack). einops/_backends.py implements a backend-abstraction layer that dispatches the parsed operation to the appropriate framework (NumPy, PyTorch, TensorFlow, JAX, CuPy, etc.), while einops/layers/ wraps the same operations as framework-native nn.Module/keras.Layer-style classes and einops/array_api.py targets the Python array API standard directly.

Tech Stack - Pure Python (69% of the repo, with the rest being Jupyter notebook tutorials) with zero runtime dependencies — einops ships no required dependencies at all, relying purely on whichever array framework the caller already has installed. Built with hatchling; framework-specific code paths (_torch_specific.py) are isolated so the core package doesn’t hard-depend on any single ML library.

Code Quality - Tests live under einops/tests/ (10 files) and are run via GitHub Actions across supported Python versions and backends. The library is narrowly scoped (a handful of core files) but heavily exercised in production — GitHub reports over 10,000 dependent projects — and has been stable enough that its pattern syntax hasn’t changed since early releases.

API Design - The pattern-string API ('b c h w -> b (c h w)') is deliberately declarative: it states what the input and output axes mean rather than how the reshape is computed, which also lets einops validate assumptions (e.g. c=256, h=19, w=19) that a bare .view() call cannot. This is a genuinely low learning curve for anyone who reads the README’s side-by-side comparisons, though newcomers unfamiliar with einsum-style notation need a short ramp-up before the patterns become second nature.

Used by 7 apps in this directory

Python
89%
AGPL 3.0

clarity-upscaler

AI Design Tools · Design Tools

5,138

Free open-source AI image upscaler reaching 13K resolution using Stable Diffusion, ControlNet, and Tiled Diffusion — a self-hostable alternative to Magnific.

View details
36
Repo Health
49
Technical
68
Dependency
Built with
Python 89%
Updated 1 years ago
Python
100%
GPL 3.0

ComfyUI

AI Design Tools · AI Development

135,247

The most powerful node-based AI workflow engine for creating images, video, 3D models, and audio with full control over every generation step.

View details
92
Repo Health
81
Technical
75
Dependency
Built with
Python 100%
Updated 6 days ago
Python
82%
Other

fish-speech

AI Development · Developer Tools · Music Audio

32,864

SOTA open-source dual-autoregressive text-to-speech model with rapid voice cloning, inline emotion tags, and real-time streaming inference across 80+ languages.

View details
69
Repo Health
71
Technical
73
Dependency
Built with
Python 82%
TypeScript 14%
Updated 2 weeks ago
C++
52%
MIT

GPT4All

AI Assistants · AI Development

77,382

Run large language models privately on your laptop — no GPU, no cloud, no data leaving your device.

View details
53
Repo Health
80
Technical
74
Dependency
Built with
C++ 52%
QML 30%
Updated 1 years ago
Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

37,526

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
63
Repo Health
82
Technical
66
Dependency
Built with
Python 51%
TypeScript 36%
Updated 2 months ago
Python
37%
Other

Open WebUI

AI Agents · AI Assistants

153,390

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
91
Repo Health
75
Technical
66
Dependency
Built with
Python 37%
Svelte 34%
JavaScript 21%
Updated 5 days ago
Rust
63%
MIT

PostgresML

AI Development · Databases

6,825

Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.

View details
51
Repo Health
76
Technical
64
Dependency
Built with
Rust 63%
JavaScript 11%
Updated 1 years ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers