trntensor 0.1.1__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. trntensor-0.3.0/.github/workflows/ci.yml +59 -0
  2. trntensor-0.3.0/.github/workflows/notify-umbrella.yml +39 -0
  3. {trntensor-0.1.1 → trntensor-0.3.0}/.github/workflows/publish.yml +7 -2
  4. {trntensor-0.1.1 → trntensor-0.3.0}/.gitignore +6 -0
  5. trntensor-0.3.0/.pre-commit-config.yaml +11 -0
  6. trntensor-0.3.0/CHANGELOG.md +201 -0
  7. {trntensor-0.1.1 → trntensor-0.3.0}/CLAUDE.md +12 -0
  8. {trntensor-0.1.1 → trntensor-0.3.0}/CODE_OF_CONDUCT.md +1 -1
  9. {trntensor-0.1.1 → trntensor-0.3.0}/CONTRIBUTING.md +3 -2
  10. trntensor-0.3.0/PKG-INFO +143 -0
  11. trntensor-0.3.0/README.md +112 -0
  12. trntensor-0.3.0/benchmarks/__init__.py +0 -0
  13. trntensor-0.3.0/benchmarks/bench_einsum.py +190 -0
  14. trntensor-0.3.0/docs/api/decompose.md +41 -0
  15. trntensor-0.3.0/docs/api/einsum.md +43 -0
  16. trntensor-0.3.0/docs/api/index.md +9 -0
  17. trntensor-0.3.0/docs/api/nki.md +78 -0
  18. trntensor-0.3.0/docs/api/plan.md +36 -0
  19. trntensor-0.3.0/docs/api/quantum.md +99 -0
  20. trntensor-0.3.0/docs/architecture.md +63 -0
  21. trntensor-0.3.0/docs/benchmarks.md +70 -0
  22. trntensor-0.3.0/docs/contraction_patterns.md +183 -0
  23. trntensor-0.3.0/docs/developing_kernels.md +36 -0
  24. trntensor-0.3.0/docs/tutorial_df_mp2.md +159 -0
  25. {trntensor-0.1.1 → trntensor-0.3.0}/examples/df_mp2_einsum.py +4 -3
  26. {trntensor-0.1.1 → trntensor-0.3.0}/infra/terraform/main.tf +2 -2
  27. {trntensor-0.1.1 → trntensor-0.3.0}/mkdocs.yml +11 -1
  28. trntensor-0.3.0/pyproject.toml +89 -0
  29. {trntensor-0.1.1 → trntensor-0.3.0}/scripts/bench_to_md.py +3 -8
  30. {trntensor-0.1.1 → trntensor-0.3.0}/scripts/run_benchmarks.sh +2 -2
  31. {trntensor-0.1.1 → trntensor-0.3.0}/scripts/run_neuron_tests.sh +17 -14
  32. trntensor-0.3.0/scripts/run_simulator_tests.sh +137 -0
  33. trntensor-0.3.0/tests/conftest.py +12 -0
  34. {trntensor-0.1.1 → trntensor-0.3.0}/tests/test_decompose.py +104 -9
  35. trntensor-0.3.0/tests/test_einsum.py +293 -0
  36. trntensor-0.3.0/tests/test_nki.py +43 -0
  37. trntensor-0.3.0/tests/test_nki_kernels.py +377 -0
  38. trntensor-0.3.0/tests/test_nki_sim.py +154 -0
  39. trntensor-0.3.0/tests/test_plan.py +247 -0
  40. trntensor-0.3.0/tests/test_quantum.py +110 -0
  41. trntensor-0.3.0/trntensor/__init__.py +51 -0
  42. trntensor-0.3.0/trntensor/decompose.py +278 -0
  43. trntensor-0.3.0/trntensor/einsum.py +228 -0
  44. {trntensor-0.1.1 → trntensor-0.3.0}/trntensor/nki/__init__.py +3 -1
  45. trntensor-0.3.0/trntensor/nki/_kernels.py +296 -0
  46. trntensor-0.3.0/trntensor/nki/dispatch.py +343 -0
  47. trntensor-0.3.0/trntensor/plan.py +316 -0
  48. trntensor-0.3.0/trntensor/py.typed +0 -0
  49. trntensor-0.3.0/trntensor/quantum.py +194 -0
  50. trntensor-0.3.0/trntensor.egg-info/PKG-INFO +143 -0
  51. {trntensor-0.1.1 → trntensor-0.3.0}/trntensor.egg-info/SOURCES.txt +23 -2
  52. {trntensor-0.1.1 → trntensor-0.3.0}/trntensor.egg-info/requires.txt +3 -4
  53. trntensor-0.3.0/uv.lock +1637 -0
  54. trntensor-0.1.1/.github/workflows/ci.yml +0 -20
  55. trntensor-0.1.1/.github/workflows/docs.yml +0 -38
  56. trntensor-0.1.1/CHANGELOG.md +0 -32
  57. trntensor-0.1.1/PKG-INFO +0 -106
  58. trntensor-0.1.1/README.md +0 -76
  59. trntensor-0.1.1/docs/api.md +0 -27
  60. trntensor-0.1.1/docs/architecture.md +0 -34
  61. trntensor-0.1.1/pyproject.toml +0 -52
  62. trntensor-0.1.1/tests/conftest.py +0 -5
  63. trntensor-0.1.1/tests/test_einsum.py +0 -149
  64. trntensor-0.1.1/tests/test_plan.py +0 -111
  65. trntensor-0.1.1/trntensor/__init__.py +0 -21
  66. trntensor-0.1.1/trntensor/decompose.py +0 -180
  67. trntensor-0.1.1/trntensor/einsum.py +0 -110
  68. trntensor-0.1.1/trntensor/nki/dispatch.py +0 -36
  69. trntensor-0.1.1/trntensor/plan.py +0 -134
  70. trntensor-0.1.1/trntensor.egg-info/PKG-INFO +0 -106
  71. {trntensor-0.1.1 → trntensor-0.3.0}/LICENSE +0 -0
  72. {trntensor-0.1.1 → trntensor-0.3.0}/docs/aws_setup.md +0 -0
  73. {trntensor-0.1.1 → trntensor-0.3.0}/docs/index.md +0 -0
  74. {trntensor-0.1.1 → trntensor-0.3.0}/docs/installation.md +0 -0
  75. {trntensor-0.1.1 → trntensor-0.3.0}/docs/quickstart.md +0 -0
  76. {trntensor-0.1.1 → trntensor-0.3.0}/infra/terraform/README.md +0 -0
  77. {trntensor-0.1.1 → trntensor-0.3.0}/setup.cfg +0 -0
  78. {trntensor-0.1.1 → trntensor-0.3.0}/trntensor.egg-info/dependency_links.txt +0 -0
  79. {trntensor-0.1.1 → trntensor-0.3.0}/trntensor.egg-info/top_level.txt +0 -0
@@ -0,0 +1,59 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ # Opt into Node.js 24 for all third-party JavaScript actions ahead of
9
+ # GitHub's June 2026 default switch. Silences the Node 20 deprecation
10
+ # notice emitted by setup-uv and codecov-action's github-script dep.
11
+ env:
12
+ FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
13
+
14
+ jobs:
15
+ lint:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v6
19
+ - uses: astral-sh/setup-uv@v6
20
+ - run: uvx ruff check .
21
+ - run: uvx ruff format --check .
22
+
23
+ test:
24
+ runs-on: ubuntu-latest
25
+ strategy:
26
+ matrix:
27
+ python-version: ["3.10", "3.11", "3.12"]
28
+ steps:
29
+ - uses: actions/checkout@v6
30
+ - uses: astral-sh/setup-uv@v6
31
+ with:
32
+ python-version: ${{ matrix.python-version }}
33
+ - run: uv sync --extra dev
34
+ - run: uv run pytest tests/ -v -x --tb=short -m "not neuron and not nki_simulator" --cov=trntensor --cov-report=xml
35
+
36
+ - name: Upload coverage reports to Codecov
37
+ uses: codecov/codecov-action@v5
38
+ with:
39
+ token: ${{ secrets.CODECOV_TOKEN }}
40
+ slug: trnsci/trntensor
41
+
42
+ nki-simulator:
43
+ # Runs NKI kernels through nki.simulate(kernel)(numpy_args) on CPU.
44
+ # Catches Python-trace-level errors (bad kwargs, dropped ops, shape
45
+ # mismatches) pre-merge without AWS round-trips. MLIR verifier
46
+ # errors remain hardware-only (simulator explicitly skips compile).
47
+ runs-on: ubuntu-latest
48
+ steps:
49
+ - uses: actions/checkout@v6
50
+ - uses: astral-sh/setup-uv@v6
51
+ with:
52
+ python-version: "3.12"
53
+ - run: uv sync --extra dev
54
+ - name: Install NKI simulator
55
+ run: uv pip install --extra-index-url https://pip.repos.neuron.amazonaws.com "nki>=0.3.0"
56
+ - name: Run simulator-backed kernel tests
57
+ env:
58
+ TRNTENSOR_USE_SIMULATOR: "1"
59
+ run: uv run pytest tests/ -v -m nki_simulator --tb=short
@@ -0,0 +1,39 @@
1
+ name: Notify trnsci umbrella of docs change
2
+
3
+ # Fires a repository_dispatch at trnsci/trnsci whenever this repo's docs or
4
+ # mkdocs.yml change on main, so the combined site at trnsci.dev rebuilds
5
+ # immediately rather than waiting for the daily cron.
6
+ #
7
+ # Requires repo/org secret TRNSCI_DISPATCH_TOKEN — a fine-grained PAT scoped
8
+ # to the trnsci/trnsci repo with "Contents: Read and write" (which covers
9
+ # repository_dispatch). See README for setup.
10
+
11
+ on:
12
+ push:
13
+ branches: [main]
14
+ paths:
15
+ - "docs/**"
16
+ - "mkdocs.yml"
17
+ - "README.md"
18
+ - "CHANGELOG.md"
19
+ workflow_dispatch:
20
+
21
+ env:
22
+ FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
23
+
24
+ jobs:
25
+ dispatch:
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - name: Trigger umbrella rebuild
29
+ env:
30
+ GH_TOKEN: ${{ secrets.TRNSCI_DISPATCH_TOKEN }}
31
+ run: |
32
+ if [ -z "${GH_TOKEN:-}" ]; then
33
+ echo "::notice::TRNSCI_DISPATCH_TOKEN not set; umbrella will pick up this change on next daily cron or manual dispatch."
34
+ exit 0
35
+ fi
36
+ gh api --method POST repos/trnsci/trnsci/dispatches \
37
+ -f event_type=subproject-updated \
38
+ -f "client_payload[repo]=${GITHUB_REPOSITORY}" \
39
+ -f "client_payload[sha]=${GITHUB_SHA}"
@@ -4,12 +4,15 @@ on:
4
4
  release:
5
5
  types: [published]
6
6
 
7
+ env:
8
+ FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
9
+
7
10
  jobs:
8
11
  build:
9
12
  runs-on: ubuntu-latest
10
13
  steps:
11
- - uses: actions/checkout@v4
12
- - uses: actions/setup-python@v5
14
+ - uses: actions/checkout@v6
15
+ - uses: actions/setup-python@v6
13
16
  with:
14
17
  python-version: "3.12"
15
18
  - run: pip install build
@@ -22,6 +25,7 @@ jobs:
22
25
  publish-pypi:
23
26
  needs: build
24
27
  runs-on: ubuntu-latest
28
+ # Only publish stable releases (v1.2.3), not pre-releases (v1.2.3-rc1)
25
29
  if: ${{ !contains(github.event.release.tag_name, '-') }}
26
30
  environment:
27
31
  name: pypi
@@ -38,6 +42,7 @@ jobs:
38
42
  publish-testpypi:
39
43
  needs: build
40
44
  runs-on: ubuntu-latest
45
+ # Only publish pre-releases to TestPyPI
41
46
  if: ${{ contains(github.event.release.tag_name, '-') }}
42
47
  environment:
43
48
  name: testpypi
@@ -31,3 +31,9 @@ site/
31
31
  # coverage artifacts
32
32
  .coverage
33
33
  htmlcov/
34
+
35
+ # terraform local state
36
+ infra/terraform/.terraform/
37
+ infra/terraform/terraform.tfstate*
38
+ infra/terraform/.terraform.lock.hcl
39
+ benchmark_results.json
@@ -0,0 +1,11 @@
1
+ # Install locally: pip install pre-commit && pre-commit install
2
+ # Runs on `git commit`; ruff auto-fixes staged Python files then formats them.
3
+ # CI re-checks the same rules in the lint job — pre-commit keeps CI green.
4
+
5
+ repos:
6
+ - repo: https://github.com/astral-sh/ruff-pre-commit
7
+ rev: v0.6.9
8
+ hooks:
9
+ - id: ruff
10
+ args: [--fix]
11
+ - id: ruff-format
@@ -0,0 +1,201 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+
12
+ - **`dtype` mixed-precision override for `einsum`** (#22) — accepts string
13
+ aliases (`"bf16"`, `"fp16"`, `"f32"`) or `torch.dtype` instances. When set,
14
+ all operands are cast to the requested dtype before contracting and the
15
+ result is returned in that dtype. Matches Neuron SDK autocast recommendations;
16
+ use `dtype="bf16"` to route fp32 models through the NKI bf16 matmul path
17
+ without changing the model's weight dtype.
18
+
19
+ ## [0.3.0] — 2026-04-16
20
+
21
+ ### Added
22
+
23
+ - **Greedy contraction-path search for 3+ operand `einsum`** (#18) —
24
+ `plan_contraction()` now returns `strategy="path"` for three or more
25
+ operands. `_greedy_path_search` selects the cheapest binary contraction
26
+ order by minimizing per-step FLOP cost; the resulting
27
+ `ContractionPlan.contraction_path` drives `_execute_path`, which
28
+ routes each binary step through the full backend selection stack so
29
+ large sub-contractions still dispatch to NKI.
30
+
31
+ - **`multi_einsum` shared-operand XLA residency** (#19) — When NKI
32
+ dispatch is active, `multi_einsum` detects operand tensors that
33
+ appear in more than one contraction (by object identity) and
34
+ pre-pins them to the XLA device once before executing the loop.
35
+ Eliminates redundant host↔device transfers for workloads like DF-MP2
36
+ where the three-center integral tensor `B` feeds many pair
37
+ contractions. Falls back to the existing per-contraction loop on CPU.
38
+
39
+ - **Subscript and shape validation with descriptive errors** (#26) —
40
+ `plan_contraction()` now validates subscripts up-front and raises
41
+ `ValueError` with precise messages: wrong operand count, rank
42
+ mismatch, and inconsistent index sizes are all caught before any
43
+ torch operation runs. Eliminates cryptic downstream errors from
44
+ `torch.einsum`.
45
+
46
+ - **PEP 561 `py.typed` marker** (#25) — `trntensor` now ships a
47
+ `py.typed` file so type checkers (mypy, pyright, etc.) recognise
48
+ the package as typed and apply inline annotations.
49
+
50
+ - **`alpha`/`beta` scaling for `einsum`** (#20) — matches cuTENSOR's
51
+ GEMM-style interface:
52
+ `einsum(subscripts, A, B, alpha=α, beta=β, out=C)` returns
53
+ `α * contract(A, B) + β * C`. Defaults (`alpha=1, beta=0, out=None`)
54
+ preserve existing behaviour exactly. Useful for accumulation patterns
55
+ and in-place gradient updates without an extra allocation.
56
+
57
+ - **Contraction plan cache** (#29 partial) — `plan_contraction()` caches
58
+ results by `(subscripts, operand shapes)`. Repeated calls with the same
59
+ subscript and shapes skip replanning entirely. `clear_plan_cache()` and
60
+ `plan_cache_info()` are exported from the top-level API.
61
+
62
+ - **Tensor Train (TT) decomposition** (#23) — `tt_decompose(tensor, max_rank)`
63
+ decomposes a d-dimensional tensor into a chain of 3-tensor cores via TT-SVD
64
+ (Oseledets 2011), bond dimension capped at `max_rank`. `tt_reconstruct(cores)`
65
+ contracts the chain back. Useful for DMRG-style high-dimensional compression.
66
+
67
+ - **Non-negative CP and warm-start CP** (#24) — `cp_decompose` gains two new
68
+ keyword arguments: `nonneg=True` switches ALS to multiplicative updates
69
+ to enforce non-negative factors; `factors=` accepts a list of pre-computed
70
+ factor matrices to warm-start from, skipping random initialization.
71
+ Both options compose.
72
+
73
+ ## [0.2.0] — 2026-04-15
74
+
75
+ ### Added
76
+
77
+ - **`trntensor.to_xla(tensor)` / `trntensor.from_xla(tensor)`** — explicit
78
+ operand residency on the Trainium XLA device. Pre-pinning operands
79
+ lets repeated trntensor calls skip per-dispatch host↔device
80
+ transfer, which otherwise dominates at current kernel sizes. The
81
+ full DF-MP2 pipeline (`ao_to_mo_transform` → `mp2_energy`) with all
82
+ operands pre-pinned pays transfer cost once instead of once per
83
+ call. The dispatch layer's `_to_xla` helper takes a fast path when
84
+ every operand is already on XLA, returning the result on XLA — the
85
+ caller decides when to pull back via `from_xla`. Closes #34.
86
+ - **`trntensor.ao_to_mo_transform(eri, C_occ, C_vir)`** — fused 4-index
87
+ AO→MO integral transform with K-tiling over the basis index (#37).
88
+ One NKI program computes `B[i,a,P] = Σ_{μν} C_occ[μ,i] · C_vir[ν,a] ·
89
+ eri[μ,ν,P]`. Tiles over μ (step 1) and ν (step 2) in TILE_K=128
90
+ chunks so `nbasis` up to 512 is supported; dispatch pads to the
91
+ nearest TILE_K multiple. Shape constraints: `nbasis ≤ 512`,
92
+ `nocc ≤ 128`, `nvir ≤ 512`. Composes with `mp2_energy` for the full
93
+ DF-MP2 pipeline from AO integrals to correlation energy. Validated
94
+ on trn1 (hardware) and via the CPU simulator CI job.
95
+ - **NKI CPU simulator dispatch** via `TRNTENSOR_USE_SIMULATOR=1`.
96
+ Routes kernels through `nki.simulate(kernel)(numpy_args)` on CPU,
97
+ bypassing `torch_xla` + NEFF compile. Iteration loop drops from
98
+ ~5 min per SSM round-trip to seconds. Correctness-only — MLIR
99
+ verifier errors remain hardware-only.
100
+ - **`nki-simulator` CI job on `ubuntu-latest`** — runs the
101
+ `nki_simulator`-marked suite against `nki>=0.3.0` from the AWS pip
102
+ index on every push + PR. Zero AWS cost for the correctness gate.
103
+ - `tests/test_nki_sim.py` — simulator-backed correctness suite,
104
+ marker `nki_simulator`. Covers matmul, batched matmul,
105
+ `ao_to_mo_transform` (including K-tiled nbasis=256 and non-aligned
106
+ nbasis=200), and `mp2_energy`.
107
+ - `scripts/run_simulator_tests.sh` — SSM runner for the simulator
108
+ suite on the trn1 DLAMI.
109
+ - `docs/developing_kernels.md` — NKI kernel development guide with
110
+ trntensor-specific env vars and file locations.
111
+
112
+ ### Changed
113
+
114
+ - **Migrated to NKI 0.3.0 / Neuron SDK 2.29.** Canonical `nki.*`
115
+ namespace; the legacy `neuronxcc.nki.*` shim is no longer used.
116
+ Kernels updated for the NKI 0.3.0 breaking-change surface:
117
+ `nisa.nc_matmul(dst=, stationary=, moving=, accumulate=True)` (all
118
+ kwargs); `nl.copy(psum)` returns a view — use `nl.ndarray` +
119
+ `nisa.tensor_copy` instead; tensor-tensor `nl.divide` dropped — use
120
+ `multiply × reciprocal`.
121
+ - Dev workflow migrated to [uv](https://github.com/astral-sh/uv).
122
+ `uv sync --extra dev` replaces `pip install -e ".[dev]"`; CI uses
123
+ `astral-sh/setup-uv@v6` and `uv run pytest` / `uvx ruff`. `uv.lock`
124
+ is committed for reproducible installs.
125
+ - Removed the `[neuron]` optional-dependencies extra. `nki` is
126
+ installed from the AWS Neuron pip index in CI or provided by the
127
+ Deep Learning AMI's pre-built venv on hardware.
128
+ - `CONTRIBUTING.md` updated to reflect the uv-based setup.
129
+
130
+ ### Fixed
131
+
132
+ - `mp2_energy_kernel` 1D-load ambiguity on pre-pinned XLA ε inputs
133
+ (#38). Reshape `eps_occ` / `eps_vir` to 2D `(N, 1)` at the dispatch
134
+ boundary; partition-dim inference is unambiguous regardless of
135
+ residency state.
136
+ - `mp2_energy_kernel` 0-D SBUF rejection (`SBUF tensors must have at
137
+ least 2 dimensions`). Per-`(i,j)` reduction now uses a persistent
138
+ `(1, 1)` SBUF accumulator (`nl.zeros((1, 1), ...)`) instead of a
139
+ direct `nl.sum` store.
140
+ - `_to_xla` fast-path now calls `xm.mark_step()` when operands are
141
+ already on XLA, forcing pending lazy computations to materialize
142
+ before the next kernel dispatch.
143
+
144
+ ### Known limitation
145
+
146
+ - The full DF-MP2 pipeline (`ao_to_mo_transform` → `mp2_energy`) with
147
+ every operand pre-pinned exposes an NKI compiler bug on trn1: the
148
+ combined XLA lazy graph provokes `trn2-only shared memory`
149
+ instructions that fail verification on trn1. Workaround: `from_xla`
150
+ the intermediate `B` between the two calls. Tracked in #39 for
151
+ upstream AWS escalation.
152
+
153
+ ## [0.1.2] — 2026-04-12
154
+
155
+ ### Changed
156
+
157
+ - `set_backend("nki")` now raises `RuntimeError` on non-Neuron hosts
158
+ instead of silently accepting the backend and failing later. Matches
159
+ the sibling-suite pattern.
160
+ - CI actions bumped to `actions/checkout@v6` + `actions/setup-python@v6`
161
+ (Node.js 24), ahead of GitHub's June 2026 default switch.
162
+ - pyproject metadata normalized across the trnsci suite (author email,
163
+ URLs, classifier list).
164
+ - Standalone `docs.yml` removed — docs are now served via `trnsci.dev`
165
+ through the umbrella's combined build. `notify-umbrella.yml` pings
166
+ the umbrella on docs changes.
167
+ - `infra/terraform/main.tf`: user-data clone URL corrected to
168
+ `trnsci/trntensor`.
169
+
170
+ ### Added
171
+
172
+ - `benchmarks/bench_einsum.py` — pytest-benchmark cases for einsum
173
+ dispatch and decompositions. CPU baseline numbers populated in
174
+ `docs/benchmarks.md`.
175
+ - `tests/test_nki.py` — backend-dispatch unit tests (CPU path).
176
+
177
+ ## [0.1.1] — 2026-04-12
178
+
179
+ ### Added
180
+
181
+ - mkdocs site with `index`, `installation`, `quickstart`, `api`, `architecture`, `aws_setup`
182
+ - `infra/terraform/` for on-hardware CI instance provisioning
183
+ - `scripts/run_neuron_tests.sh` and benchmark helpers
184
+ - GitHub Actions `ci.yml`, `docs.yml`, `publish.yml`
185
+ - `Issues` and `Documentation` URLs in pyproject.toml
186
+ - `tests/test_plan.py` — dedicated planner unit tests (parsing,
187
+ strategy selection, FLOP estimates); extended CP / Tucker coverage
188
+ (all-zero tensor, rank > min dim, unequal mode ranks)
189
+
190
+ ### Changed
191
+
192
+ - Bumped `neuronxcc` floor from `>=2.15` to `>=2.24` to unify with the
193
+ rest of the trnsci suite. `torch-neuronx` floor bumped to `>=2.9`.
194
+
195
+ ## [0.1.0] — 2026-04-12
196
+
197
+ ### Added
198
+
199
+ - Initial scaffold: einsum with contraction planning, CP / Tucker decompositions
200
+ - NKI dispatch with fused-contraction kernel stubs
201
+ - `examples/df_mp2_einsum.py` — DF-MP2 energy via einsum
@@ -59,3 +59,15 @@ pip install -e ".[dev]"
59
59
  pytest tests/ -v
60
60
  python examples/df_mp2_einsum.py --demo
61
61
  ```
62
+
63
+ ## Blog posts
64
+
65
+ When asked to draft a blog post for this library for the [trnsci blog](https://trnsci.dev/blog/):
66
+
67
+ 1. Read the editorial brief at [`docs/blog/AUTHOR_BRIEF.md`](https://github.com/trnsci/trnsci/blob/main/docs/blog/AUTHOR_BRIEF.md) in the umbrella repo (trnsci/trnsci). It defines voice (authorless, library-as-subject), stance (architecture-first, transparency-always), and the nine required section headings.
68
+
69
+ 2. Find the prompt block for this library in [`BLOG_PROMPTS.md`](https://github.com/trnsci/trnsci/blob/main/BLOG_PROMPTS.md) at the umbrella repo root. It carries library-specific context and suggested architectural angles.
70
+
71
+ 3. Draft the post following the brief. Open a PR against `trnsci/trnsci` at `docs/blog/posts/<YYYY-MM-DD>-<slug>.md`. Scott (suite director) reviews before merge.
72
+
73
+ The umbrella repo — not this one — owns the blog. Per-library retrospective posts are unsigned; library is the subject, no byline. See the brief for the full set of rules.
@@ -12,7 +12,7 @@ This Code applies within all project spaces — the GitHub repositories under th
12
12
 
13
13
  Concerns about behaviour in project spaces may be reported confidentially to:
14
14
 
15
- **3011922+scttfrdmn@users.noreply.github.com**
15
+ **scttfrdmn@gmail.com**
16
16
 
17
17
  All reports will be reviewed and investigated promptly and fairly. The project maintainers are obligated to respect the privacy and security of the reporter.
18
18
 
@@ -26,8 +26,9 @@ A single sub-project in isolation:
26
26
 
27
27
  ```bash
28
28
  cd trnfft # or any other
29
- pip install -e ".[dev]"
30
- pytest tests/ -v -m "not neuron"
29
+ uv sync --extra dev
30
+ uv run pre-commit install # ruff check + format on every commit
31
+ uv run pytest tests/ -v -m "not neuron"
31
32
  ```
32
33
 
33
34
  ## Tests
@@ -0,0 +1,143 @@
1
+ Metadata-Version: 2.4
2
+ Name: trntensor
3
+ Version: 0.3.0
4
+ Summary: Tensor contractions for AWS Trainium via NKI
5
+ Author-email: Scott Friedman <scttfrdmn@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/trnsci/trntensor
8
+ Project-URL: Documentation, https://trnsci.dev/trntensor/
9
+ Project-URL: Repository, https://github.com/trnsci/trntensor
10
+ Project-URL: Issues, https://github.com/trnsci/trntensor/issues
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering
15
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: torch>=2.1
20
+ Requires-Dist: numpy>=1.24
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=7.0; extra == "dev"
23
+ Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
24
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
25
+ Requires-Dist: ruff>=0.6; extra == "dev"
26
+ Requires-Dist: pre-commit>=3.7; extra == "dev"
27
+ Requires-Dist: scipy>=1.11; extra == "dev"
28
+ Requires-Dist: mkdocs>=1.5; extra == "dev"
29
+ Requires-Dist: mkdocs-material>=9.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # trntensor
33
+
34
+ [![CI](https://github.com/trnsci/trntensor/actions/workflows/ci.yml/badge.svg)](https://github.com/trnsci/trntensor/actions/workflows/ci.yml)
35
+ [![codecov](https://codecov.io/gh/trnsci/trntensor/graph/badge.svg)](https://codecov.io/gh/trnsci/trntensor)
36
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
37
+ [![PyPI](https://img.shields.io/pypi/v/trntensor)](https://pypi.org/project/trntensor/)
38
+ [![Python](https://img.shields.io/pypi/pyversions/trntensor)](https://pypi.org/project/trntensor/)
39
+ [![License](https://img.shields.io/github/license/trnsci/trntensor)](LICENSE)
40
+ [![Docs](https://img.shields.io/badge/docs-trnsci.dev-blue)](https://trnsci.dev/trntensor/)
41
+
42
+ Tensor contractions for AWS Trainium via NKI.
43
+
44
+ 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](https://github.com/trnsci)).
45
+
46
+ ## Current phase
47
+
48
+ trntensor follows the [trnsci 5-phase roadmap](https://trnsci.dev/roadmap/). Active work is tracked in phase-labeled GitHub issues:
49
+
50
+ - **[Phase 1 — correctness](https://github.com/trnsci/trntensor/issues/27)** (active): matmul + batched-matmul NKI kernels in place; awaiting hardware validation + additional `@pytest.mark.neuron` coverage.
51
+ - **[Phase 2 — precision](https://github.com/trnsci/trntensor/issues/28)**: precision-aware contraction path selection (depends on [trnblas#22](https://github.com/trnsci/trnblas/issues/22) double-double GEMM).
52
+ - **[Phase 3 — perf](https://github.com/trnsci/trntensor/issues/29)**: opt_einsum-style path planner, plan cache reuse.
53
+ - **[Phase 4 — multi-chip](https://github.com/trnsci/trntensor/issues/30)**: sharded tensor contractions.
54
+ - **[Phase 5 — generation](https://github.com/trnsci/trntensor/issues/31)**: trn2 fused multi-contraction paths.
55
+
56
+ Suite-wide tracker: [trnsci/trnsci#1](https://github.com/trnsci/trnsci/issues/1).
57
+
58
+ ## Install
59
+
60
+ ```bash
61
+ pip install trntensor
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ ```python
67
+ import torch
68
+ import trntensor
69
+
70
+ # Einsum — drop-in for torch.einsum with contraction planning
71
+ C = trntensor.einsum("ij,jk->ik", A, B) # matmul
72
+ T = trntensor.einsum("ap,bp->ab", B_i, B_j) # DF-MP2 contraction
73
+ X = trntensor.einsum("mi,mnP->inP", C_occ, eri) # AO→MO transform
74
+
75
+ # Contraction planning
76
+ plan = trntensor.plan_contraction("ij,jk->ik", A, B)
77
+ flops = trntensor.estimate_flops("ij,jk->ik", A, B)
78
+
79
+ # CP decomposition (tensor hypercontraction)
80
+ factors, weights = trntensor.cp_decompose(tensor, rank=10)
81
+ reconstructed = trntensor.cp_reconstruct(factors, weights)
82
+
83
+ # Tucker decomposition (HOSVD)
84
+ core, factors = trntensor.tucker_decompose(tensor, ranks=(5, 5, 5))
85
+ ```
86
+
87
+ ## Operations
88
+
89
+ | Category | Operation | Description |
90
+ |----------|-----------|-------------|
91
+ | Contraction | `einsum` | General tensor contraction |
92
+ | Contraction | `multi_einsum` | Multiple contractions (fusion-ready) |
93
+ | Planning | `plan_contraction` | Analyze and select strategy |
94
+ | Planning | `estimate_flops` | FLOPs for a contraction |
95
+ | Decomposition | `cp_decompose` | CP/PARAFAC via ALS |
96
+ | Decomposition | `tucker_decompose` | Tucker via HOSVD |
97
+
98
+ ## Status
99
+
100
+ - [x] Einsum with matmul/bmm/torch dispatch
101
+ - [x] Contraction planner
102
+ - [x] CP decomposition (ALS)
103
+ - [x] Tucker decomposition (HOSVD)
104
+ - [x] DF-MP2 einsum example
105
+ - [x] NKI fused contraction kernels (`mp2_energy`, `ao_to_mo_transform`)
106
+ - [x] XLA operand residency (`to_xla` / `from_xla`)
107
+ - [x] NKI CPU simulator + `nki-simulator` CI gate
108
+ - [x] Optimal contraction ordering — greedy path search for 3+ operands
109
+ - [x] Multi-contraction shared-operand XLA pre-pinning
110
+ - [x] Contraction plan cache (`clear_plan_cache` / `plan_cache_info`)
111
+ - [x] Alpha/beta scaling for `einsum` (cuTENSOR GEMM-style)
112
+ - [x] Input validation with descriptive errors
113
+ - [x] Tensor Train (TT) decomposition (TT-SVD)
114
+ - [x] Non-negative CP + warm-start CP
115
+ - [x] PEP 561 `py.typed` marker
116
+ - [ ] Mixed precision / `dtype` override for bf16/fp16
117
+
118
+ ## Related Projects
119
+
120
+ | Project | What |
121
+ |---------|------|
122
+ | [trnfft](https://github.com/scttfrdmn/trnfft) | FFT + complex ops |
123
+ | [trnblas](https://github.com/scttfrdmn/trnblas) | BLAS operations |
124
+ | [trnsolver](https://github.com/scttfrdmn/trnsolver) | Linear solvers |
125
+ | [trnrand](https://github.com/scttfrdmn/trnrand) | Random number generation |
126
+ | [trnsparse](https://github.com/scttfrdmn/trnsparse) | Sparse operations |
127
+
128
+ ## License
129
+
130
+ Apache 2.0 — Copyright 2026 Scott Friedman
131
+
132
+
133
+ ## Disclaimer
134
+
135
+ 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.
136
+
137
+ "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.
138
+
139
+ All work, opinions, analyses, benchmark results, architectural commentary, and editorial judgments in this repository and on [trnsci.dev](https://trnsci.dev) are those of the project's contributors. They do not represent the views, positions, or commitments of Amazon, AWS, or Annapurna Labs.
140
+
141
+ 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.
142
+
143
+ For official AWS guidance, see [aws-neuron documentation](https://awsdocs-neuron.readthedocs-hosted.com/) and the [AWS Trainium product page](https://aws.amazon.com/ai/machine-learning/trainium/).
@@ -0,0 +1,112 @@
1
+ # trntensor
2
+
3
+ [![CI](https://github.com/trnsci/trntensor/actions/workflows/ci.yml/badge.svg)](https://github.com/trnsci/trntensor/actions/workflows/ci.yml)
4
+ [![codecov](https://codecov.io/gh/trnsci/trntensor/graph/badge.svg)](https://codecov.io/gh/trnsci/trntensor)
5
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
6
+ [![PyPI](https://img.shields.io/pypi/v/trntensor)](https://pypi.org/project/trntensor/)
7
+ [![Python](https://img.shields.io/pypi/pyversions/trntensor)](https://pypi.org/project/trntensor/)
8
+ [![License](https://img.shields.io/github/license/trnsci/trntensor)](LICENSE)
9
+ [![Docs](https://img.shields.io/badge/docs-trnsci.dev-blue)](https://trnsci.dev/trntensor/)
10
+
11
+ Tensor contractions for AWS Trainium via NKI.
12
+
13
+ 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](https://github.com/trnsci)).
14
+
15
+ ## Current phase
16
+
17
+ trntensor follows the [trnsci 5-phase roadmap](https://trnsci.dev/roadmap/). Active work is tracked in phase-labeled GitHub issues:
18
+
19
+ - **[Phase 1 — correctness](https://github.com/trnsci/trntensor/issues/27)** (active): matmul + batched-matmul NKI kernels in place; awaiting hardware validation + additional `@pytest.mark.neuron` coverage.
20
+ - **[Phase 2 — precision](https://github.com/trnsci/trntensor/issues/28)**: precision-aware contraction path selection (depends on [trnblas#22](https://github.com/trnsci/trnblas/issues/22) double-double GEMM).
21
+ - **[Phase 3 — perf](https://github.com/trnsci/trntensor/issues/29)**: opt_einsum-style path planner, plan cache reuse.
22
+ - **[Phase 4 — multi-chip](https://github.com/trnsci/trntensor/issues/30)**: sharded tensor contractions.
23
+ - **[Phase 5 — generation](https://github.com/trnsci/trntensor/issues/31)**: trn2 fused multi-contraction paths.
24
+
25
+ Suite-wide tracker: [trnsci/trnsci#1](https://github.com/trnsci/trnsci/issues/1).
26
+
27
+ ## Install
28
+
29
+ ```bash
30
+ pip install trntensor
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```python
36
+ import torch
37
+ import trntensor
38
+
39
+ # Einsum — drop-in for torch.einsum with contraction planning
40
+ C = trntensor.einsum("ij,jk->ik", A, B) # matmul
41
+ T = trntensor.einsum("ap,bp->ab", B_i, B_j) # DF-MP2 contraction
42
+ X = trntensor.einsum("mi,mnP->inP", C_occ, eri) # AO→MO transform
43
+
44
+ # Contraction planning
45
+ plan = trntensor.plan_contraction("ij,jk->ik", A, B)
46
+ flops = trntensor.estimate_flops("ij,jk->ik", A, B)
47
+
48
+ # CP decomposition (tensor hypercontraction)
49
+ factors, weights = trntensor.cp_decompose(tensor, rank=10)
50
+ reconstructed = trntensor.cp_reconstruct(factors, weights)
51
+
52
+ # Tucker decomposition (HOSVD)
53
+ core, factors = trntensor.tucker_decompose(tensor, ranks=(5, 5, 5))
54
+ ```
55
+
56
+ ## Operations
57
+
58
+ | Category | Operation | Description |
59
+ |----------|-----------|-------------|
60
+ | Contraction | `einsum` | General tensor contraction |
61
+ | Contraction | `multi_einsum` | Multiple contractions (fusion-ready) |
62
+ | Planning | `plan_contraction` | Analyze and select strategy |
63
+ | Planning | `estimate_flops` | FLOPs for a contraction |
64
+ | Decomposition | `cp_decompose` | CP/PARAFAC via ALS |
65
+ | Decomposition | `tucker_decompose` | Tucker via HOSVD |
66
+
67
+ ## Status
68
+
69
+ - [x] Einsum with matmul/bmm/torch dispatch
70
+ - [x] Contraction planner
71
+ - [x] CP decomposition (ALS)
72
+ - [x] Tucker decomposition (HOSVD)
73
+ - [x] DF-MP2 einsum example
74
+ - [x] NKI fused contraction kernels (`mp2_energy`, `ao_to_mo_transform`)
75
+ - [x] XLA operand residency (`to_xla` / `from_xla`)
76
+ - [x] NKI CPU simulator + `nki-simulator` CI gate
77
+ - [x] Optimal contraction ordering — greedy path search for 3+ operands
78
+ - [x] Multi-contraction shared-operand XLA pre-pinning
79
+ - [x] Contraction plan cache (`clear_plan_cache` / `plan_cache_info`)
80
+ - [x] Alpha/beta scaling for `einsum` (cuTENSOR GEMM-style)
81
+ - [x] Input validation with descriptive errors
82
+ - [x] Tensor Train (TT) decomposition (TT-SVD)
83
+ - [x] Non-negative CP + warm-start CP
84
+ - [x] PEP 561 `py.typed` marker
85
+ - [ ] Mixed precision / `dtype` override for bf16/fp16
86
+
87
+ ## Related Projects
88
+
89
+ | Project | What |
90
+ |---------|------|
91
+ | [trnfft](https://github.com/scttfrdmn/trnfft) | FFT + complex ops |
92
+ | [trnblas](https://github.com/scttfrdmn/trnblas) | BLAS operations |
93
+ | [trnsolver](https://github.com/scttfrdmn/trnsolver) | Linear solvers |
94
+ | [trnrand](https://github.com/scttfrdmn/trnrand) | Random number generation |
95
+ | [trnsparse](https://github.com/scttfrdmn/trnsparse) | Sparse operations |
96
+
97
+ ## License
98
+
99
+ Apache 2.0 — Copyright 2026 Scott Friedman
100
+
101
+
102
+ ## Disclaimer
103
+
104
+ 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.
105
+
106
+ "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.
107
+
108
+ All work, opinions, analyses, benchmark results, architectural commentary, and editorial judgments in this repository and on [trnsci.dev](https://trnsci.dev) are those of the project's contributors. They do not represent the views, positions, or commitments of Amazon, AWS, or Annapurna Labs.
109
+
110
+ 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.
111
+
112
+ For official AWS guidance, see [aws-neuron documentation](https://awsdocs-neuron.readthedocs-hosted.com/) and the [AWS Trainium product page](https://aws.amazon.com/ai/machine-learning/trainium/).
File without changes