torch-einshard
torch-einshard expresses local and distributed PyTorch tensor operations with
einsum-like axis and sharding notation.
Installation
python -m pip install torch-einshard
The main entry point is torch_einshard.einshard:
import torch_einshard as es
z = es.einshard("a b, b c -> a c", x, y)
Axis names work like torch.einsum subscripts. Sharded logical axes can also
name a PyTorch DeviceMesh dimension with /:
a/sp b/dp, b/dp c -> a/sp c
This means axis a is sharded over mesh dimension sp, axis b is sharded
over dp, and the contraction over b/dp produces partial local results that
are all-reduced over dp.
Tensor-level partial values use //:
b n h // tp -> b n h
A partial tensor has the full logical shape locally, but each rank holds only one contribution to the value. Converting it back to a non-partial tensor sum-reduces over the named mesh dimension.
Quick Examples
Local contraction:
z = es.einshard("a b k c, b c l d -> k l d a", x, y)
Distributed split:
from torch.distributed.device_mesh import init_device_mesh
mesh = init_device_mesh("cpu", (2, 4), mesh_dim_names=("dp", "sp"))
z = es.einshard("a b -> a/sp b", x, mesh=mesh, shapes={"sp": a_shapes})
Tensor-parallel contraction:
z = es.einshard("b n c, h/tp c -> b n h/tp", x, weight_shard, mesh=mesh)
Named-axis FFT:
z = es.einfft("b x y c -> b kx ky c", x, axes={"x": "kx", "y": "ky"})
Halo exchange and local-window construction:
patches = es.einwindow(
"b h/sp_h w/sp_w c -> b h/sp_h w/sp_w kh kw c",
x,
{"h": "kh", "w": "kw"},
{"h": 1, "w": 1},
mesh=mesh,
shapes={"sp_h": h_shapes, "sp_w": w_shapes},
)
Documentation
The full documentation lives under
docs/:
- Getting started covers installation, quickstart, and test commands.
- Notation covers axis, sharding, partial, factored-axis, family, and ellipsis notation.
- Meshes and shapes
covers
DeviceMesh, compound mesh groups, and uneven split metadata. - User guides cover local, distributed, FFT, halo/window/convolution, roll, parameter, and policy topics.
- Reference documentation covers the API and known limitations.
- Development documentation covers the roadmap, performance, and design notes.
Build the HTML docs with:
uv run sphinx-build -b html docs docs/_build/html
Running Tests
Local and single-process tests:
uv run pytest
Full distributed test suite:
./run_tests.sh
run_tests.sh uses torchrun --nproc-per-node 8.
Current Status
torch-einshard supports local einsum-style operations, selected distributed
split/gather/repartition patterns, tensor-parallel contractions, partial tensor
notation, named-axis FFTs, halo/window/convolution helpers, roll operations,
optimization-policy diagnostics, and parameter metadata helpers.
Known limitations are tracked in the limitations reference. Remaining feature and planning work is tracked in the roadmap.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torch_einshard-1.0.tar.gz.
File metadata
- Download URL: torch_einshard-1.0.tar.gz
- Upload date:
- Size: 51.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0754d85a7bbac0826af0d35510792cfaefcff128dde5c76f59c90e4c5c52cb87
|
|
| MD5 |
422b61855e13aca9e9c089c3440ba3af
|
|
| BLAKE2b-256 |
86136f748ef8417c756dc7624154241c562e7954be97b76767006fbad29e097c
|
File details
Details for the file torch_einshard-1.0-py3-none-any.whl.
File metadata
- Download URL: torch_einshard-1.0-py3-none-any.whl
- Upload date:
- Size: 59.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87392fc94273fa39ace1daa1334a96a2b2e5156266ab62235bcc7116661ff173
|
|
| MD5 |
b3f6850791b86d018365bf7c696279fd
|
|
| BLAKE2b-256 |
e9676f8c69207369c53534d013a3c83f336944f5106602f2e08204a6063d9da5
|