trntensor 0.22.0__tar.gz → 0.24.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 (91) hide show
  1. {trntensor-0.22.0 → trntensor-0.24.0}/CHANGELOG.md +349 -0
  2. {trntensor-0.22.0 → trntensor-0.24.0}/CLAUDE.md +7 -3
  3. {trntensor-0.22.0/trntensor.egg-info → trntensor-0.24.0}/PKG-INFO +46 -12
  4. {trntensor-0.22.0 → trntensor-0.24.0}/README.md +45 -11
  5. {trntensor-0.22.0 → trntensor-0.24.0}/docs/api/einsum.md +27 -14
  6. {trntensor-0.22.0 → trntensor-0.24.0}/docs/api/nki.md +77 -11
  7. {trntensor-0.22.0 → trntensor-0.24.0}/docs/api/plan.md +12 -6
  8. {trntensor-0.22.0 → trntensor-0.24.0}/docs/api/quantum.md +36 -7
  9. trntensor-0.24.0/docs/api/stream.md +63 -0
  10. {trntensor-0.22.0 → trntensor-0.24.0}/docs/architecture.md +24 -12
  11. {trntensor-0.22.0 → trntensor-0.24.0}/docs/benchmarks.md +15 -3
  12. {trntensor-0.22.0 → trntensor-0.24.0}/docs/contraction_patterns.md +27 -17
  13. trntensor-0.24.0/docs/index.md +41 -0
  14. trntensor-0.24.0/docs/installation.md +26 -0
  15. {trntensor-0.22.0 → trntensor-0.24.0}/docs/quickstart.md +12 -8
  16. {trntensor-0.22.0 → trntensor-0.24.0}/docs/tutorial_df_mp2.md +30 -28
  17. {trntensor-0.22.0 → trntensor-0.24.0}/mkdocs.yml +1 -0
  18. {trntensor-0.22.0 → trntensor-0.24.0}/pyproject.toml +1 -1
  19. trntensor-0.24.0/scripts/bench_ao2mo_nocc.py +173 -0
  20. trntensor-0.24.0/scripts/bench_eager_handle.py +129 -0
  21. trntensor-0.24.0/tests/conftest.py +81 -0
  22. trntensor-0.24.0/tests/test_conformance.py +1191 -0
  23. trntensor-0.24.0/tests/test_decompose.py +430 -0
  24. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_einsum.py +256 -2
  25. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_host_output.py +2 -2
  26. trntensor-0.24.0/tests/test_kernel_dtype_guard.py +1171 -0
  27. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_native_dispatch.py +522 -6
  28. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_nki_compile.py +28 -0
  29. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_nki_native.py +106 -2
  30. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_nki_sim.py +27 -0
  31. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_plan.py +72 -0
  32. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_quantum.py +90 -0
  33. trntensor-0.24.0/tests/test_stream.py +211 -0
  34. trntensor-0.24.0/tests/test_trace_cache_safety.py +563 -0
  35. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/__init__.py +15 -1
  36. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/decompose.py +63 -14
  37. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/einsum.py +140 -14
  38. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/nki/_kernels.py +89 -28
  39. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/nki/_native.py +18 -1
  40. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/nki/collectives.py +5 -0
  41. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/nki/dispatch.py +742 -34
  42. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/parallel.py +13 -0
  43. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/plan.py +22 -8
  44. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/quantum.py +133 -22
  45. trntensor-0.24.0/trntensor/stream.py +552 -0
  46. {trntensor-0.22.0 → trntensor-0.24.0/trntensor.egg-info}/PKG-INFO +46 -12
  47. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor.egg-info/SOURCES.txt +8 -0
  48. trntensor-0.22.0/docs/index.md +0 -35
  49. trntensor-0.22.0/docs/installation.md +0 -21
  50. trntensor-0.22.0/tests/conftest.py +0 -49
  51. trntensor-0.22.0/tests/test_decompose.py +0 -219
  52. {trntensor-0.22.0 → trntensor-0.24.0}/.github/workflows/ci.yml +0 -0
  53. {trntensor-0.22.0 → trntensor-0.24.0}/.github/workflows/notify-umbrella.yml +0 -0
  54. {trntensor-0.22.0 → trntensor-0.24.0}/.github/workflows/publish.yml +0 -0
  55. {trntensor-0.22.0 → trntensor-0.24.0}/.gitignore +0 -0
  56. {trntensor-0.22.0 → trntensor-0.24.0}/.pre-commit-config.yaml +0 -0
  57. {trntensor-0.22.0 → trntensor-0.24.0}/CODE_OF_CONDUCT.md +0 -0
  58. {trntensor-0.22.0 → trntensor-0.24.0}/CONTRIBUTING.md +0 -0
  59. {trntensor-0.22.0 → trntensor-0.24.0}/LICENSE +0 -0
  60. {trntensor-0.22.0 → trntensor-0.24.0}/benchmarks/__init__.py +0 -0
  61. {trntensor-0.22.0 → trntensor-0.24.0}/benchmarks/bench_einsum.py +0 -0
  62. {trntensor-0.22.0 → trntensor-0.24.0}/docs/api/decompose.md +0 -0
  63. {trntensor-0.22.0 → trntensor-0.24.0}/docs/api/index.md +0 -0
  64. {trntensor-0.22.0 → trntensor-0.24.0}/docs/aws_setup.md +0 -0
  65. {trntensor-0.22.0 → trntensor-0.24.0}/docs/design/matmul_dispatch_findings.md +0 -0
  66. {trntensor-0.22.0 → trntensor-0.24.0}/docs/design/matmul_kernel_profile.md +0 -0
  67. {trntensor-0.22.0 → trntensor-0.24.0}/docs/developing_kernels.md +0 -0
  68. {trntensor-0.22.0 → trntensor-0.24.0}/examples/df_mp2_einsum.py +0 -0
  69. {trntensor-0.22.0 → trntensor-0.24.0}/infra/terraform/README.md +0 -0
  70. {trntensor-0.22.0 → trntensor-0.24.0}/infra/terraform/main.tf +0 -0
  71. {trntensor-0.22.0 → trntensor-0.24.0}/scripts/autotune_dispatch.py +0 -0
  72. {trntensor-0.22.0 → trntensor-0.24.0}/scripts/bench_native_einsum.py +0 -0
  73. {trntensor-0.22.0 → trntensor-0.24.0}/scripts/bench_native_kernels.py +0 -0
  74. {trntensor-0.22.0 → trntensor-0.24.0}/scripts/bench_to_md.py +0 -0
  75. {trntensor-0.22.0 → trntensor-0.24.0}/scripts/run_benchmarks.sh +0 -0
  76. {trntensor-0.22.0 → trntensor-0.24.0}/scripts/run_neuron_profile.sh +0 -0
  77. {trntensor-0.22.0 → trntensor-0.24.0}/scripts/run_neuron_tests.sh +0 -0
  78. {trntensor-0.22.0 → trntensor-0.24.0}/scripts/run_reduce_parallel_multirank.py +0 -0
  79. {trntensor-0.22.0 → trntensor-0.24.0}/scripts/run_simulator_tests.sh +0 -0
  80. {trntensor-0.22.0 → trntensor-0.24.0}/setup.cfg +0 -0
  81. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_nki.py +0 -0
  82. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_nki_kernels.py +0 -0
  83. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_nki_tail_audit.py +0 -0
  84. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_parallel.py +0 -0
  85. {trntensor-0.22.0 → trntensor-0.24.0}/tests/test_sr_runtime.py +0 -0
  86. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/nki/__init__.py +0 -0
  87. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor/py.typed +0 -0
  88. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor.egg-info/dependency_links.txt +0 -0
  89. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor.egg-info/requires.txt +0 -0
  90. {trntensor-0.22.0 → trntensor-0.24.0}/trntensor.egg-info/top_level.txt +0 -0
  91. {trntensor-0.22.0 → trntensor-0.24.0}/uv.lock +0 -0
@@ -7,6 +7,355 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.24.0] — 2026-11-04
11
+
12
+ Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
13
+
14
+ Headline: trntensor.stream.AuxStream for DF integrals streamed over the aux index (#102), cached eager NKI handles, and the trnsci float64 policy with a dtype guard at the kernel boundary.
15
+
16
+ ### Fixed
17
+
18
+ - **`mp2_energy`'s aten route chunks j as well as i (trnsci/trnsci#115).** It
19
+ chunked only the occupied index i. Once one i row of `T` (`nocc · nvir²`)
20
+ exceeded `_MP2_CHUNK_ELEMS`, every step held that whole row, 1.37 GB at
21
+ nocc 161 / nvir 1461 / naux 6064 (C40H82 / aug-cc-pVDZ), plus its temporaries.
22
+ On a 24 GiB Trn2 core, with only the 5.7 GB of `B` resident, the step ran out
23
+ of device memory. Blocks are now at most `_MP2_CHUNK_ELEMS` elements, and the
24
+ same case ran on one core in 222 s.
25
+ ### Changed
26
+
27
+ - **`AuxStream` uploads a memory-mapped chunk to a device straight from the
28
+ mapping (trnsci/trnsci#115).** The sequential read into RAM, added so that
29
+ host row gathers stop faulting pages at random, now runs only for chunks
30
+ computed on the host. On Trn2, a page-cached 1.6 GB chunk went from 2.9 GB/s
31
+ (copy, then upload) to 12–14 GB/s (upload from the mapping). For water61 /
32
+ aug-cc-pVDZ (114.6 GB of B, 49.7 GB streamed per SCF iteration over 4
33
+ cores), the per-iteration upload wait went from 12.5 s to 4.3 s.
34
+ ### Performance
35
+
36
+ - **Eager NKI kernel calls skip the per-call handle rebuild and the custom-op
37
+ layer (same fix as trnblas#92).** On the native path a `trntensor::`
38
+ custom-op call cost about 0.1 ms of host time before the kernel was queued,
39
+ against 0.016 ms for aten. Most of it went to nki's `Kernel.__call__`,
40
+ which rebuilds the torch handle on every call, plus the `torch.library`
41
+ layer. `dispatch._launch` and the `mp2_energy_row` loop now call a
42
+ `torch_neuronx.wrap_nki` handle built once per kernel; compile-time keyword
43
+ arguments (`use_sr`, `nub`, `tp`, `tail`, `banks`) pass through unchanged.
44
+ On trn2 (LNC=2), a 256x128x512 `matmul` launch drops from 0.143 to
45
+ 0.036 ms of issue time (e2e 0.222 to 0.128 ms), `_nki_mp2_energy_rows` with
46
+ nocc=8 from 2.94 to 2.34 ms, and the `df_exchange` kernel pair's issue time
47
+ from 0.78 to 0.36 ms. Results are bit-identical. `torch.compile`,
48
+ requires-grad, int64 and tensor-subclass inputs keep the custom op.
49
+ `TRNTENSOR_NKI_EAGER_HANDLE=0` turns this off;
50
+ `scripts/bench_eager_handle.py` measures it.
51
+
52
+ ### Added
53
+
54
+ - **`trntensor.stream`: DF integrals streamed over the aux index**
55
+ (trnsolver#15). At nbasis 1658 the packed fp32 integrals were 33.4 GB and
56
+ only fit split over a Trn2 chip's 4 logical cores; at nbasis ≈ 3300 they
57
+ are about 270 GB.
58
+ - `AuxStream(chunks, nbasis, devices=..., resident_bytes=..., prefetch=...)`
59
+ holds `B` as `(npair, nq)` aux chunks (tensors, numpy memmaps or lazy
60
+ loaders), keeps chunks resident up to a per-device budget and uploads the
61
+ rest on every call from a loader thread, one chunk ahead per device, so
62
+ uploads overlap compute. `jk()` builds packed J and K in one pass
63
+ (`df_coulomb` / `df_exchange` per chunk, summed per device, then on the
64
+ host); `ao_to_mo()` writes `B_ia^P` chunk by chunk into a host tensor or
65
+ memmap. Chunks are dealt round-robin over `devices` (`neuron:0..3`).
66
+ - `aux_chunk_width` / `split_aux`: 128-multiple chunks under 2 GiB by
67
+ default, below the 4 GiB transposed-LHS limit (aws-neuron-sdk#1457, #97).
68
+ - `pack_density` / `unpack_packed`: the packed-density helpers, for use on
69
+ host tensors at large nbasis (the device gathers compile for > 40 min at
70
+ nbasis 1658, trnsolver#87).
71
+ - `mp2_energy_blocked`: DF-MP2 over occupied blocks of a host `B_ia^P`,
72
+ for `B` larger than one device.
73
+ - Memory-mapped chunks are read into RAM with one sequential read when
74
+ loaded. Left mapped, the row gathers of `df_exchange` fault pages in at
75
+ random, which was disk-bound on a disk-backed store.
76
+ - CPU-validated against dense references; device overlap and scaling are
77
+ still to be measured.
78
+
79
+ ### Changed
80
+
81
+ - **float64 follows the trnsci float64 policy (#92, trnsci/trnsci#35).**
82
+ Trainium computes float64 at fp32 precision, so a float64 operand on a
83
+ kernel route cannot get float64 accuracy there. This applies to the matmul /
84
+ batched-matmul kernels (`einsum`, `multi_einsum`) and to the chemistry
85
+ kernels (`mp2_energy`, `ao_to_mo_transform`, `df_exchange`, `df_coulomb`):
86
+ - **`"auto"`:** float64 under `auto` now computes in torch at float64
87
+ accuracy (previously cast to fp32 on the NKI path). For the chemistry
88
+ kernels the cast came in with #88 and was in 0.23.0. Through 0.22.0
89
+ float64 reached them unchanged and returned inf. torch runs on the
90
+ operands' own device; float64 host operands stay on the host.
91
+ - **Explicit `set_backend("nki")` (or `TRNTENSOR_FORCE_BACKEND=nki`):**
92
+ float64 is cast to fp32, the kernel runs, and the result comes back as
93
+ float64. A one-time `UserWarning` per op says the precision is fp32.
94
+ Through 0.23.0 the chemistry kernels cast without a warning; the matmul
95
+ kernels got float64 operands unchanged.
96
+ - **`TRNTENSOR_REQUIRE_NKI=1`:** float64 on a kernel route raises
97
+ `NotImplementedError` (trnblas#69's convention), under explicit `"nki"`
98
+ and `"auto"` alike. **Callers who ran float64 chemistry inputs under
99
+ `TRNTENSOR_REQUIRE_NKI=1` (0.23.0: the kernel ran in fp32) now get an
100
+ error.** Pass float32 operands to run the kernels, or unset the variable.
101
+ - **Result dtype:** always the pytorch backend's dtype for the same inputs,
102
+ including bf16 / fp16 and mixed-dtype promotion (`torch.promote_types`
103
+ of the operands).
104
+
105
+ - **float64 already on the `neuron` device:** under `"auto"`, "torch on
106
+ the operands' device" would be device aten, which computes float64 at
107
+ fp32 precision (measured on Trn2). float64 / complex128 operands on the
108
+ `neuron` device are now copied to the host, computed in host torch at
109
+ float64 accuracy, and the result is returned on the original device in
110
+ float64 / complex128. This covers `einsum`, `multi_einsum` (which returns
111
+ host tensors, as before), `gather` (device `torch.cat` rounds float64 to
112
+ fp32), `einsum(dtype=float64)` on fp32 / bf16 device operands, the
113
+ chemistry calls and the CP / Tucker / TT
114
+ decompositions and reconstructions. One `UserWarning` per op per process:
115
+ "float64 on the neuron device is computed on the host for float64
116
+ accuracy (device arithmetic is fp32); pass float32 to stay on device".
117
+ **New: `TRNTENSOR_FP64_ON_DEVICE=1`** keeps device aten (fp32 precision,
118
+ no warning) for callers who prefer speed. **Under
119
+ `TRNTENSOR_REQUIRE_NKI=1`, float64 / complex128 on the `neuron` device
120
+ now raises `NotImplementedError` at every guarded entry point** (backends
121
+ `"auto"` and `"nki"`, no host copy, ahead of `TRNTENSOR_FP64_ON_DEVICE`);
122
+ before, only the kernel routes raised, and an `einsum` with no kernel
123
+ route (below the size thresholds, or not a matmul) or a decomposition
124
+ ran device aten at fp32 precision with no error. Host-resident float64 is
125
+ unchanged, and `multi_einsum` no longer pins host float64 / complex128
126
+ operands to the device under `"auto"`; through 0.23.0 shared operands
127
+ were pinned, so device aten computed them at fp32 precision.
128
+ `--backend auto --conformance-device neuron` now holds float64 and
129
+ complex128 to the float64 tolerance.
130
+ The routes that place their own compute follow the same rule:
131
+ `trntensor.stream.AuxStream(..., dtype=float64)` and
132
+ `mp2_energy_blocked` with a `neuron` device in `devices` keep the chunks
133
+ and the arithmetic on the host (results still default to the first
134
+ device given), and `pack_tril` / `unpack_tril` / `pack_density` /
135
+ `unpack_packed` gather float64 / complex128 on the host, because on the
136
+ neuron device both the gather (`index_select`, fancy indexing) and
137
+ `torch.cat` round float64 to fp32 (measured on Trn2, rel err ~4e-8).
138
+
139
+ Affected versions: the old behaviour is 0.23.0 for the chemistry kernels
140
+ (the silent fp32 cast) and 0.23.0 and earlier for the matmul kernels
141
+ (float64 unchanged). The new behaviour lands in the next release (0.24.0).
142
+ Docs: "Precision and dtypes" in `docs/api/nki.md`.
143
+ `tests/test_conformance.py` now holds float64 to the float64 tolerance
144
+ for host inputs under `--backend auto`, as under `pytorch`.
145
+
146
+ ### Fixed
147
+
148
+ - **One dtype guard at the NKI kernel boundary: float64, integer, bool and
149
+ complex operands no longer reach a kernel that does not take them**
150
+ (silent, trnsci/trnsci#35; the class of #87). `nki.dispatch` now has a
151
+ per-kernel operand-dtype table (`KERNEL_OPERAND_DTYPES`). Every launch
152
+ checks it and raises `TypeError` if a dtype is not listed: the native op
153
+ and the eager-handle fast path (`_native_call`), the XLA call, the
154
+ simulator, the `mp2_energy` row loop and the reduce-parallel all-reduce. A native op without an entry cannot be loaded.
155
+ The host wrappers decide first:
156
+ - `einsum` / `multi_einsum` (matmul and batched-matmul kernels; fp32, bf16,
157
+ fp16, one shared dtype): integer, bool, complex and mixed dtypes run
158
+ torch, as the pytorch backend does; float64 follows the policy above.
159
+ Through 0.23.0 they reached the kernels under `set_backend("nki")`, or
160
+ under `"auto"` above the size thresholds.
161
+ - `mp2_energy`, `ao_to_mo_transform` (fp32 / bf16 kernels) and
162
+ `df_exchange`, `df_coulomb` (fp32 kernels): float16 operands, and
163
+ bfloat16 operands of `df_*`, are computed in fp32 (a lossless upcast).
164
+ The result is returned in the aten route's dtype. float64 follows the
165
+ policy above. Integer, bool and complex operands take aten. On the kernel
166
+ route, bf16 `df_coulomb` raised in the host tail whenever `npair` was not
167
+ a multiple of 256, then fell back to aten. Re-allowing bf16 on the `df_*`
168
+ kernels waits on a Trn2 bf16 run (#92).
169
+ - reduce-parallel all-reduce: partials other than fp32 / bf16 / fp16 are
170
+ summed by `torch.distributed` instead of the NKI collective kernel.
171
+ float64 partials are summed there at full precision.
172
+ - Under `TRNTENSOR_REQUIRE_NKI=1`, a dtype that would run torch instead of
173
+ the kernel raises `NotImplementedError` (trnblas's convention).
174
+ The `df_half_packed` op's fake (meta) output is now float32, like the
175
+ kernel's. Test: `tests/test_kernel_dtype_guard.py`.
176
+
177
+ - **`unpack_tril` / `pack_tril` on the neuron device at LNC=1 returned
178
+ wrong data once the gathered output reached 4 GiB (#97).** Affected
179
+ 0.20.0–0.23.0: `unpack_tril`, `pack_tril`, and the packed-`eri` aten /
180
+ legacy routes of `ao_to_mo_transform`, which unpack with `unpack_tril`: on
181
+ the neuron device at LNC=1, one `index_select` along dim 0 whose output
182
+ reaches 2^32 bytes can be silently wrong (about half the elements, at
183
+ times NaN) or hit the runtime's 30 s execution timeout. Measured on Trn2:
184
+ exact at 2^32 − 16 KiB, wrong at exactly 2^32, and 154 M mismatched
185
+ elements for `unpack_tril` at nbasis 736 / naux 2304 (4.99e9 bytes). It
186
+ is exact at LNC=2 and on the host. Device gathers are now split into row blocks of at most
187
+ 2 GiB of output and concatenated in order (exact). Host gathers are one
188
+ `index_select` as before.
189
+ - **Complex `tucker_decompose` on the neuron device used `U^T`, not `U^H`
190
+ (#89).** Affected 0.23.0 (the release that switched the core to
191
+ `factors[mode].mH`, #73): `.mH` of a complex tensor is a lazy conj view,
192
+ and device matmul ignores the conj bit (aws-neuron/aws-neuron-sdk#1455),
193
+ so the core of a device-resident complex tensor was silently computed
194
+ with the unconjugated factors. CPU results were correct. The conjugate
195
+ transpose is now materialized with `resolve_conj()` before the mode
196
+ product, as trnsolver's `factor._mH` does; real input is unchanged (no
197
+ copy). The complex `cp_decompose` added in this release (#103) had the
198
+ same pattern (`V.mH @ V`, `T_mode @ V.conj()`) and is fixed the same way.
199
+ A CPU `TorchFunctionMode` test fails if any lazy conj view reaches a
200
+ matmul, einsum, solve or pinv in either decomposition.
201
+
202
+ - **`cp_decompose` works in the input dtype, including float64 and complex
203
+ (#103).** Affected 0.1.1–0.23.0: the random init and the Khatri-Rao buffer
204
+ were float32 on the host, so float64 or complex input raised `expected m1
205
+ and m2 to have the same dtype` on every backend (and a float64 warm start
206
+ was truncated to float32 inside the Khatri-Rao product). The init, the
207
+ Khatri-Rao buffer and the weights now follow `tensor.dtype` and
208
+ `tensor.device`, warm-start factors are cast to them, and complex input
209
+ uses the conjugated normal equations `(V^H V) A^T = (T_(k) conj(V))^T`.
210
+ Weights are real (`tensor.real.dtype`). `nonneg=True` with complex input
211
+ raises `ValueError`. Real float32 results are bit-identical.
212
+ - **`cp_reconstruct` returns the factors' dtype on the factors' device
213
+ (#78).** Affected 0.1.1–0.23.0: it accumulated into a float32 host buffer
214
+ (`torch.zeros(shape)`), so bf16 or fp16 factors came back as float32 and
215
+ device factors raised a device mismatch. The buffer now has the promoted
216
+ dtype of `factors` and `weights` and the factors' device. float32 and
217
+ float64 results are unchanged.
218
+ - **`plan_contraction` fills `ContractionPlan.estimated_flops` (#83).**
219
+ Affected 0.1.1–0.23.0: the documented multiply-add estimate was never set
220
+ and always read 0. `matmul`, `bmm` and `torch` plans now carry
221
+ `estimate_flops(subscripts, *operands)` (the product of all index sizes);
222
+ `path` plans carry the multiply-adds of the planned binary steps, which is
223
+ what runs and is less than the dense all-index product. Plans are cached by
224
+ shape, so the field is exact for the cached shapes.
225
+ - **`einsum(..., out=)` now writes the result into `out` and returns it
226
+ (#77).** Affected 0.3.0–0.23.0: `out` was only read as the `beta` addend
227
+ and never written, so the documented in-place accumulation example
228
+ `einsum(..., beta=1.0, out=acc)` silently left `acc` unchanged. `out` now
229
+ behaves as in `torch.einsum` and cuTENSOR: it receives
230
+ `alpha * contract + beta * out` (old contents not read when `beta == 0`),
231
+ must have the result's shape (`ValueError` otherwise), must accept the
232
+ result dtype under `torch.can_cast` (`RuntimeError` otherwise), and may
233
+ alias an operand. Like `torch.einsum(out=)`, it raises `RuntimeError` when
234
+ grad mode is on and an operand or `out` requires grad. Callers that reused
235
+ `C` after passing it as `out=C` now see it overwritten; pass `out=C.clone()`
236
+ to keep the old behaviour.
237
+
238
+ ## [0.23.0] — 2026-11-02
239
+
240
+ Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
241
+
242
+ Headline: **correctness fixes — upgrade recommended.** `kahan`/`dd` dropped the imaginary part of complex operands and rounded large integers (#69, #90); `beta=0` read `out=` (#71); complex `tucker_decompose` used Uᵀ (#73); `multi_einsum` returned fp32 results as fp64 (#75); `einsum(precision="dd")` missed its documented bound (#84); float64 chemistry kernels returned inf on device (#87); `ao_to_mo_transform` on device with operands over 4 GiB was silently wrong and is now guarded (#97). New: native AO→MO for any nocc, 1.8–3.5× faster than aten at nocc 160–384 (#94).
243
+
244
+ ### Changed
245
+
246
+ - **`ao_to_mo_transform`'s Trn2 kernels now run any `nocc` (#80).** They
247
+ needed `nocc ≤ 128`, so larger systems fell back to aten under `"auto"`.
248
+ - Stage 1 runs occupied blocks of ≤ 128 over each eri block, so `eri` is
249
+ read once whatever `nocc` is. `C_occ` and `C_vir` stay resident in SBUF.
250
+ - Both stages move 512 columns per Tensor Engine pass (`512 // TP` ν in
251
+ stage 1, `512 // TP` orbitals in stage 2), and stage 2 fetches and
252
+ stores each group with one strided DMA.
253
+ - With an odd aux-chunk count and `nocc > 128`, the two programs of an
254
+ LNC=2 core split the occupied index instead of the aux chunks (the
255
+ dispatcher appends one zero orbital when `nocc` is odd), so both
256
+ physical cores still work.
257
+ - The packed kernel gets the same treatment and keeps its in-place gather.
258
+ - Trn2, LNC=2, fp32, warm: at nbasis 512 / naux 1536 the kernel is
259
+ 1.8–2.4× faster than aten at nocc 160–384 (full `eri`) and 2.7–3.5×
260
+ with packed `eri`. It is 1.3–1.7× faster than launching the old kernel
261
+ once per 128 orbitals. At LNC=1 it is 1.3–1.7× (full) and 2.3–2.6×
262
+ (packed) faster than aten. Tables on #80.
263
+ - At `nocc ≤ 128` it is 0.99–1.08× the speed of `main` (the 512-column
264
+ passes), and the first-call compile is shorter.
265
+ - With an odd aux-chunk count and `nocc > 128` the occupied split is
266
+ 1.3–1.6× faster than one program (e.g. 512/257/1152: 17.8 → 11.7 ms).
267
+ - **`"auto"` routing for `ao_to_mo_transform` (#80).**
268
+ - The `nocc ≤ 128` condition is gone.
269
+ - A full `eri` whose nbasis or naux is not a 128 multiple now stays on
270
+ aten. The kernel pads a copy of the whole square first, and that copy
271
+ costs more than aten (300/100/700: 5.6 ms against 2.0 ms). This also
272
+ changes routing at `nocc ≤ 128`. Pass packed `eri` to keep the kernel:
273
+ it pads nbasis only in its gather indices.
274
+ - A packed `eri` with a padded nbasis needs 2e9 multiply-adds of stage-1
275
+ work instead of 5e8.
276
+ - The kernel's SBUF budget goes from 144 to 176 KiB (df_exchange's). At
277
+ n_ao 970, nocc 161, packed naux 4608 it needs 158 KiB and runs in
278
+ 118 ms on Trn2 (LNC=2); aten ran out of device memory there.
279
+
280
+ ### Added
281
+
282
+ - **Guard against the NKI trace-cache closure bug ([aws-neuron/aws-neuron-sdk#1454](https://github.com/aws-neuron/aws-neuron-sdk/issues/1454),
283
+ trnsci/trnsci#35).** `tests/test_trace_cache_safety.py` (CPU) finds every
284
+ `@nki.jit` kernel and fails if its body, or a helper it calls, reads a
285
+ closure variable or a module global that is not a constant expression
286
+ (reviewed exceptions are allow-listed with a reason), and checks each
287
+ kernel's `__closure__` at runtime against a stub `nki`.
288
+ - Tests: `conftest.py` no longer turns the NKI trace cache off. Neuron tests
289
+ run with it on, as under `import torch_neuronx`, with a fresh
290
+ `NKI_TRACE_CACHE_URL` directory per session (no stale editable-install
291
+ traces). `NKI_ENABLE_TRACE_CACHE=0` still turns it off.
292
+ - README: known platform issue note for #1454.
293
+
294
+ ### Fixed
295
+
296
+ - **`ao_to_mo_transform` aten route on the device: wrong results from 4 GiB of
297
+ `eri` (#97).** On TorchNeuron (torch-neuronx 2.14.3), a matmul whose left
298
+ operand is a transposed view returns wrong values, without an error, once the
299
+ right operand exceeds 2^32 bytes and the contraction dim is a multiple of 128.
300
+ If the right operand came straight from the host it aborts instead
301
+ (aws-neuron/aws-neuron-sdk#1448). Both `torch.einsum` steps of the aten route
302
+ lower to that matmul, so at nbasis 768 / naux 2304 the result was off by
303
+ about 1 relative. On the device, from 2^32 bytes of `eri` or of the
304
+ half-transformed tensor, the two steps now run as `mm` and `bmm` with
305
+ contiguous orbital transposes. At 768/64/2304 the error against float64 is
306
+ 2.2e-7 (was 1.06), and a warm call takes 16.1 ms (the wrong route took
307
+ 25 ms). Not fixed here: at LNC=1, the device `index_select` that builds a
308
+ square `eri` over 4 GiB is itself wrong (it unpacks packed input for the aten
309
+ route), so that case still returns wrong values or NaN (#97).
310
+
311
+ - **`einsum(precision="kahan")` rounded int32 values above 2**24 on the
312
+ neuron device** (silent, #90). The device computes integer matmul in fp32.
313
+ Since #70 integer operands contracted natively on any device. They now
314
+ contract natively only on CPU/CUDA, and on the host for other devices.
315
+ Unreleased (`main` after #70 only). Found by the conformance suite on Trn2
316
+ (trnsci/trnsci#35).
317
+ - **NKI chemistry kernels on Trainium: float64 operands gave inf, and kernel
318
+ routes changed the result dtype** (silent, #87). float64 tensors reached the
319
+ fp32 kernels as is. `df_coulomb` (≥ 256 packed rows), `ao_to_mo_transform`
320
+ and `df_exchange` came back inf under `set_backend("nki")`, or under
321
+ `"auto"` at the sizes where it picks the kernels. float64 operands are now
322
+ computed in fp32 and returned as float64, the documented fp64-on-Trainium
323
+ behaviour (`df_*` 0.21.0–0.22.0, `ao_to_mo_transform` every release with
324
+ its kernels). `mp2_energy` (row and legacy kernels), `ao_to_mo_transform`
325
+ and `df_exchange` also returned float32 for float64 or bfloat16 callers.
326
+ They now return the aten route's dtype. `df_exchange` with `naux == 0` (or
327
+ `nocc == 0`) raised `ZeroDivisionError` in the route's tiling and now takes
328
+ aten. Found by the conformance suite on Trn2 (trnsci/trnsci#35).
329
+ - **`einsum(precision="dd")` on float32 / float64 operands was less accurate
330
+ than `"fast"`** (silent; 0.17.0 through 0.22.0, the CPU emulation; Trainium
331
+ raises `NotImplementedError`). The CPU route split every operand into two
332
+ bf16-precision pieces (~16 mantissa bits) and rounded float64 operands to
333
+ float32, so the error was ~1e-5 instead of the documented K·u² + u_out
334
+ (6e-8 fp32, 1.1e-16 fp64). float32 operands now accumulate in fp64 (exact
335
+ products, inside K·u²). float64 operands form exact TwoProduct products and
336
+ sum them in double-word arithmetic on `matmul` / `bmm` plans and `path`
337
+ steps; generic `torch` plans accumulate in fp64. bf16 / fp16 `"dd"` and
338
+ every `"fast"` result are unchanged (#84).
339
+ - **`einsum(..., out=C)` with `beta=0` (the default) read `C`**, so NaN or
340
+ inf in the buffer (e.g. `torch.empty`) made the result NaN (silent, every
341
+ backend). Affects 0.3.0 through 0.22.0. `beta == 0` now ignores `out`, as
342
+ in BLAS, cuTENSOR and trnblas (#71).
343
+ - **`tucker_decompose` returned a wrong core for complex tensors** (silent,
344
+ every backend): it projected with `Uᵀ` instead of `Uᴴ`, so even a
345
+ full-rank reconstruction was off by ~140 %. Affects every release through
346
+ 0.22.0. `tt_decompose` now also accepts complex tensors instead of raising
347
+ (#73). Real tensors are unchanged.
348
+ - **`precision="kahan"` / `"dd"` / `target_forward_error` dropped the imaginary
349
+ part of complex operands and rounded large integers** (silent, every
350
+ backend). Affects `"kahan"` in 0.4.0 through 0.22.0, and `"dd"` and
351
+ `target_forward_error` in 0.17.0 through 0.22.0. Complex operands now
352
+ accumulate in complex128, and integer operands contract natively, which is
353
+ exact (#69).
354
+ - **`multi_einsum` changed result dtypes for mixed-dtype batches** (silent,
355
+ every backend). Same-shape contractions were stacked without checking
356
+ dtype, so float32 results came back float64. Affects 0.17.0 through 0.22.0.
357
+ Batching now requires matching operand dtypes and devices (#75).
358
+
10
359
  ## [0.22.0] — 2026-11-01
11
360
 
12
361
  Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
@@ -21,7 +21,9 @@ trntensor/
21
21
  │ ├── __init__.py
22
22
  │ ├── einsum.py # einsum(), multi_einsum()
23
23
  │ ├── plan.py # ContractionPlan, plan_contraction(), estimate_flops()
24
- │ ├── decompose.py # cp_decompose, tucker_decompose (HOSVD)
24
+ │ ├── decompose.py # cp_decompose, tucker_decompose (HOSVD), tt_decompose
25
+ │ ├── quantum.py # mp2_energy, ao_to_mo_transform, df_exchange, df_coulomb
26
+ │ ├── parallel.py # ShardedTensor, scatter, gather
25
27
  │ └── nki/
26
28
  │ ├── __init__.py
27
29
  │ ├── _kernels.py # @nki.jit kernels
@@ -38,8 +40,10 @@ trntensor/
38
40
  ## Contraction Planning
39
41
 
40
42
  The planner analyzes einsum subscripts and selects:
41
- - **matmul**: 2D contraction over single index → `torch.matmul`
42
- - **bmm**: batched 2D contraction → `torch.bmm`
43
+ - **matmul**: 2D contraction over single index, output `[A free, B free]` → `torch.matmul`
44
+ - **bmm**: exactly `bij,bjk->bik` → `torch.bmm`
45
+ (other index orders go to `torch.einsum`; before 0.22.0 they silently
46
+ returned the wrong layout, #64)
43
47
  - **torch**: complex patterns → `torch.einsum`
44
48
  - **(future) nki**: fused multi-index contractions on Tensor Engine
45
49
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trntensor
3
- Version: 0.22.0
3
+ Version: 0.24.0
4
4
  Summary: Tensor contractions for AWS Trainium via NKI
5
5
  Author-email: Scott Friedman <scttfrdmn@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -54,10 +54,10 @@ Einstein summation with contraction planning, CP and Tucker decompositions. Expr
54
54
 
55
55
  trntensor follows the [trnsci 5-phase roadmap](https://trnsci.dev/roadmap/). Active work is tracked in phase-labeled GitHub issues:
56
56
 
57
- - **[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.
58
- - **[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).
59
- - **[Phase 3 — perf](https://github.com/trnsci/trntensor/issues/29)**: opt_einsum-style path planner, plan cache reuse.
60
- - **[Phase 4 — multi-chip](https://github.com/trnsci/trntensor/issues/30)**: sharded tensor contractions.
57
+ - **[Phase 1 — correctness](https://github.com/trnsci/trntensor/issues/27)** (closed): NKI kernels validated on hardware. On the native TorchNeuron path (Trn2/Trn3) the fused `mp2_energy`, `ao_to_mo_transform`, `df_exchange` and `df_coulomb` kernels beat the aten routes they replace; the NKI matmul/bmm kernels never did and are deprecated there in favour of aten (0.19.0).
58
+ - **[Phase 2 — precision](https://github.com/trnsci/trntensor/issues/28)** (closed): precision-aware mode selection (`precision=`, `target_forward_error=`). `precision="dd"` on Trainium still waits on [trnblas#22](https://github.com/trnsci/trnblas/issues/22) double-double GEMM.
59
+ - **[Phase 3 — perf](https://github.com/trnsci/trntensor/issues/29)** (closed): greedy multi-operand path planner, plan cache.
60
+ - **[Phase 4 — multi-chip](https://github.com/trnsci/trntensor/issues/30)** (active): sharded tensor contractions (`ShardedTensor`, reduce-parallel all-reduce).
61
61
  - **[Phase 5 — generation](https://github.com/trnsci/trntensor/issues/31)**: trn2 fused multi-contraction paths.
62
62
 
63
63
  Suite-wide tracker: [trnsci/trnsci#1](https://github.com/trnsci/trnsci/issues/1).
@@ -92,6 +92,19 @@ the device with `to_device` / `from_device`; the older `to_xla` /
92
92
  editable install (`pip install -e`), set `NKI_ENABLE_TRACE_CACHE=0`: the NKI
93
93
  kernel cache only versions installed wheels and can serve stale kernels.
94
94
 
95
+ ### Known platform issue: NKI trace cache and kernel factories
96
+
97
+ `import torch_neuronx` turns on the NKI trace cache, and the cache key ignores
98
+ constants captured in a kernel's closure: two `@nki.jit` kernels built by one
99
+ factory, differing only in a captured value, share one trace, and the second
100
+ silently returns the first's results
101
+ ([aws-neuron/aws-neuron-sdk#1454](https://github.com/aws-neuron/aws-neuron-sdk/issues/1454)).
102
+ trntensor's kernels do not rely on closure constants (or on module globals that
103
+ can differ between processes): every value that specialises a kernel is a
104
+ kernel argument, and `tests/test_trace_cache_safety.py` enforces this. If you
105
+ write your own NKI kernels with a factory, set `NKI_ENABLE_TRACE_CACHE=0`
106
+ before importing `torch_neuronx`.
107
+
95
108
  ## Usage
96
109
 
97
110
  ```python
@@ -125,10 +138,16 @@ core, factors = trntensor.tucker_decompose(tensor, ranks=(5, 5, 5))
125
138
  | Planning | `estimate_flops` | FLOPs for a contraction |
126
139
  | Decomposition | `cp_decompose` | CP/PARAFAC via ALS |
127
140
  | Decomposition | `tucker_decompose` | Tucker via HOSVD |
141
+ | Decomposition | `tt_decompose` | Tensor Train via TT-SVD |
142
+ | Chemistry | `mp2_energy` | Fused DF-MP2 correlation energy |
143
+ | Chemistry | `ao_to_mo_transform` | Fused AO→MO transform (full or packed integrals) |
144
+ | Chemistry | `df_exchange` / `df_coulomb` | Fused DF exchange (K) / Coulomb (J) from packed integrals |
145
+ | Chemistry | `pack_tril` / `unpack_tril` | Packed (μ≥ν) three-centre integral layout |
146
+ | Sharding | `ShardedTensor`, `scatter`, `gather` | Output- and reduce-parallel sharded contractions |
128
147
 
129
148
  ## Status
130
149
 
131
- - [x] Einsum with matmul/bmm/torch dispatch
150
+ - [x] Einsum with matmul/bmm/torch dispatch (output index order honoured since 0.22.0; earlier releases returned the wrong layout for transposed/permuted outputs, #64)
132
151
  - [x] Contraction planner
133
152
  - [x] CP decomposition (ALS)
134
153
  - [x] Tucker decomposition (HOSVD)
@@ -146,17 +165,32 @@ core, factors = trntensor.tucker_decompose(tensor, ranks=(5, 5, 5))
146
165
  - [x] Non-negative CP + warm-start CP
147
166
  - [x] PEP 561 `py.typed` marker
148
167
  - [x] Mixed precision / `dtype` override for bf16/fp16
149
- - [x] `precision=` kwarg (`"fast"` / `"kahan"` fp64 promotion / `"dd"` stub)
168
+ - [x] `precision=` kwarg (`"fast"` / `"kahan"` fp64 promotion / `"sr"` / `"dd"`: CPU emulation only, raises on Trainium until trnblas#22)
169
+
170
+ ## Known issues in earlier releases
171
+
172
+ Silent wrong-result bugs fixed in the 2026-10-31 to 2026-11-02 releases. Details are in the [CHANGELOG](CHANGELOG.md).
173
+
174
+ | Bug | Affected | Fixed in |
175
+ |-----|----------|----------|
176
+ | `einsum` returned the wrong layout for transposed or permuted outputs (e.g. `ij,jk->ki` gave `A@B`), every backend (#64) | through 0.21.0 | 0.22.0 |
177
+ | `einsum(..., out=C)` with `beta=0` read `C`, so NaN/inf in it made the result NaN (#71) | 0.3.0–0.22.0 | 0.23.0 |
178
+ | `tucker_decompose` used `Uᵀ` instead of `Uᴴ` for complex tensors, giving a wrong core (#73) | through 0.22.0 | 0.23.0 |
179
+ | `precision="kahan"` / `"dd"` / `target_forward_error` dropped the imaginary part of complex operands and rounded large integers (#69) | `"kahan"` 0.4.0–0.22.0; `"dd"`, `target_forward_error` 0.17.0–0.22.0 | 0.23.0 |
180
+ | `einsum(precision="dd")` on float32/float64 was less accurate than `"fast"` (CPU emulation, #84) | 0.17.0–0.22.0 | 0.23.0 |
181
+ | `multi_einsum` returned float32 results as float64 in mixed-dtype batches (#75) | 0.17.0–0.22.0 | 0.23.0 |
182
+ | NKI chemistry kernels returned inf for float64 operands, and some kernel routes changed the result dtype (#87) | `df_*` 0.21.0–0.22.0; `ao_to_mo_transform` every release with its kernels | 0.23.0 |
183
+ | `ao_to_mo_transform` aten route on the TorchNeuron device was wrong once `eri` exceeded 4 GiB (#97; one LNC=1 case is still open) | through 0.22.0 | 0.23.0 |
150
184
 
151
185
  ## Related Projects
152
186
 
153
187
  | Project | What |
154
188
  |---------|------|
155
- | [trnfft](https://github.com/scttfrdmn/trnfft) | FFT + complex ops |
156
- | [trnblas](https://github.com/scttfrdmn/trnblas) | BLAS operations |
157
- | [trnsolver](https://github.com/scttfrdmn/trnsolver) | Linear solvers |
158
- | [trnrand](https://github.com/scttfrdmn/trnrand) | Random number generation |
159
- | [trnsparse](https://github.com/scttfrdmn/trnsparse) | Sparse operations |
189
+ | [trnfft](https://github.com/trnsci/trnfft) | FFT + complex ops |
190
+ | [trnblas](https://github.com/trnsci/trnblas) | BLAS operations |
191
+ | [trnsolver](https://github.com/trnsci/trnsolver) | Linear solvers |
192
+ | [trnrand](https://github.com/trnsci/trnrand) | Random number generation |
193
+ | [trnsparse](https://github.com/trnsci/trnsparse) | Sparse operations |
160
194
 
161
195
  ## License
162
196
 
@@ -16,10 +16,10 @@ Einstein summation with contraction planning, CP and Tucker decompositions. Expr
16
16
 
17
17
  trntensor follows the [trnsci 5-phase roadmap](https://trnsci.dev/roadmap/). Active work is tracked in phase-labeled GitHub issues:
18
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.
19
+ - **[Phase 1 — correctness](https://github.com/trnsci/trntensor/issues/27)** (closed): NKI kernels validated on hardware. On the native TorchNeuron path (Trn2/Trn3) the fused `mp2_energy`, `ao_to_mo_transform`, `df_exchange` and `df_coulomb` kernels beat the aten routes they replace; the NKI matmul/bmm kernels never did and are deprecated there in favour of aten (0.19.0).
20
+ - **[Phase 2 — precision](https://github.com/trnsci/trntensor/issues/28)** (closed): precision-aware mode selection (`precision=`, `target_forward_error=`). `precision="dd"` on Trainium still waits on [trnblas#22](https://github.com/trnsci/trnblas/issues/22) double-double GEMM.
21
+ - **[Phase 3 — perf](https://github.com/trnsci/trntensor/issues/29)** (closed): greedy multi-operand path planner, plan cache.
22
+ - **[Phase 4 — multi-chip](https://github.com/trnsci/trntensor/issues/30)** (active): sharded tensor contractions (`ShardedTensor`, reduce-parallel all-reduce).
23
23
  - **[Phase 5 — generation](https://github.com/trnsci/trntensor/issues/31)**: trn2 fused multi-contraction paths.
24
24
 
25
25
  Suite-wide tracker: [trnsci/trnsci#1](https://github.com/trnsci/trnsci/issues/1).
@@ -54,6 +54,19 @@ the device with `to_device` / `from_device`; the older `to_xla` /
54
54
  editable install (`pip install -e`), set `NKI_ENABLE_TRACE_CACHE=0`: the NKI
55
55
  kernel cache only versions installed wheels and can serve stale kernels.
56
56
 
57
+ ### Known platform issue: NKI trace cache and kernel factories
58
+
59
+ `import torch_neuronx` turns on the NKI trace cache, and the cache key ignores
60
+ constants captured in a kernel's closure: two `@nki.jit` kernels built by one
61
+ factory, differing only in a captured value, share one trace, and the second
62
+ silently returns the first's results
63
+ ([aws-neuron/aws-neuron-sdk#1454](https://github.com/aws-neuron/aws-neuron-sdk/issues/1454)).
64
+ trntensor's kernels do not rely on closure constants (or on module globals that
65
+ can differ between processes): every value that specialises a kernel is a
66
+ kernel argument, and `tests/test_trace_cache_safety.py` enforces this. If you
67
+ write your own NKI kernels with a factory, set `NKI_ENABLE_TRACE_CACHE=0`
68
+ before importing `torch_neuronx`.
69
+
57
70
  ## Usage
58
71
 
59
72
  ```python
@@ -87,10 +100,16 @@ core, factors = trntensor.tucker_decompose(tensor, ranks=(5, 5, 5))
87
100
  | Planning | `estimate_flops` | FLOPs for a contraction |
88
101
  | Decomposition | `cp_decompose` | CP/PARAFAC via ALS |
89
102
  | Decomposition | `tucker_decompose` | Tucker via HOSVD |
103
+ | Decomposition | `tt_decompose` | Tensor Train via TT-SVD |
104
+ | Chemistry | `mp2_energy` | Fused DF-MP2 correlation energy |
105
+ | Chemistry | `ao_to_mo_transform` | Fused AO→MO transform (full or packed integrals) |
106
+ | Chemistry | `df_exchange` / `df_coulomb` | Fused DF exchange (K) / Coulomb (J) from packed integrals |
107
+ | Chemistry | `pack_tril` / `unpack_tril` | Packed (μ≥ν) three-centre integral layout |
108
+ | Sharding | `ShardedTensor`, `scatter`, `gather` | Output- and reduce-parallel sharded contractions |
90
109
 
91
110
  ## Status
92
111
 
93
- - [x] Einsum with matmul/bmm/torch dispatch
112
+ - [x] Einsum with matmul/bmm/torch dispatch (output index order honoured since 0.22.0; earlier releases returned the wrong layout for transposed/permuted outputs, #64)
94
113
  - [x] Contraction planner
95
114
  - [x] CP decomposition (ALS)
96
115
  - [x] Tucker decomposition (HOSVD)
@@ -108,17 +127,32 @@ core, factors = trntensor.tucker_decompose(tensor, ranks=(5, 5, 5))
108
127
  - [x] Non-negative CP + warm-start CP
109
128
  - [x] PEP 561 `py.typed` marker
110
129
  - [x] Mixed precision / `dtype` override for bf16/fp16
111
- - [x] `precision=` kwarg (`"fast"` / `"kahan"` fp64 promotion / `"dd"` stub)
130
+ - [x] `precision=` kwarg (`"fast"` / `"kahan"` fp64 promotion / `"sr"` / `"dd"`: CPU emulation only, raises on Trainium until trnblas#22)
131
+
132
+ ## Known issues in earlier releases
133
+
134
+ Silent wrong-result bugs fixed in the 2026-10-31 to 2026-11-02 releases. Details are in the [CHANGELOG](CHANGELOG.md).
135
+
136
+ | Bug | Affected | Fixed in |
137
+ |-----|----------|----------|
138
+ | `einsum` returned the wrong layout for transposed or permuted outputs (e.g. `ij,jk->ki` gave `A@B`), every backend (#64) | through 0.21.0 | 0.22.0 |
139
+ | `einsum(..., out=C)` with `beta=0` read `C`, so NaN/inf in it made the result NaN (#71) | 0.3.0–0.22.0 | 0.23.0 |
140
+ | `tucker_decompose` used `Uᵀ` instead of `Uᴴ` for complex tensors, giving a wrong core (#73) | through 0.22.0 | 0.23.0 |
141
+ | `precision="kahan"` / `"dd"` / `target_forward_error` dropped the imaginary part of complex operands and rounded large integers (#69) | `"kahan"` 0.4.0–0.22.0; `"dd"`, `target_forward_error` 0.17.0–0.22.0 | 0.23.0 |
142
+ | `einsum(precision="dd")` on float32/float64 was less accurate than `"fast"` (CPU emulation, #84) | 0.17.0–0.22.0 | 0.23.0 |
143
+ | `multi_einsum` returned float32 results as float64 in mixed-dtype batches (#75) | 0.17.0–0.22.0 | 0.23.0 |
144
+ | NKI chemistry kernels returned inf for float64 operands, and some kernel routes changed the result dtype (#87) | `df_*` 0.21.0–0.22.0; `ao_to_mo_transform` every release with its kernels | 0.23.0 |
145
+ | `ao_to_mo_transform` aten route on the TorchNeuron device was wrong once `eri` exceeded 4 GiB (#97; one LNC=1 case is still open) | through 0.22.0 | 0.23.0 |
112
146
 
113
147
  ## Related Projects
114
148
 
115
149
  | Project | What |
116
150
  |---------|------|
117
- | [trnfft](https://github.com/scttfrdmn/trnfft) | FFT + complex ops |
118
- | [trnblas](https://github.com/scttfrdmn/trnblas) | BLAS operations |
119
- | [trnsolver](https://github.com/scttfrdmn/trnsolver) | Linear solvers |
120
- | [trnrand](https://github.com/scttfrdmn/trnrand) | Random number generation |
121
- | [trnsparse](https://github.com/scttfrdmn/trnsparse) | Sparse operations |
151
+ | [trnfft](https://github.com/trnsci/trnfft) | FFT + complex ops |
152
+ | [trnblas](https://github.com/trnsci/trnblas) | BLAS operations |
153
+ | [trnsolver](https://github.com/trnsci/trnsolver) | Linear solvers |
154
+ | [trnrand](https://github.com/trnsci/trnrand) | Random number generation |
155
+ | [trnsparse](https://github.com/trnsci/trnsparse) | Sparse operations |
122
156
 
123
157
  ## License
124
158