trntensor 0.1.1__tar.gz → 0.1.2__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 (46) hide show
  1. {trntensor-0.1.1 → trntensor-0.1.2}/.github/workflows/ci.yml +2 -2
  2. trntensor-0.1.2/.github/workflows/notify-umbrella.yml +36 -0
  3. {trntensor-0.1.1 → trntensor-0.1.2}/.github/workflows/publish.yml +4 -2
  4. {trntensor-0.1.1 → trntensor-0.1.2}/CHANGELOG.md +24 -0
  5. {trntensor-0.1.1 → trntensor-0.1.2}/CODE_OF_CONDUCT.md +1 -1
  6. {trntensor-0.1.1/trntensor.egg-info → trntensor-0.1.2}/PKG-INFO +4 -3
  7. trntensor-0.1.2/benchmarks/__init__.py +0 -0
  8. trntensor-0.1.2/benchmarks/bench_einsum.py +56 -0
  9. trntensor-0.1.2/docs/benchmarks.md +38 -0
  10. {trntensor-0.1.1 → trntensor-0.1.2}/infra/terraform/main.tf +1 -1
  11. {trntensor-0.1.1 → trntensor-0.1.2}/mkdocs.yml +1 -0
  12. {trntensor-0.1.1 → trntensor-0.1.2}/pyproject.toml +4 -3
  13. {trntensor-0.1.1 → trntensor-0.1.2}/scripts/run_benchmarks.sh +1 -1
  14. trntensor-0.1.2/tests/test_nki.py +29 -0
  15. {trntensor-0.1.1 → trntensor-0.1.2}/trntensor/__init__.py +1 -1
  16. {trntensor-0.1.1 → trntensor-0.1.2}/trntensor/nki/dispatch.py +4 -0
  17. {trntensor-0.1.1 → trntensor-0.1.2/trntensor.egg-info}/PKG-INFO +4 -3
  18. {trntensor-0.1.1 → trntensor-0.1.2}/trntensor.egg-info/SOURCES.txt +5 -1
  19. trntensor-0.1.1/.github/workflows/docs.yml +0 -38
  20. {trntensor-0.1.1 → trntensor-0.1.2}/.gitignore +0 -0
  21. {trntensor-0.1.1 → trntensor-0.1.2}/CLAUDE.md +0 -0
  22. {trntensor-0.1.1 → trntensor-0.1.2}/CONTRIBUTING.md +0 -0
  23. {trntensor-0.1.1 → trntensor-0.1.2}/LICENSE +0 -0
  24. {trntensor-0.1.1 → trntensor-0.1.2}/README.md +0 -0
  25. {trntensor-0.1.1 → trntensor-0.1.2}/docs/api.md +0 -0
  26. {trntensor-0.1.1 → trntensor-0.1.2}/docs/architecture.md +0 -0
  27. {trntensor-0.1.1 → trntensor-0.1.2}/docs/aws_setup.md +0 -0
  28. {trntensor-0.1.1 → trntensor-0.1.2}/docs/index.md +0 -0
  29. {trntensor-0.1.1 → trntensor-0.1.2}/docs/installation.md +0 -0
  30. {trntensor-0.1.1 → trntensor-0.1.2}/docs/quickstart.md +0 -0
  31. {trntensor-0.1.1 → trntensor-0.1.2}/examples/df_mp2_einsum.py +0 -0
  32. {trntensor-0.1.1 → trntensor-0.1.2}/infra/terraform/README.md +0 -0
  33. {trntensor-0.1.1 → trntensor-0.1.2}/scripts/bench_to_md.py +0 -0
  34. {trntensor-0.1.1 → trntensor-0.1.2}/scripts/run_neuron_tests.sh +0 -0
  35. {trntensor-0.1.1 → trntensor-0.1.2}/setup.cfg +0 -0
  36. {trntensor-0.1.1 → trntensor-0.1.2}/tests/conftest.py +0 -0
  37. {trntensor-0.1.1 → trntensor-0.1.2}/tests/test_decompose.py +0 -0
  38. {trntensor-0.1.1 → trntensor-0.1.2}/tests/test_einsum.py +0 -0
  39. {trntensor-0.1.1 → trntensor-0.1.2}/tests/test_plan.py +0 -0
  40. {trntensor-0.1.1 → trntensor-0.1.2}/trntensor/decompose.py +0 -0
  41. {trntensor-0.1.1 → trntensor-0.1.2}/trntensor/einsum.py +0 -0
  42. {trntensor-0.1.1 → trntensor-0.1.2}/trntensor/nki/__init__.py +0 -0
  43. {trntensor-0.1.1 → trntensor-0.1.2}/trntensor/plan.py +0 -0
  44. {trntensor-0.1.1 → trntensor-0.1.2}/trntensor.egg-info/dependency_links.txt +0 -0
  45. {trntensor-0.1.1 → trntensor-0.1.2}/trntensor.egg-info/requires.txt +0 -0
  46. {trntensor-0.1.1 → trntensor-0.1.2}/trntensor.egg-info/top_level.txt +0 -0
@@ -12,8 +12,8 @@ jobs:
12
12
  matrix:
13
13
  python-version: ["3.10", "3.11", "3.12"]
14
14
  steps:
15
- - uses: actions/checkout@v4
16
- - uses: actions/setup-python@v5
15
+ - uses: actions/checkout@v6
16
+ - uses: actions/setup-python@v6
17
17
  with:
18
18
  python-version: ${{ matrix.python-version }}
19
19
  - run: pip install -e ".[dev]"
@@ -0,0 +1,36 @@
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
+ jobs:
22
+ dispatch:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - name: Trigger umbrella rebuild
26
+ env:
27
+ GH_TOKEN: ${{ secrets.TRNSCI_DISPATCH_TOKEN }}
28
+ run: |
29
+ if [ -z "${GH_TOKEN:-}" ]; then
30
+ echo "::notice::TRNSCI_DISPATCH_TOKEN not set; umbrella will pick up this change on next daily cron or manual dispatch."
31
+ exit 0
32
+ fi
33
+ gh api --method POST repos/trnsci/trnsci/dispatches \
34
+ -f event_type=subproject-updated \
35
+ -f "client_payload[repo]=${GITHUB_REPOSITORY}" \
36
+ -f "client_payload[sha]=${GITHUB_SHA}"
@@ -8,8 +8,8 @@ jobs:
8
8
  build:
9
9
  runs-on: ubuntu-latest
10
10
  steps:
11
- - uses: actions/checkout@v4
12
- - uses: actions/setup-python@v5
11
+ - uses: actions/checkout@v6
12
+ - uses: actions/setup-python@v6
13
13
  with:
14
14
  python-version: "3.12"
15
15
  - run: pip install build
@@ -22,6 +22,7 @@ jobs:
22
22
  publish-pypi:
23
23
  needs: build
24
24
  runs-on: ubuntu-latest
25
+ # Only publish stable releases (v1.2.3), not pre-releases (v1.2.3-rc1)
25
26
  if: ${{ !contains(github.event.release.tag_name, '-') }}
26
27
  environment:
27
28
  name: pypi
@@ -38,6 +39,7 @@ jobs:
38
39
  publish-testpypi:
39
40
  needs: build
40
41
  runs-on: ubuntu-latest
42
+ # Only publish pre-releases to TestPyPI
41
43
  if: ${{ contains(github.event.release.tag_name, '-') }}
42
44
  environment:
43
45
  name: testpypi
@@ -5,6 +5,30 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.2] — 2026-04-12
9
+
10
+ ### Changed
11
+
12
+ - `set_backend("nki")` now raises `RuntimeError` on non-Neuron hosts
13
+ instead of silently accepting the backend and failing later. Matches
14
+ the sibling-suite pattern.
15
+ - CI actions bumped to `actions/checkout@v6` + `actions/setup-python@v6`
16
+ (Node.js 24), ahead of GitHub's June 2026 default switch.
17
+ - pyproject metadata normalized across the trnsci suite (author email,
18
+ URLs, classifier list).
19
+ - Standalone `docs.yml` removed — docs are now served via `trnsci.dev`
20
+ through the umbrella's combined build. `notify-umbrella.yml` pings
21
+ the umbrella on docs changes.
22
+ - `infra/terraform/main.tf`: user-data clone URL corrected to
23
+ `trnsci/trntensor`.
24
+
25
+ ### Added
26
+
27
+ - `benchmarks/bench_einsum.py` — pytest-benchmark cases for einsum
28
+ dispatch and decompositions. CPU baseline numbers populated in
29
+ `docs/benchmarks.md`.
30
+ - `tests/test_nki.py` — backend-dispatch unit tests (CPU path).
31
+
8
32
  ## [0.1.1] — 2026-04-12
9
33
 
10
34
  ### Added
@@ -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
 
@@ -1,17 +1,18 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trntensor
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Tensor contractions for AWS Trainium via NKI
5
- Author-email: Scott Friedman <3011922+scttfrdmn@users.noreply.github.com>
5
+ Author-email: Scott Friedman <scttfrdmn@gmail.com>
6
6
  License-Expression: Apache-2.0
7
7
  Project-URL: Homepage, https://github.com/trnsci/trntensor
8
- Project-URL: Documentation, https://trnsci.github.io/trntensor/
8
+ Project-URL: Documentation, https://trnsci.dev/trntensor/
9
9
  Project-URL: Repository, https://github.com/trnsci/trntensor
10
10
  Project-URL: Issues, https://github.com/trnsci/trntensor/issues
11
11
  Classifier: Development Status :: 3 - Alpha
12
12
  Classifier: Intended Audience :: Science/Research
13
13
  Classifier: Programming Language :: Python :: 3
14
14
  Classifier: Topic :: Scientific/Engineering
15
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
15
16
  Requires-Python: >=3.10
16
17
  Description-Content-Type: text/markdown
17
18
  License-File: LICENSE
File without changes
@@ -0,0 +1,56 @@
1
+ """Benchmarks for einsum dispatch and decompositions.
2
+
3
+ Run with:
4
+ pytest benchmarks/ --benchmark-only
5
+
6
+ On-hardware (via SSM orchestration):
7
+ scripts/run_benchmarks.sh trn1
8
+ """
9
+
10
+ import pytest
11
+ import torch
12
+
13
+ import trntensor
14
+
15
+
16
+ @pytest.fixture(autouse=True)
17
+ def _seed():
18
+ torch.manual_seed(0)
19
+
20
+
21
+ class TestEinsumBench:
22
+
23
+ def test_matmul_512(self, benchmark):
24
+ A = torch.randn(512, 512)
25
+ B = torch.randn(512, 512)
26
+ benchmark(trntensor.einsum, "ij,jk->ik", A, B)
27
+
28
+ def test_bmm_batched(self, benchmark):
29
+ A = torch.randn(16, 256, 256)
30
+ B = torch.randn(16, 256, 256)
31
+ benchmark(trntensor.einsum, "bij,bjk->bik", A, B)
32
+
33
+ def test_df_mp2_pair(self, benchmark):
34
+ """DF-MP2 pair contraction: T_ab = Σ_P B_ia^P B_jb^P."""
35
+ nvir, naux = 48, 128
36
+ Bi = torch.randn(nvir, naux)
37
+ Bj = torch.randn(nvir, naux)
38
+ benchmark(trntensor.einsum, "ap,bp->ab", Bi, Bj)
39
+
40
+ def test_4index_transform(self, benchmark):
41
+ """AO→MO half-transform."""
42
+ nbasis, nocc, naux = 32, 8, 64
43
+ C = torch.randn(nbasis, nocc)
44
+ eri = torch.randn(nbasis, nbasis, naux)
45
+ benchmark(trntensor.einsum, "mi,mnP->inP", C, eri)
46
+
47
+
48
+ class TestDecomposeBench:
49
+
50
+ def test_cp_rank8(self, benchmark):
51
+ T = torch.randn(16, 16, 16)
52
+ benchmark(trntensor.cp_decompose, T, rank=8, max_iter=20)
53
+
54
+ def test_tucker_low_rank(self, benchmark):
55
+ T = torch.randn(16, 16, 16)
56
+ benchmark(trntensor.tucker_decompose, T, ranks=(4, 4, 4))
@@ -0,0 +1,38 @@
1
+ # Benchmarks
2
+
3
+ Performance results for trntensor — einsum dispatch, contraction planning, and CP / Tucker decompositions — comparing the PyTorch CPU fallback against the NKI Trainium path.
4
+
5
+ ## Reproducing
6
+
7
+ ```bash
8
+ # CPU baseline (local)
9
+ pytest benchmarks/bench_einsum.py --benchmark-only
10
+
11
+ # On-hardware (via SSM orchestration)
12
+ AWS_PROFILE=... ./scripts/run_benchmarks.sh trn1
13
+ ```
14
+
15
+ ## PyTorch CPU baseline
16
+
17
+ Runs on a developer laptop. Use these numbers to sanity-check relative costs of different contraction patterns — not as a ceiling for what Trainium can do.
18
+
19
+ _Platform: Darwin arm64, PyTorch CPU, median of ≥5 rounds._
20
+
21
+ | Op | Shape | Median |
22
+ |---|---|---|
23
+ | `einsum ap,bp->ab` (DF-MP2 pair) | 48×128 × 48×128 | 4.5 µs |
24
+ | `einsum mi,mnP->inP` (4-index) | 32×8, 32×32×64 | 10.5 µs |
25
+ | `einsum ij,jk->ik` | 512×512 × 512×512 | 104 µs |
26
+ | `tucker_decompose` | 16³ ranks (4,4,4) | 177 µs |
27
+ | `einsum bij,bjk->bik` | 16×256×256 | 337 µs |
28
+ | `cp_decompose` | 16³ rank 8 (20 iters) | 4.6 ms |
29
+
30
+ ## NKI (Trainium) — pending
31
+
32
+ Fused-contraction kernels are scaffolded in `trntensor/nki/dispatch.py` but not yet implemented. Tracked in [#1](https://github.com/trnsci/trntensor/issues/1). The `scripts/run_benchmarks.sh` SSM orchestration is ready to populate the NKI column once kernels land.
33
+
34
+ | Op | NKI (Trainium) | Speedup vs CPU |
35
+ |---|---|---|
36
+ | all | pending | pending |
37
+
38
+ See [AWS Setup](aws_setup.md) for the on-hardware CI flow.
@@ -119,7 +119,7 @@ resource "aws_instance" "ci" {
119
119
  #!/bin/bash
120
120
  set -euxo pipefail
121
121
  cd /home/ubuntu
122
- sudo -u ubuntu git clone https://github.com/scttfrdmn/trntensor.git trntensor
122
+ sudo -u ubuntu git clone https://github.com/trnsci/trntensor.git trntensor
123
123
  # Install into the AMI's pre-built Neuron venv (has neuronxcc preinstalled).
124
124
  # Use [dev] only — [neuron] would try to fetch neuronxcc from PyPI where it doesn't exist.
125
125
  NEURON_VENV=$(ls -d /opt/aws_neuronx_venv_pytorch_* | head -1)
@@ -22,6 +22,7 @@ nav:
22
22
  - Quickstart: quickstart.md
23
23
  - API Reference: api.md
24
24
  - Architecture: architecture.md
25
+ - Benchmarks: benchmarks.md
25
26
  - Deployment:
26
27
  - AWS Setup for Neuron CI: aws_setup.md
27
28
 
@@ -4,19 +4,20 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "trntensor"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Tensor contractions for AWS Trainium via NKI"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
11
11
  requires-python = ">=3.10"
12
12
  authors = [
13
- { name = "Scott Friedman", email = "3011922+scttfrdmn@users.noreply.github.com" },
13
+ { name = "Scott Friedman", email = "scttfrdmn@gmail.com" },
14
14
  ]
15
15
  classifiers = [
16
16
  "Development Status :: 3 - Alpha",
17
17
  "Intended Audience :: Science/Research",
18
18
  "Programming Language :: Python :: 3",
19
19
  "Topic :: Scientific/Engineering",
20
+ "Topic :: Scientific/Engineering :: Mathematics",
20
21
  ]
21
22
  dependencies = [
22
23
  "torch>=2.1",
@@ -40,7 +41,7 @@ dev = [
40
41
 
41
42
  [project.urls]
42
43
  Homepage = "https://github.com/trnsci/trntensor"
43
- Documentation = "https://trnsci.github.io/trntensor/"
44
+ Documentation = "https://trnsci.dev/trntensor/"
44
45
  Repository = "https://github.com/trnsci/trntensor"
45
46
  Issues = "https://github.com/trnsci/trntensor/issues"
46
47
 
@@ -81,7 +81,7 @@ BENCH_SCRIPT="source /opt/aws_neuronx_venv_pytorch_2_9/bin/activate && \
81
81
  git fetch --all && \
82
82
  git checkout $SHA && \
83
83
  pip install -e '.[dev]' --quiet && \
84
- pytest benchmarks/bench_rand.py --benchmark-only --benchmark-json=$REMOTE_JSON --tb=short 2>&1 | tail -120 && \
84
+ pytest benchmarks/ --benchmark-only --benchmark-json=$REMOTE_JSON --tb=short 2>&1 | tail -120 && \
85
85
  echo BENCH_OK"
86
86
 
87
87
  CMD_ID=$(aws ssm send-command \
@@ -0,0 +1,29 @@
1
+ """Backend dispatch tests (CPU path)."""
2
+
3
+ import pytest
4
+ import trntensor
5
+ from trntensor.nki.dispatch import HAS_NKI
6
+
7
+
8
+ def test_set_backend_auto():
9
+ trntensor.set_backend("auto")
10
+ assert trntensor.get_backend() == "auto"
11
+
12
+
13
+ def test_set_backend_pytorch():
14
+ trntensor.set_backend("pytorch")
15
+ assert trntensor.get_backend() == "pytorch"
16
+ trntensor.set_backend("auto")
17
+
18
+
19
+ def test_set_backend_invalid():
20
+ with pytest.raises(AssertionError):
21
+ trntensor.set_backend("tpu")
22
+
23
+
24
+ @pytest.mark.skipif(HAS_NKI, reason="Test asserts the no-NKI guard")
25
+ def test_set_backend_nki_raises_without_neuronxcc():
26
+ with pytest.raises(RuntimeError, match="neuronxcc"):
27
+ trntensor.set_backend("nki")
28
+ # State should not have changed
29
+ assert trntensor.get_backend() != "nki"
@@ -5,7 +5,7 @@ Einstein summation, contraction planning, and tensor decompositions
5
5
  for scientific computing. Part of the trnsci scientific computing suite.
6
6
  """
7
7
 
8
- __version__ = "0.1.1"
8
+ __version__ = "0.1.2"
9
9
 
10
10
  from .einsum import einsum, multi_einsum
11
11
  from .plan import ContractionPlan, plan_contraction, estimate_flops
@@ -25,6 +25,10 @@ _backend = "auto"
25
25
  def set_backend(backend: str):
26
26
  global _backend
27
27
  assert backend in ("auto", "pytorch", "nki")
28
+ if backend == "nki" and not HAS_NKI:
29
+ raise RuntimeError(
30
+ "NKI backend requires neuronxcc. Install with: pip install 'trntensor[neuron]'"
31
+ )
28
32
  _backend = backend
29
33
 
30
34
  def get_backend() -> str:
@@ -1,17 +1,18 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trntensor
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Tensor contractions for AWS Trainium via NKI
5
- Author-email: Scott Friedman <3011922+scttfrdmn@users.noreply.github.com>
5
+ Author-email: Scott Friedman <scttfrdmn@gmail.com>
6
6
  License-Expression: Apache-2.0
7
7
  Project-URL: Homepage, https://github.com/trnsci/trntensor
8
- Project-URL: Documentation, https://trnsci.github.io/trntensor/
8
+ Project-URL: Documentation, https://trnsci.dev/trntensor/
9
9
  Project-URL: Repository, https://github.com/trnsci/trntensor
10
10
  Project-URL: Issues, https://github.com/trnsci/trntensor/issues
11
11
  Classifier: Development Status :: 3 - Alpha
12
12
  Classifier: Intended Audience :: Science/Research
13
13
  Classifier: Programming Language :: Python :: 3
14
14
  Classifier: Topic :: Scientific/Engineering
15
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
15
16
  Requires-Python: >=3.10
16
17
  Description-Content-Type: text/markdown
17
18
  License-File: LICENSE
@@ -8,11 +8,14 @@ README.md
8
8
  mkdocs.yml
9
9
  pyproject.toml
10
10
  .github/workflows/ci.yml
11
- .github/workflows/docs.yml
11
+ .github/workflows/notify-umbrella.yml
12
12
  .github/workflows/publish.yml
13
+ benchmarks/__init__.py
14
+ benchmarks/bench_einsum.py
13
15
  docs/api.md
14
16
  docs/architecture.md
15
17
  docs/aws_setup.md
18
+ docs/benchmarks.md
16
19
  docs/index.md
17
20
  docs/installation.md
18
21
  docs/quickstart.md
@@ -25,6 +28,7 @@ scripts/run_neuron_tests.sh
25
28
  tests/conftest.py
26
29
  tests/test_decompose.py
27
30
  tests/test_einsum.py
31
+ tests/test_nki.py
28
32
  tests/test_plan.py
29
33
  trntensor/__init__.py
30
34
  trntensor/decompose.py
@@ -1,38 +0,0 @@
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes