Tensor contractions for AWS Trainium via NKI
Project description
trntensor
Tensor contractions for AWS Trainium via NKI.
Einstein summation with contraction planning, CP and Tucker decompositions. Expresses scientific tensor workloads naturally instead of decomposing to GEMM. Part of the trnsci scientific computing suite (github.com/trnsci).
Install
pip install trntensor
Usage
import torch
import trntensor
# Einsum — drop-in for torch.einsum with contraction planning
C = trntensor.einsum("ij,jk->ik", A, B) # matmul
T = trntensor.einsum("ap,bp->ab", B_i, B_j) # DF-MP2 contraction
X = trntensor.einsum("mi,mnP->inP", C_occ, eri) # AO→MO transform
# Contraction planning
plan = trntensor.plan_contraction("ij,jk->ik", A, B)
flops = trntensor.estimate_flops("ij,jk->ik", A, B)
# CP decomposition (tensor hypercontraction)
factors, weights = trntensor.cp_decompose(tensor, rank=10)
reconstructed = trntensor.cp_reconstruct(factors, weights)
# Tucker decomposition (HOSVD)
core, factors = trntensor.tucker_decompose(tensor, ranks=(5, 5, 5))
Operations
| Category | Operation | Description |
|---|---|---|
| Contraction | einsum |
General tensor contraction |
| Contraction | multi_einsum |
Multiple contractions (fusion-ready) |
| Planning | plan_contraction |
Analyze and select strategy |
| Planning | estimate_flops |
FLOPs for a contraction |
| Decomposition | cp_decompose |
CP/PARAFAC via ALS |
| Decomposition | tucker_decompose |
Tucker via HOSVD |
Status
- Einsum with matmul/bmm/torch dispatch
- Contraction planner
- CP decomposition (ALS)
- Tucker decomposition (HOSVD)
- DF-MP2 einsum example
- NKI fused contraction kernels
- Multi-contraction fusion
- Optimal contraction ordering (like opt_einsum)
Related Projects
| Project | What |
|---|---|
| trnfft | FFT + complex ops |
| trnblas | BLAS operations |
| trnsolver | Linear solvers |
| trnrand | Random number generation |
| trnsparse | Sparse operations |
License
Apache 2.0 — Copyright 2026 Scott Friedman
Project details
Release history Release notifications | RSS feed
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 trntensor-0.1.2.tar.gz.
File metadata
- Download URL: trntensor-0.1.2.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
926c79c9b9aa0a77c8aa88c418c5d83646a282c64c28a9a7880124a19a43fa20
|
|
| MD5 |
85392952774fa8384448b050495ef0e1
|
|
| BLAKE2b-256 |
48b23b66045dd8b36a1efc8ccff7699e3762ce78979ca861dc5c58c7c56a7881
|
Provenance
The following attestation bundles were made for trntensor-0.1.2.tar.gz:
Publisher:
publish.yml on trnsci/trntensor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trntensor-0.1.2.tar.gz -
Subject digest:
926c79c9b9aa0a77c8aa88c418c5d83646a282c64c28a9a7880124a19a43fa20 - Sigstore transparency entry: 1282697623
- Sigstore integration time:
-
Permalink:
trnsci/trntensor@fa54c4e484b7921e2767dfb45b5f4782c656426a -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/trnsci
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fa54c4e484b7921e2767dfb45b5f4782c656426a -
Trigger Event:
release
-
Statement type:
File details
Details for the file trntensor-0.1.2-py3-none-any.whl.
File metadata
- Download URL: trntensor-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a35bf9f8a6a87c3c9a8ba27c8d3b0ea437e933f2e8b531954627f3f14683e744
|
|
| MD5 |
62c02b23d8ff0cff8331bbd5e11890de
|
|
| BLAKE2b-256 |
507c239db211c614462645f65b39dee2fa20d13045e71762df9d3a874d3d7494
|
Provenance
The following attestation bundles were made for trntensor-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on trnsci/trntensor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trntensor-0.1.2-py3-none-any.whl -
Subject digest:
a35bf9f8a6a87c3c9a8ba27c8d3b0ea437e933f2e8b531954627f3f14683e744 - Sigstore transparency entry: 1282697643
- Sigstore integration time:
-
Permalink:
trnsci/trntensor@fa54c4e484b7921e2767dfb45b5f4782c656426a -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/trnsci
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fa54c4e484b7921e2767dfb45b5f4782c656426a -
Trigger Event:
release
-
Statement type: