Skip to main content

trntensor

CI codecov Ruff PyPI Python License Docs

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).

Current phase

trntensor follows the trnsci 5-phase roadmap. Active work is tracked in phase-labeled GitHub issues:

Suite-wide tracker: trnsci/trnsci#1.

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 (mp2_energy, ao_to_mo_transform)
  • XLA operand residency (to_xla / from_xla)
  • NKI CPU simulator + nki-simulator CI gate
  • Optimal contraction ordering — greedy path search for 3+ operands
  • Multi-contraction shared-operand XLA pre-pinning
  • Contraction plan cache (clear_plan_cache / plan_cache_info)
  • Alpha/beta scaling for einsum (cuTENSOR GEMM-style)
  • Input validation with descriptive errors
  • Tensor Train (TT) decomposition (TT-SVD)
  • Non-negative CP + warm-start CP
  • PEP 561 py.typed marker
  • Mixed precision / dtype override for bf16/fp16
  • precision= kwarg ("fast" / "kahan" fp64 promotion / "dd" stub)
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

Disclaimer

trnsci is an independent open-source project. It is not sponsored by, endorsed by, or affiliated with Amazon.com, Inc., Amazon Web Services, Inc., or Annapurna Labs Ltd.

"AWS", "Amazon", "Trainium", "Inferentia", "NeuronCore", "Neuron SDK", and related identifiers are trademarks of their respective owners and are used here solely for descriptive and interoperability purposes. Use does not imply endorsement, partnership, or any other relationship.

All work, opinions, analyses, benchmark results, architectural commentary, and editorial judgments in this repository and on trnsci.dev are those of the project's contributors. They do not represent the views, positions, or commitments of Amazon, AWS, or Annapurna Labs.

Feedback directed at the Neuron SDK or Trainium hardware is good-faith ecosystem commentary from independent users. It is not privileged information, is not pre-reviewed by AWS, and should not be read as authoritative about product roadmap, behavior, or quality.

For official AWS guidance, see aws-neuron documentation and the AWS Trainium product page.

Metadata

Release files for trntensor 0.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trntensor 0.17.0
File Size Uploaded Provenance Actions
trntensor-0.17.0.tar.gz 226.3 kB With provenance Details for trntensor-0.17.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for trntensor 0.17.0
File Interpreter ABI Platform Actions
trntensor-0.17.0-py3-none-any.whl Python 3 none any Details for trntensor-0.17.0-py3-none-any.whl

Total release size: 274.2 kB

Release files / trntensor-0.17.0.tar.gz

Download URL trntensor-0.17.0.tar.gz
Size 226.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2e1b7ff91113d74fc295be20b1a642490aa4e36bb4d6162cd129f08005213172
BLAKE2b-256 checksum
How to use checksums
1caef801d7c5134245a47c6a4949c008c3967b7c8f7372f8577607040c4e8f6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / trntensor-0.17.0-py3-none-any.whl

Download URL trntensor-0.17.0-py3-none-any.whl
Size 47.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80a2d8ea158ede6530322f6a4a2834dd05ceeade950534800b73d68f8b88f36d
BLAKE2b-256 checksum
How to use checksums
73bab3438f919447708b94de371be94849bd4f18be84b9ecf78b0066eca3d1b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Security for trntensor 0.17.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for trntensor-0.17.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page