trntensor 0.1.1__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 (41) hide show
  1. trntensor-0.1.1/.github/workflows/ci.yml +20 -0
  2. trntensor-0.1.1/.github/workflows/docs.yml +38 -0
  3. trntensor-0.1.1/.github/workflows/publish.yml +54 -0
  4. trntensor-0.1.1/.gitignore +33 -0
  5. trntensor-0.1.1/CHANGELOG.md +32 -0
  6. trntensor-0.1.1/CLAUDE.md +61 -0
  7. trntensor-0.1.1/CODE_OF_CONDUCT.md +25 -0
  8. trntensor-0.1.1/CONTRIBUTING.md +69 -0
  9. trntensor-0.1.1/LICENSE +201 -0
  10. trntensor-0.1.1/PKG-INFO +106 -0
  11. trntensor-0.1.1/README.md +76 -0
  12. trntensor-0.1.1/docs/api.md +27 -0
  13. trntensor-0.1.1/docs/architecture.md +34 -0
  14. trntensor-0.1.1/docs/aws_setup.md +79 -0
  15. trntensor-0.1.1/docs/index.md +35 -0
  16. trntensor-0.1.1/docs/installation.md +21 -0
  17. trntensor-0.1.1/docs/quickstart.md +49 -0
  18. trntensor-0.1.1/examples/df_mp2_einsum.py +84 -0
  19. trntensor-0.1.1/infra/terraform/README.md +58 -0
  20. trntensor-0.1.1/infra/terraform/main.tf +150 -0
  21. trntensor-0.1.1/mkdocs.yml +33 -0
  22. trntensor-0.1.1/pyproject.toml +52 -0
  23. trntensor-0.1.1/scripts/bench_to_md.py +129 -0
  24. trntensor-0.1.1/scripts/run_benchmarks.sh +159 -0
  25. trntensor-0.1.1/scripts/run_neuron_tests.sh +140 -0
  26. trntensor-0.1.1/setup.cfg +4 -0
  27. trntensor-0.1.1/tests/conftest.py +5 -0
  28. trntensor-0.1.1/tests/test_decompose.py +124 -0
  29. trntensor-0.1.1/tests/test_einsum.py +149 -0
  30. trntensor-0.1.1/tests/test_plan.py +111 -0
  31. trntensor-0.1.1/trntensor/__init__.py +21 -0
  32. trntensor-0.1.1/trntensor/decompose.py +180 -0
  33. trntensor-0.1.1/trntensor/einsum.py +110 -0
  34. trntensor-0.1.1/trntensor/nki/__init__.py +3 -0
  35. trntensor-0.1.1/trntensor/nki/dispatch.py +36 -0
  36. trntensor-0.1.1/trntensor/plan.py +134 -0
  37. trntensor-0.1.1/trntensor.egg-info/PKG-INFO +106 -0
  38. trntensor-0.1.1/trntensor.egg-info/SOURCES.txt +39 -0
  39. trntensor-0.1.1/trntensor.egg-info/dependency_links.txt +1 -0
  40. trntensor-0.1.1/trntensor.egg-info/requires.txt +13 -0
  41. trntensor-0.1.1/trntensor.egg-info/top_level.txt +1 -0
@@ -0,0 +1,20 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.10", "3.11", "3.12"]
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: ${{ matrix.python-version }}
19
+ - run: pip install -e ".[dev]"
20
+ - run: pytest tests/ -v -x --tb=short -m "not neuron"
@@ -0,0 +1,38 @@
1
+ name: Deploy Docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ permissions:
8
+ contents: read
9
+ pages: write
10
+ id-token: write
11
+
12
+ concurrency:
13
+ group: pages
14
+ cancel-in-progress: true
15
+
16
+ jobs:
17
+ build:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: actions/setup-python@v5
22
+ with:
23
+ python-version: "3.12"
24
+ - run: pip install mkdocs mkdocs-material
25
+ - run: mkdocs build --strict
26
+ - uses: actions/upload-pages-artifact@v3
27
+ with:
28
+ path: site/
29
+
30
+ deploy:
31
+ needs: build
32
+ runs-on: ubuntu-latest
33
+ environment:
34
+ name: github-pages
35
+ url: ${{ steps.deployment.outputs.page_url }}
36
+ steps:
37
+ - id: deployment
38
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,54 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-python@v5
13
+ with:
14
+ python-version: "3.12"
15
+ - run: pip install build
16
+ - run: python -m build
17
+ - uses: actions/upload-artifact@v4
18
+ with:
19
+ name: dist
20
+ path: dist/
21
+
22
+ publish-pypi:
23
+ needs: build
24
+ runs-on: ubuntu-latest
25
+ if: ${{ !contains(github.event.release.tag_name, '-') }}
26
+ environment:
27
+ name: pypi
28
+ url: https://pypi.org/project/trntensor/
29
+ permissions:
30
+ id-token: write
31
+ steps:
32
+ - uses: actions/download-artifact@v4
33
+ with:
34
+ name: dist
35
+ path: dist/
36
+ - uses: pypa/gh-action-pypi-publish@release/v1
37
+
38
+ publish-testpypi:
39
+ needs: build
40
+ runs-on: ubuntu-latest
41
+ if: ${{ contains(github.event.release.tag_name, '-') }}
42
+ environment:
43
+ name: testpypi
44
+ url: https://test.pypi.org/project/trntensor/
45
+ permissions:
46
+ id-token: write
47
+ steps:
48
+ - uses: actions/download-artifact@v4
49
+ with:
50
+ name: dist
51
+ path: dist/
52
+ - uses: pypa/gh-action-pypi-publish@release/v1
53
+ with:
54
+ repository-url: https://test.pypi.org/legacy/
@@ -0,0 +1,33 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .eggs/
8
+ *.egg
9
+ .pytest_cache/
10
+ .tox/
11
+ .venv/
12
+ venv/
13
+ *.so
14
+ .idea/
15
+ .vscode/
16
+ *.swp
17
+ *.swo
18
+ *~
19
+ files.zip
20
+
21
+ # Terraform — never commit state (leaks resource IDs and may contain secrets)
22
+ infra/terraform/.terraform/
23
+ infra/terraform/.terraform.lock.hcl
24
+ infra/terraform/terraform.tfstate
25
+ infra/terraform/terraform.tfstate.backup
26
+ infra/terraform/*.tfvars
27
+
28
+ # mkdocs build output
29
+ site/
30
+
31
+ # coverage artifacts
32
+ .coverage
33
+ htmlcov/
@@ -0,0 +1,32 @@
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
+ ## [0.1.1] — 2026-04-12
9
+
10
+ ### Added
11
+
12
+ - mkdocs site with `index`, `installation`, `quickstart`, `api`, `architecture`, `aws_setup`
13
+ - `infra/terraform/` for on-hardware CI instance provisioning
14
+ - `scripts/run_neuron_tests.sh` and benchmark helpers
15
+ - GitHub Actions `ci.yml`, `docs.yml`, `publish.yml`
16
+ - `Issues` and `Documentation` URLs in pyproject.toml
17
+ - `tests/test_plan.py` — dedicated planner unit tests (parsing,
18
+ strategy selection, FLOP estimates); extended CP / Tucker coverage
19
+ (all-zero tensor, rank > min dim, unequal mode ranks)
20
+
21
+ ### Changed
22
+
23
+ - Bumped `neuronxcc` floor from `>=2.15` to `>=2.24` to unify with the
24
+ rest of the trnsci suite. `torch-neuronx` floor bumped to `>=2.9`.
25
+
26
+ ## [0.1.0] — 2026-04-12
27
+
28
+ ### Added
29
+
30
+ - Initial scaffold: einsum with contraction planning, CP / Tucker decompositions
31
+ - NKI dispatch with fused-contraction kernel stubs
32
+ - `examples/df_mp2_einsum.py` — DF-MP2 energy via einsum
@@ -0,0 +1,61 @@
1
+ # trntensor
2
+
3
+ Tensor contractions for AWS Trainium via NKI.
4
+ Part of the trnsci scientific computing suite.
5
+
6
+ ## What This Is
7
+
8
+ A cuTENSOR-equivalent for Trainium. Einstein summation with contraction
9
+ planning, and CP/Tucker decompositions. Expresses tensor workloads
10
+ naturally instead of decomposing to GEMM.
11
+
12
+ For DF-MP2, the natural expression `einsum("ap,bp->ab", B[i], B[j])` is
13
+ clearer than `B[i] @ B[j].T` and enables the planner to fuse operations
14
+ (e.g., folding the energy denominator division into the accumulation).
15
+
16
+ ## Architecture
17
+
18
+ ```
19
+ trntensor/
20
+ ├── trntensor/
21
+ │ ├── __init__.py
22
+ │ ├── einsum.py # einsum(), multi_einsum()
23
+ │ ├── plan.py # ContractionPlan, plan_contraction(), estimate_flops()
24
+ │ ├── decompose.py # cp_decompose, tucker_decompose (HOSVD)
25
+ │ └── nki/
26
+ │ ├── __init__.py
27
+ │ └── dispatch.py # Fused contraction kernels
28
+ ├── tests/
29
+ │ ├── test_einsum.py # Matmul, bmm, 4-index transform, DF-MP2 pattern
30
+ │ └── test_decompose.py # CP rank-1/low-rank, Tucker orthogonality
31
+ ├── examples/
32
+ │ └── df_mp2_einsum.py # DF-MP2 energy via einsum
33
+ ```
34
+
35
+ ## Contraction Planning
36
+
37
+ The planner analyzes einsum subscripts and selects:
38
+ - **matmul**: 2D contraction over single index → `torch.matmul`
39
+ - **bmm**: batched 2D contraction → `torch.bmm`
40
+ - **torch**: complex patterns → `torch.einsum`
41
+ - **(future) nki**: fused multi-index contractions on Tensor Engine
42
+
43
+ ## Decompositions for Quantum Chemistry
44
+
45
+ - **CP (CANDECOMP/PARAFAC)**: Tensor hypercontraction (THC) of
46
+ two-electron integrals. Reduces O(N⁴) storage to O(N²R).
47
+ - **Tucker (HOSVD)**: Low-rank approximation of DF coefficient tensors.
48
+ Reduces memory for large auxiliary basis sets.
49
+
50
+ ## Dependencies
51
+
52
+ - `torch>=2.1`, `numpy>=1.24`
53
+ - `neuronxcc` (optional)
54
+
55
+ ## Development
56
+
57
+ ```bash
58
+ pip install -e ".[dev]"
59
+ pytest tests/ -v
60
+ python examples/df_mp2_einsum.py --demo
61
+ ```
@@ -0,0 +1,25 @@
1
+ # Code of Conduct
2
+
3
+ This project adopts the [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1, as its code of conduct. The full text is available at:
4
+
5
+ https://www.contributor-covenant.org/version/2/1/code_of_conduct/
6
+
7
+ ## Scope
8
+
9
+ This Code applies within all project spaces — the GitHub repositories under the [trnsci](https://github.com/trnsci) organization, issue trackers, pull request discussions, and any public forums where an individual is representing the project or its community.
10
+
11
+ ## Reporting
12
+
13
+ Concerns about behaviour in project spaces may be reported confidentially to:
14
+
15
+ **3011922+scttfrdmn@users.noreply.github.com**
16
+
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
+
19
+ ## Enforcement
20
+
21
+ Maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
22
+
23
+ ## Attribution
24
+
25
+ This Code of Conduct is adapted from the Contributor Covenant, version 2.1, available at https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. It is licensed under CC BY 4.0.
@@ -0,0 +1,69 @@
1
+ # Contributing to trntensor
2
+
3
+ Thanks for your interest in contributing. This document covers the whole suite — the same guidelines apply to the umbrella and to each of the six sub-projects (`trnfft`, `trnblas`, `trnrand`, `trnsolver`, `trnsparse`, `trntensor`).
4
+
5
+ ## Where does my change belong?
6
+
7
+ - **Scoped to a single library** — bug fix, new feature, added kernel in one sub-project → open a PR in that sub-project's repo.
8
+ - **Cross-cutting** — integration examples, umbrella docs, CUDA-rosetta content, coordinated version bumps, shared tooling → open a PR against [trnsci/trnsci](https://github.com/trnsci/trnsci).
9
+
10
+ If you aren't sure, open the PR where it's easiest and we'll move it.
11
+
12
+ ## Development setup
13
+
14
+ ```bash
15
+ git clone git@github.com:trnsci/trnsci.git
16
+ cd trnsci
17
+ # Clone sibling sub-projects if you don't already have them:
18
+ for p in trnfft trnblas trnrand trnsolver trnsparse trntensor; do
19
+ [ -d "$p" ] || git clone "git@github.com:trnsci/$p.git"
20
+ done
21
+ make install-dev
22
+ make test-all
23
+ ```
24
+
25
+ A single sub-project in isolation:
26
+
27
+ ```bash
28
+ cd trnfft # or any other
29
+ pip install -e ".[dev]"
30
+ pytest tests/ -v -m "not neuron"
31
+ ```
32
+
33
+ ## Tests
34
+
35
+ - `pytest tests/ -v -m "not neuron"` — the CPU-only suite. Must pass on every PR.
36
+ - `pytest tests/ -v -m neuron` — on-hardware suite, run from a machine with AWS credentials via `scripts/run_neuron_tests.sh`. Not part of standard CI.
37
+
38
+ ## Conventions
39
+
40
+ - **License header** — new files get the Apache 2.0 notice and `Copyright 2026 Scott Friedman` where a notice is customary (long source files, not one-line configs).
41
+ - **Python** — ≥ 3.10; `torch` ≥ 2.1; `numpy` ≥ 1.24.
42
+ - **No emoji** in source, commits, or docs unless the feature is literally about emoji.
43
+ - **Docstrings** only where they help a reader who doesn't have the context you had when writing. Don't restate the signature.
44
+ - **No throwaway files** in the repo root — work-in-progress notes belong in PR descriptions or `docs/`.
45
+
46
+ ## Commit style
47
+
48
+ Conventional-ish prefixes: `fix:`, `feat:`, `docs:`, `test:`, `bench:`, `chore:`, `refactor:`. Keep the subject line ≤ 72 characters. Longer context goes in the body.
49
+
50
+ ## Pull requests
51
+
52
+ Before opening a PR:
53
+
54
+ - [ ] `pytest tests/ -v -m "not neuron"` passes
55
+ - [ ] If you changed public API or behaviour, `CHANGELOG.md` has an `[Unreleased]` entry
56
+ - [ ] If you added a public symbol, the project's `docs/api.md` lists it
57
+ - [ ] PR description says *what* changed and *why*, not just *what*
58
+
59
+ ## Issues
60
+
61
+ Label each issue one of: `bug`, `feature`, `question`, `docs`, `infra`. Bugs include repro steps and expected-vs-actual output. Features describe the use case.
62
+
63
+ ## Code of conduct
64
+
65
+ By participating, you agree to abide by the [Contributor Covenant v2.1](CODE_OF_CONDUCT.md). Report concerns to the contact listed there.
66
+
67
+ ## License
68
+
69
+ Contributions are Apache 2.0, per the repository's [LICENSE](LICENSE). You attest you have the right to submit the code.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2026 Scott Friedman
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for describing the origin of the Work and
143
+ reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may accept support,
169
+ obligations, or other liability only on behalf of Yourself and on
170
+ Your sole responsibility, not on behalf of any other Contributor,
171
+ and only if You agree to indemnify, defend, and hold each Contributor
172
+ harmless for any liability incurred by, or claims asserted against,
173
+ such Contributor by reason of your accepting any such warranty or
174
+ additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Scott Friedman
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: trntensor
3
+ Version: 0.1.1
4
+ Summary: Tensor contractions for AWS Trainium via NKI
5
+ Author-email: Scott Friedman <3011922+scttfrdmn@users.noreply.github.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/trnsci/trntensor
8
+ Project-URL: Documentation, https://trnsci.github.io/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
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: torch>=2.1
19
+ Requires-Dist: numpy>=1.24
20
+ Provides-Extra: neuron
21
+ Requires-Dist: neuronxcc>=2.24; extra == "neuron"
22
+ Requires-Dist: torch-neuronx>=2.9; extra == "neuron"
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0; extra == "dev"
25
+ Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
26
+ Requires-Dist: scipy>=1.11; extra == "dev"
27
+ Requires-Dist: mkdocs>=1.5; extra == "dev"
28
+ Requires-Dist: mkdocs-material>=9.0; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # trntensor
32
+
33
+ [![CI](https://github.com/scttfrdmn/trntensor/actions/workflows/ci.yml/badge.svg)](https://github.com/scttfrdmn/trntensor/actions/workflows/ci.yml)
34
+ [![PyPI](https://img.shields.io/pypi/v/trntensor)](https://pypi.org/project/trntensor/)
35
+ [![Python](https://img.shields.io/pypi/pyversions/trntensor)](https://pypi.org/project/trntensor/)
36
+ [![License](https://img.shields.io/github/license/scttfrdmn/trntensor)](LICENSE)
37
+ [![Docs](https://img.shields.io/badge/docs-mkdocs-blue)](https://trnsci.github.io/trntensor/)
38
+
39
+ Tensor contractions for AWS Trainium via NKI.
40
+
41
+ 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)).
42
+
43
+ ## Install
44
+
45
+ ```bash
46
+ pip install trntensor
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ ```python
52
+ import torch
53
+ import trntensor
54
+
55
+ # Einsum — drop-in for torch.einsum with contraction planning
56
+ C = trntensor.einsum("ij,jk->ik", A, B) # matmul
57
+ T = trntensor.einsum("ap,bp->ab", B_i, B_j) # DF-MP2 contraction
58
+ X = trntensor.einsum("mi,mnP->inP", C_occ, eri) # AO→MO transform
59
+
60
+ # Contraction planning
61
+ plan = trntensor.plan_contraction("ij,jk->ik", A, B)
62
+ flops = trntensor.estimate_flops("ij,jk->ik", A, B)
63
+
64
+ # CP decomposition (tensor hypercontraction)
65
+ factors, weights = trntensor.cp_decompose(tensor, rank=10)
66
+ reconstructed = trntensor.cp_reconstruct(factors, weights)
67
+
68
+ # Tucker decomposition (HOSVD)
69
+ core, factors = trntensor.tucker_decompose(tensor, ranks=(5, 5, 5))
70
+ ```
71
+
72
+ ## Operations
73
+
74
+ | Category | Operation | Description |
75
+ |----------|-----------|-------------|
76
+ | Contraction | `einsum` | General tensor contraction |
77
+ | Contraction | `multi_einsum` | Multiple contractions (fusion-ready) |
78
+ | Planning | `plan_contraction` | Analyze and select strategy |
79
+ | Planning | `estimate_flops` | FLOPs for a contraction |
80
+ | Decomposition | `cp_decompose` | CP/PARAFAC via ALS |
81
+ | Decomposition | `tucker_decompose` | Tucker via HOSVD |
82
+
83
+ ## Status
84
+
85
+ - [x] Einsum with matmul/bmm/torch dispatch
86
+ - [x] Contraction planner
87
+ - [x] CP decomposition (ALS)
88
+ - [x] Tucker decomposition (HOSVD)
89
+ - [x] DF-MP2 einsum example
90
+ - [ ] NKI fused contraction kernels
91
+ - [ ] Multi-contraction fusion
92
+ - [ ] Optimal contraction ordering (like opt_einsum)
93
+
94
+ ## Related Projects
95
+
96
+ | Project | What |
97
+ |---------|------|
98
+ | [trnfft](https://github.com/scttfrdmn/trnfft) | FFT + complex ops |
99
+ | [trnblas](https://github.com/scttfrdmn/trnblas) | BLAS operations |
100
+ | [trnsolver](https://github.com/scttfrdmn/trnsolver) | Linear solvers |
101
+ | [trnrand](https://github.com/scttfrdmn/trnrand) | Random number generation |
102
+ | [trnsparse](https://github.com/scttfrdmn/trnsparse) | Sparse operations |
103
+
104
+ ## License
105
+
106
+ Apache 2.0 — Copyright 2026 Scott Friedman