trnsolver 0.22.0__tar.gz → 0.22.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.
- {trnsolver-0.22.0 → trnsolver-0.22.1}/.github/workflows/ci.yml +1 -1
- {trnsolver-0.22.0 → trnsolver-0.22.1}/.pre-commit-config.yaml +4 -2
- {trnsolver-0.22.0 → trnsolver-0.22.1}/CHANGELOG.md +21 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/PKG-INFO +5 -3
- {trnsolver-0.22.0 → trnsolver-0.22.1}/README.md +3 -1
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/api/factor.md +20 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/api/iterative.md +2 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/pyproject.toml +2 -2
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_conformance.py +5 -5
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_factor.py +100 -8
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/__init__.py +1 -1
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/block.py +10 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/factor.py +49 -7
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver.egg-info/PKG-INFO +5 -3
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver.egg-info/requires.txt +1 -1
- {trnsolver-0.22.0 → trnsolver-0.22.1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/.github/pull_request_template.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/.github/workflows/neuron.yml +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/.github/workflows/notify-umbrella.yml +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/.github/workflows/publish.yml +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/.gitignore +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/CLAUDE.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/CODE_OF_CONDUCT.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/CONTRIBUTING.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/LICENSE +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/benchmarks/bench_cuda.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/benchmarks/bench_solver.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/benchmarks/conftest.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/api/eigen.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/api/nki.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/architecture.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/aws_setup.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/benchmarks.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/developing_kernels.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/index.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/installation.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/docs/quickstart.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/examples/df_store.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/examples/scf_df_mp2.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/examples/scf_df_rhf.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/examples/scf_eigen.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/infra/terraform/README.md +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/infra/terraform/gpu.tf +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/infra/terraform/main.tf +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/mkdocs.yml +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/bench_eager_handle.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/bench_gp_precond.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/bench_jacobi.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/bench_jacobi_multicore.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/bench_occupied_subspace.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/bench_scf.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/bench_scf_ladder.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/probe_large_n_split.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/run_cuda_tests.sh +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/run_neuron_tests.sh +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/run_simulator_tests.sh +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/scripts/stop_neuron_ci.sh +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/setup.cfg +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/conftest.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_bench_scf_ladder.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_block_neuron.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_cg_block.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_compile.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_complex_rhs.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_dtype.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_eigen.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_eigh_cutover.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_eigh_neuron.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_hermitian_batch.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_iterative.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_iterative_autograd.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_iterative_rhs_scale.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_jacobi.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_jacobi_onezero_arg.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_kernel_dtype_guard.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_native_dispatch.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_nki_compile.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_nki_native.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_nki_sim.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_nki_tail_audit.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_orthogonalize.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_scf_df_mp2.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_scf_df_rhf.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_subspace.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/tests/test_trace_cache_safety.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/_jacobi.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/eigen.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/iterative.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/nki/__init__.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/nki/_native.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/nki/dispatch.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/nki/eigh_pool.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/nki/jacobi.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/nki/subspace.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/orthogonalize.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver/subspace.py +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver.egg-info/SOURCES.txt +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver.egg-info/dependency_links.txt +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/trnsolver.egg-info/top_level.txt +0 -0
- {trnsolver-0.22.0 → trnsolver-0.22.1}/uv.lock +0 -0
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
# pre-commit run --all-files
|
|
13
13
|
|
|
14
14
|
repos:
|
|
15
|
+
# Keep rev in lockstep with the ruff pin in .github/workflows/ci.yml
|
|
16
|
+
# (and the [dev] extra in pyproject.toml) so local and CI agree.
|
|
15
17
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
16
|
-
rev: v0.
|
|
18
|
+
rev: v0.17.3
|
|
17
19
|
hooks:
|
|
18
|
-
- id: ruff
|
|
20
|
+
- id: ruff-check
|
|
19
21
|
args: [--fix]
|
|
20
22
|
- id: ruff-format
|
|
21
23
|
|
|
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.22.1] — 2026-11-07
|
|
11
|
+
|
|
12
|
+
Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
|
|
13
|
+
|
|
14
|
+
Headline: solve_spd emits a FutureWarning for the ambiguous B shape, A (*, n, n, n) with B (*, n, n), ahead of the 0.23.0 switch to torch's reading (#79, #131); inv_spd no longer passes that shape internally.
|
|
15
|
+
|
|
16
|
+
### Deprecated
|
|
17
|
+
|
|
18
|
+
- **`solve_spd(A, B)` with an ambiguous B: A `(*, n, n, n)`, B `(*, n, n)`
|
|
19
|
+
(#79).** In this case `B.shape == A.shape[:-1]` and A's last batch dim equals n.
|
|
20
|
+
`solve_spd` reads B as `(*, n, k)` right-hand-side matrices broadcast over
|
|
21
|
+
A's batch and returns `(*, n, n, n)`; `torch.linalg.solve` (and
|
|
22
|
+
`trnsolver.solve`) read it as a batch of vectors and return `(*, n, n)`.
|
|
23
|
+
The result is unchanged in 0.22.1, but the call now emits a `FutureWarning`
|
|
24
|
+
(once per call site). In 0.23.0 `solve_spd` switches to torch's reading
|
|
25
|
+
(#130). To be explicit, pass `B.unsqueeze(-1)` for a batch of vectors, or
|
|
26
|
+
`B.unsqueeze(-3)` to broadcast one shared matrix. Both forms mean the same
|
|
27
|
+
in every release. For a 3-D A, `B.unsqueeze(-3)` is today's result; with
|
|
28
|
+
more batch dims, `B.unsqueeze(0)` is. `inv_spd` no longer passes that shape
|
|
29
|
+
internally, so a batched A with batch dim n does not warn.
|
|
30
|
+
|
|
10
31
|
## [0.22.0] — 2026-11-04
|
|
11
32
|
|
|
12
33
|
Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trnsolver
|
|
3
|
-
Version: 0.22.
|
|
3
|
+
Version: 0.22.1
|
|
4
4
|
Summary: Linear solvers and eigendecomposition for AWS Trainium via NKI
|
|
5
5
|
Author-email: Scott Friedman <scttfrdmn@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -30,7 +30,7 @@ Provides-Extra: dev
|
|
|
30
30
|
Requires-Dist: pytest<9,>=7.0; extra == "dev"
|
|
31
31
|
Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
|
|
32
32
|
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
33
|
-
Requires-Dist: ruff
|
|
33
|
+
Requires-Dist: ruff==0.17.3; extra == "dev"
|
|
34
34
|
Requires-Dist: scipy>=1.11; extra == "dev"
|
|
35
35
|
Requires-Dist: trnblas>=0.9; extra == "dev"
|
|
36
36
|
Requires-Dist: trntensor>=0.24; extra == "dev"
|
|
@@ -255,12 +255,14 @@ CPU baselines (torch.linalg, scipy.linalg, trnsolver PyTorch path) run on every
|
|
|
255
255
|
|
|
256
256
|
## Known issues in earlier releases
|
|
257
257
|
|
|
258
|
-
Silent wrong-result bugs fixed in the 2026-10-31 to 2026-11-
|
|
258
|
+
Silent wrong-result bugs fixed in the 2026-10-31 to 2026-11-04 releases. Details are in the [CHANGELOG](CHANGELOG.md).
|
|
259
259
|
|
|
260
260
|
| Bug | Affected | Fixed in |
|
|
261
261
|
|---|---|---|
|
|
262
262
|
| `eigh` on the NKI Householder path (`TRNSOLVER_REQUIRE_NKI=1` or a non-native NKI device): float64 input gave garbage results, and n = 1 returned `(1, 1)` eigenvalues; `eigh_generalized` inherited both (#83) | through 0.20.0 (n = 1 shape: 0.4.0–0.20.0) | 0.21.0 |
|
|
263
263
|
| Complex Hermitian and batched input to `cholesky(upper=True)`, `solve_spd`, `inv_spd`, `inv_sqrt_spd`, `eigh_generalized`, `eigh_randomized`, `pinv` and `ssor_preconditioner` used `.T` instead of `.mH` (#64) | every release through 0.20.0 (`pinv` since 0.5.0, `ssor_preconditioner` since 0.8.0) | 0.21.0 |
|
|
264
|
+
| `cg` dropped the imaginary part of complex input (unconjugated inner products cast to real), so a complex Hermitian system returned a wrong `x` with only a `UserWarning`; a complex `A` with a real `b` also lost `A`'s imaginary part (#100) | every release through 0.21.0 | 0.22.0 |
|
|
265
|
+
| `cg` gave a wrong gradient with respect to `A` (it differentiated a fixed polynomial in `A`; rel. err 0.55 at n = 5), and `schur` returned `Q`, `T` that silently contributed zero gradient (#76) | every release through 0.21.0 | 0.22.0 |
|
|
264
266
|
|
|
265
267
|
## Related projects in the trnsci suite
|
|
266
268
|
|
|
@@ -217,12 +217,14 @@ CPU baselines (torch.linalg, scipy.linalg, trnsolver PyTorch path) run on every
|
|
|
217
217
|
|
|
218
218
|
## Known issues in earlier releases
|
|
219
219
|
|
|
220
|
-
Silent wrong-result bugs fixed in the 2026-10-31 to 2026-11-
|
|
220
|
+
Silent wrong-result bugs fixed in the 2026-10-31 to 2026-11-04 releases. Details are in the [CHANGELOG](CHANGELOG.md).
|
|
221
221
|
|
|
222
222
|
| Bug | Affected | Fixed in |
|
|
223
223
|
|---|---|---|
|
|
224
224
|
| `eigh` on the NKI Householder path (`TRNSOLVER_REQUIRE_NKI=1` or a non-native NKI device): float64 input gave garbage results, and n = 1 returned `(1, 1)` eigenvalues; `eigh_generalized` inherited both (#83) | through 0.20.0 (n = 1 shape: 0.4.0–0.20.0) | 0.21.0 |
|
|
225
225
|
| Complex Hermitian and batched input to `cholesky(upper=True)`, `solve_spd`, `inv_spd`, `inv_sqrt_spd`, `eigh_generalized`, `eigh_randomized`, `pinv` and `ssor_preconditioner` used `.T` instead of `.mH` (#64) | every release through 0.20.0 (`pinv` since 0.5.0, `ssor_preconditioner` since 0.8.0) | 0.21.0 |
|
|
226
|
+
| `cg` dropped the imaginary part of complex input (unconjugated inner products cast to real), so a complex Hermitian system returned a wrong `x` with only a `UserWarning`; a complex `A` with a real `b` also lost `A`'s imaginary part (#100) | every release through 0.21.0 | 0.22.0 |
|
|
227
|
+
| `cg` gave a wrong gradient with respect to `A` (it differentiated a fixed polynomial in `A`; rel. err 0.55 at n = 5), and `schur` returned `Q`, `T` that silently contributed zero gradient (#76) | every release through 0.21.0 | 0.22.0 |
|
|
226
228
|
|
|
227
229
|
## Related projects in the trnsci suite
|
|
228
230
|
|
|
@@ -25,6 +25,26 @@ Solves `A X = B` via LU.
|
|
|
25
25
|
|
|
26
26
|
Solves `A X = B` via Cholesky — faster than `solve` when `A` is SPD.
|
|
27
27
|
|
|
28
|
+
`B` is `(n,)`, `(*, n, k)`, or a batch of vectors `(*, n)` with
|
|
29
|
+
`B.shape == A.shape[:-1]`, as `torch.linalg.solve` reads it.
|
|
30
|
+
|
|
31
|
+
!!! warning "Deprecated in 0.22.1: an ambiguous `B` shape (#79)"
|
|
32
|
+
When A's last batch dim equals `n` (A `(*, n, n, n)`, B `(*, n, n)`), `B`
|
|
33
|
+
can be read either way. `solve_spd` still reads it as `(*, n, k)`
|
|
34
|
+
right-hand-side matrices broadcast over A's batch (result
|
|
35
|
+
`(*, n, n, n)`), and now emits a `FutureWarning`. From 0.23.0 it reads
|
|
36
|
+
it as a batch of vectors, as `torch.linalg.solve` does (result
|
|
37
|
+
`(*, n, n)`; [#130](https://github.com/trnsci/trnsolver/issues/130)).
|
|
38
|
+
Be explicit; both forms mean the same in every release:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
X = trnsolver.solve_spd(A, B.unsqueeze(-1)) # batch of vectors -> (*, n, n, 1)
|
|
42
|
+
X = trnsolver.solve_spd(A, B.unsqueeze(-3)) # one shared (n, k) right-hand side
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For a 3-D `A`, `B.unsqueeze(-3)` is the current result; with more batch
|
|
46
|
+
dims, `B.unsqueeze(0)` is.
|
|
47
|
+
|
|
28
48
|
## `inv_spd(A)`
|
|
29
49
|
|
|
30
50
|
Returns `A⁻¹` for SPD `A` via Cholesky.
|
|
@@ -92,6 +92,8 @@ def ksub(idx): # K[idx][:, idx], c × c on the host
|
|
|
92
92
|
L = trnsolver.pivoted_cholesky(op.diag, krows, 1024, block=512, relax=0.5, sub_fn=ksub)
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
+
**float64: keep K on the host when `rows_fn` gathers.** The build is float64 on the host, but L is only as accurate as the rows `rows_fn` returns, and the library can't see inside the callable. On Trn2 a device-side gather of float64 (`K[idx]`, `index_select`, `torch.cat`) rounds to fp32, with a relative error of about 3.6e-8. So a `rows_fn` that gathers rows from a float64 `K` on the `neuron` device gives a `pivoted_lowrank_preconditioner` (or `pivoted_cholesky`) accurate to about 2e-8, not about 1e-15. For float64, keep `K`, or whatever data `rows_fn` reads, on the host. Plain copies (`.to`, `.clone()`, `.contiguous()`, basic indexing) are exact.
|
|
96
|
+
|
|
95
97
|
`PivotedLowRankPreconditioner(L, shift, apply=...)` applies `(L Lᵀ + shift·I)⁻¹`. It has these attributes and methods:
|
|
96
98
|
|
|
97
99
|
- `.L`, `.shift`, `.W` (or `.Q`, `.g` for `"projected"`);
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "trnsolver"
|
|
7
|
-
version = "0.22.
|
|
7
|
+
version = "0.22.1"
|
|
8
8
|
description = "Linear solvers and eigendecomposition for AWS Trainium via NKI"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -55,7 +55,7 @@ dev = [
|
|
|
55
55
|
"pytest>=7.0,<9", # pytest-benchmark 5.3 breaks on pytest 9 (Function._nodeid)
|
|
56
56
|
"pytest-benchmark>=4.0",
|
|
57
57
|
"pytest-cov>=4.0",
|
|
58
|
-
"ruff
|
|
58
|
+
"ruff==0.17.3",
|
|
59
59
|
"scipy>=1.11",
|
|
60
60
|
# examples/scf_df_rhf.py (tests/test_scf_df_rhf.py) composes the suite.
|
|
61
61
|
"trnblas>=0.9",
|
|
@@ -1383,13 +1383,13 @@ for _op in OPS:
|
|
|
1383
1383
|
BATCH_IDS.append(
|
|
1384
1384
|
(f"{_op}-batch{N}", _op, (N,))
|
|
1385
1385
|
) # batch == n: a .T over all dims keeps the shape
|
|
1386
|
-
# Batch == n: B (n, n)
|
|
1387
|
-
#
|
|
1388
|
-
#
|
|
1386
|
+
# Batch == n: B (n, n) still reads as one shared (n, k) right-hand side, with
|
|
1387
|
+
# a FutureWarning (0.22.1); 0.23.0 switches to torch's batch-of-vectors reading
|
|
1388
|
+
# and this case passes (trnsci/trnsolver#79, #130).
|
|
1389
1389
|
KNOWN[f"solve_spd_vec-batch{N}"] = pytest.mark.xfail(
|
|
1390
1390
|
strict=True,
|
|
1391
|
-
reason="trnsci/trnsolver#
|
|
1392
|
-
"as a shared (n, k) right-hand side, not a batch of vectors",
|
|
1391
|
+
reason="trnsci/trnsolver#130: until 0.23.0 solve_spd reads B (n, n) with batch == n "
|
|
1392
|
+
"as a shared (n, k) right-hand side (deprecated, #79), not a batch of vectors",
|
|
1393
1393
|
)
|
|
1394
1394
|
|
|
1395
1395
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""Test matrix factorizations."""
|
|
2
2
|
|
|
3
|
+
import warnings
|
|
4
|
+
|
|
3
5
|
import numpy as np
|
|
4
6
|
import pytest
|
|
5
7
|
import torch
|
|
@@ -229,15 +231,105 @@ class TestSolveSPDBatchedVectors:
|
|
|
229
231
|
B = torch.ones(3, 4, dtype=torch.float64)
|
|
230
232
|
np.testing.assert_allclose(trnsolver.solve_spd(A, B).numpy(), np.ones((3, 4)))
|
|
231
233
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
234
|
+
|
|
235
|
+
def _spd_np(batch, n, seed=0):
|
|
236
|
+
X = np.random.default_rng(seed).standard_normal((*batch, n, n))
|
|
237
|
+
return X @ np.swapaxes(X, -1, -2) + n * np.eye(n)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def _no_warnings(fn, *args, **kwargs):
|
|
241
|
+
with warnings.catch_warnings():
|
|
242
|
+
warnings.simplefilter("error")
|
|
243
|
+
return fn(*args, **kwargs)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
class TestSolveSPDAmbiguousRHS:
|
|
247
|
+
"""A (*, n, n, n), B (*, n, n): deprecated in 0.22.1, switches in 0.23.0 (#79, #130).
|
|
248
|
+
|
|
249
|
+
Today B reads as (*, n, k) right-hand sides broadcast over A's batch;
|
|
250
|
+
0.23.0 reads it as a batch of vectors, as torch.linalg.solve does. The
|
|
251
|
+
explicit forms B.unsqueeze(-1) / B.unsqueeze(-3) have B.dim() == A.dim(),
|
|
252
|
+
so neither reading applies to them: same result in both releases.
|
|
253
|
+
Reference: numpy.linalg.solve (LAPACK).
|
|
254
|
+
"""
|
|
255
|
+
|
|
256
|
+
n = 4
|
|
257
|
+
|
|
258
|
+
def _case(self, batch=()):
|
|
259
|
+
n = self.n
|
|
260
|
+
A = _spd_np((*batch, n), n, seed=2)
|
|
261
|
+
B = np.random.default_rng(3).standard_normal((*batch, n, n))
|
|
262
|
+
return A, B
|
|
263
|
+
|
|
264
|
+
@pytest.mark.parametrize("ir", [False, True])
|
|
265
|
+
def test_warns_and_keeps_matrix_reading(self, ir):
|
|
266
|
+
A, B = self._case()
|
|
267
|
+
with pytest.warns(FutureWarning, match=r"0\.23\.0") as rec:
|
|
268
|
+
X = trnsolver.solve_spd(
|
|
269
|
+
torch.from_numpy(A), torch.from_numpy(B), iterative_refinement=ir
|
|
270
|
+
)
|
|
271
|
+
assert X.shape == (self.n,) * 3
|
|
240
272
|
np.testing.assert_allclose(X.numpy(), np.linalg.solve(A, B), rtol=0, atol=1e-10)
|
|
273
|
+
msg = str(rec[0].message)
|
|
274
|
+
assert "B.unsqueeze(-1)" in msg and "B.unsqueeze(-3)" in msg
|
|
275
|
+
# Points at the caller, not at trnsolver internals.
|
|
276
|
+
assert rec[0].filename == __file__
|
|
277
|
+
|
|
278
|
+
def test_warns_with_leading_batch(self):
|
|
279
|
+
# A (n, n, n, n), B (n, n, n): B broadcasts as (1, n, n, n), so today's
|
|
280
|
+
# result is B.unsqueeze(0); the message says so.
|
|
281
|
+
A, B = self._case((self.n,))
|
|
282
|
+
with pytest.warns(FutureWarning, match=r"B\.unsqueeze\(0\) gives today's result"):
|
|
283
|
+
X = trnsolver.solve_spd(torch.from_numpy(A), torch.from_numpy(B))
|
|
284
|
+
Xe = _no_warnings(
|
|
285
|
+
trnsolver.solve_spd, torch.from_numpy(A), torch.from_numpy(B).unsqueeze(0)
|
|
286
|
+
)
|
|
287
|
+
assert torch.equal(X, Xe)
|
|
288
|
+
|
|
289
|
+
def test_explicit_batch_of_vectors(self):
|
|
290
|
+
# B.unsqueeze(-1): the 0.23.0 reading of B, as torch.linalg.solve.
|
|
291
|
+
A, B = self._case()
|
|
292
|
+
At, Bt = torch.from_numpy(A), torch.from_numpy(B)
|
|
293
|
+
X = _no_warnings(trnsolver.solve_spd, At, Bt.unsqueeze(-1))
|
|
294
|
+
assert X.shape == (self.n, self.n, 1)
|
|
295
|
+
ref = np.linalg.solve(A, B[..., None])[..., 0]
|
|
296
|
+
np.testing.assert_allclose(X.squeeze(-1).numpy(), ref, rtol=0, atol=1e-10)
|
|
297
|
+
np.testing.assert_allclose(
|
|
298
|
+
X.squeeze(-1).numpy(), torch.linalg.solve(At, Bt).numpy(), rtol=0, atol=1e-10
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
def test_explicit_shared_matrix(self):
|
|
302
|
+
# B.unsqueeze(-3): one shared (n, k) right-hand side; for a 3-D A that
|
|
303
|
+
# is exactly today's result.
|
|
304
|
+
A, B = self._case()
|
|
305
|
+
At, Bt = torch.from_numpy(A), torch.from_numpy(B)
|
|
306
|
+
X = _no_warnings(trnsolver.solve_spd, At, Bt.unsqueeze(-3))
|
|
307
|
+
with pytest.warns(FutureWarning):
|
|
308
|
+
X_today = trnsolver.solve_spd(At, Bt)
|
|
309
|
+
assert torch.equal(X, X_today)
|
|
310
|
+
np.testing.assert_allclose(X.numpy(), np.linalg.solve(A, B), rtol=0, atol=1e-10)
|
|
311
|
+
|
|
312
|
+
@pytest.mark.parametrize(
|
|
313
|
+
"a_shape,b_shape",
|
|
314
|
+
[
|
|
315
|
+
((4, 4), (4,)),
|
|
316
|
+
((4, 4), (4, 4)),
|
|
317
|
+
((3, 4, 4), (3, 4)), # batch of vectors, batch != n
|
|
318
|
+
((4, 4, 4), (4, 4, 4)),
|
|
319
|
+
((4, 4, 4), (4, 2)),
|
|
320
|
+
((2, 3, 4, 4), (2, 3, 4)),
|
|
321
|
+
],
|
|
322
|
+
)
|
|
323
|
+
def test_no_warning_outside_ambiguous_case(self, a_shape, b_shape):
|
|
324
|
+
n = a_shape[-1]
|
|
325
|
+
A = torch.from_numpy(_spd_np(a_shape[:-2], n))
|
|
326
|
+
B = torch.ones(b_shape, dtype=torch.float64)
|
|
327
|
+
_no_warnings(trnsolver.solve_spd, A, B)
|
|
328
|
+
|
|
329
|
+
def test_inv_spd_batch_equals_n_does_not_warn(self):
|
|
330
|
+
A = torch.from_numpy(_spd_np((self.n,), self.n))
|
|
331
|
+
Ainv = _no_warnings(trnsolver.inv_spd, A)
|
|
332
|
+
np.testing.assert_allclose(Ainv.numpy(), np.linalg.inv(A.numpy()), rtol=0, atol=1e-10)
|
|
241
333
|
|
|
242
334
|
|
|
243
335
|
class TestInvSqrtSPD:
|
|
@@ -6,7 +6,7 @@ computing on Trainium. Complements trnblas (BLAS) and trnfft (FFT).
|
|
|
6
6
|
Part of the trnsci scientific computing suite.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
__version__ = "0.22.
|
|
9
|
+
__version__ = "0.22.1"
|
|
10
10
|
|
|
11
11
|
# Block CG on matrix-free operators, low-rank preconditioner, SLQ log-det (#97)
|
|
12
12
|
from .block import (
|
|
@@ -638,6 +638,16 @@ def pivoted_lowrank_preconditioner(
|
|
|
638
638
|
pass the kernel diagonal and rows, and the noise variance as ``shift``.
|
|
639
639
|
Use the result as ``M=`` in ``cg_block``; its ``logdet()`` and
|
|
640
640
|
``sample()`` serve preconditioned ``slq_logdet``.
|
|
641
|
+
|
|
642
|
+
float64: L is built in float64 on the host, but it is only as accurate
|
|
643
|
+
as the rows ``rows_fn`` returns, and the library cannot see inside the
|
|
644
|
+
callable. On Trn2 a device-side gather of float64 (``K[idx]``,
|
|
645
|
+
``index_select``, ``torch.cat``) rounds to fp32 (relative error about
|
|
646
|
+
3.6e-8), so a ``rows_fn`` that gathers rows from a float64 K resident on
|
|
647
|
+
the ``neuron`` device gives a preconditioner accurate to about 2e-8, not
|
|
648
|
+
about 1e-15. For float64, keep K (or whatever data ``rows_fn`` reads) on
|
|
649
|
+
the host. Plain copies (``.to``, ``.clone()``, ``.contiguous()``, basic
|
|
650
|
+
indexing) are exact.
|
|
641
651
|
"""
|
|
642
652
|
L = pivoted_cholesky(diag_fn, rows_fn, rank, tol=tol)
|
|
643
653
|
return PivotedLowRankPreconditioner(L, shift, apply=apply)
|
|
@@ -14,6 +14,8 @@ For SCF:
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
+
import warnings
|
|
18
|
+
|
|
17
19
|
import torch
|
|
18
20
|
|
|
19
21
|
from .nki.dispatch import _fp64_host_guard
|
|
@@ -569,6 +571,32 @@ def solve(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor:
|
|
|
569
571
|
return _restore(X, orig)
|
|
570
572
|
|
|
571
573
|
|
|
574
|
+
def _warn_ambiguous_rhs(A: torch.Tensor, B: torch.Tensor) -> None:
|
|
575
|
+
"""FutureWarning for solve_spd's ambiguous B (#79); the reading switches in 0.23.0.
|
|
576
|
+
|
|
577
|
+
No dedup of its own: Python's default filter shows a FutureWarning once
|
|
578
|
+
per call site, and ``stacklevel`` points at the caller of ``solve_spd``
|
|
579
|
+
(through the ``_fp64_host_guard`` wrapper).
|
|
580
|
+
"""
|
|
581
|
+
n = A.shape[-1]
|
|
582
|
+
if A.dim() == 3:
|
|
583
|
+
shared = "or B.unsqueeze(-3) to broadcast one shared (n, k) matrix (today's result)"
|
|
584
|
+
else:
|
|
585
|
+
shared = (
|
|
586
|
+
"or B.unsqueeze(-3) to broadcast each (n, k) matrix over A's last batch dim; "
|
|
587
|
+
"B.unsqueeze(0) gives today's result"
|
|
588
|
+
)
|
|
589
|
+
warnings.warn(
|
|
590
|
+
f"trnsolver solve_spd: B of shape {tuple(B.shape)} equals A.shape[:-1] and A's last "
|
|
591
|
+
f"batch dim equals n = {n}, so B is ambiguous. It is read as (*, n, k) "
|
|
592
|
+
"right-hand-side matrices broadcast over A's batch; from trnsolver 0.23.0 it is "
|
|
593
|
+
"read as a batch of vectors, as torch.linalg.solve does (trnsci/trnsolver#79). "
|
|
594
|
+
f"To be explicit, pass B.unsqueeze(-1) for a batch of vectors, {shared}.",
|
|
595
|
+
FutureWarning,
|
|
596
|
+
stacklevel=4,
|
|
597
|
+
)
|
|
598
|
+
|
|
599
|
+
|
|
572
600
|
@_fp64_host_guard("solve_spd")
|
|
573
601
|
def solve_spd(
|
|
574
602
|
A: torch.Tensor,
|
|
@@ -583,9 +611,19 @@ def solve_spd(
|
|
|
583
611
|
A: SPD matrix (n, n), or a batch (*, n, n).
|
|
584
612
|
B: Right-hand side (n,) or (n, k); for a batched A also (*, n, k),
|
|
585
613
|
or a batch of vectors (*, n) with ``B.shape == A.shape[:-1]``
|
|
586
|
-
(as ``torch.linalg.solve``; #79).
|
|
587
|
-
|
|
588
|
-
|
|
614
|
+
(as ``torch.linalg.solve``; #79).
|
|
615
|
+
|
|
616
|
+
Deprecated: when the last batch dim of A equals n (A
|
|
617
|
+
``(*, n, n, n)``, B ``(*, n, n)``), such a B is ambiguous. It is
|
|
618
|
+
still read as (*, n, k) right-hand-side matrices broadcast over
|
|
619
|
+
A's batch, with a ``FutureWarning``; from 0.23.0 it is read as a
|
|
620
|
+
batch of vectors, as ``torch.linalg.solve`` does. Be explicit:
|
|
621
|
+
``B.unsqueeze(-1)`` for a batch of vectors (result
|
|
622
|
+
``(*, n, n, 1)``), or ``B.unsqueeze(-3)`` to broadcast one shared
|
|
623
|
+
right-hand-side matrix over A's last batch dim. For a 3-D A,
|
|
624
|
+
``B.unsqueeze(-3)`` is today's result; with more batch dims,
|
|
625
|
+
``B.unsqueeze(0)`` is. Both explicit forms mean the same in every
|
|
626
|
+
release.
|
|
589
627
|
iterative_refinement: If True, perform one step of iterative
|
|
590
628
|
refinement: compute the residual R = B - A @ X and apply a
|
|
591
629
|
second Cholesky solve for the correction dX = chol_solve(R).
|
|
@@ -601,9 +639,10 @@ def solve_spd(
|
|
|
601
639
|
n = A.shape[-1]
|
|
602
640
|
# A batch of vectors, B (*, n) with B.shape == A.shape[:-1] (#79). Only
|
|
603
641
|
# where B cannot be read as (*, n, k), so existing callers are unchanged.
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
642
|
+
vec_shaped = B.dim() >= 2 and B.dim() == A.dim() - 1 and B.shape == A.shape[:-1]
|
|
643
|
+
squeeze = B.dim() == 1 or (vec_shaped and B.shape[-2] != n)
|
|
644
|
+
if vec_shaped and B.shape[-2] == n:
|
|
645
|
+
_warn_ambiguous_rhs(A, B)
|
|
607
646
|
if squeeze:
|
|
608
647
|
B = B.unsqueeze(-1)
|
|
609
648
|
# A = L L^H: back substitution with L^H (``.mH``: conjugate for complex,
|
|
@@ -635,7 +674,10 @@ def inv_spd(A: torch.Tensor) -> torch.Tensor:
|
|
|
635
674
|
"""
|
|
636
675
|
A, orig = _to_fp32(A)
|
|
637
676
|
n = A.shape[-1]
|
|
638
|
-
|
|
677
|
+
# The identity at A's full shape: for a batch dim equal to n a bare (n, n)
|
|
678
|
+
# eye is the ambiguous B of solve_spd (#79).
|
|
679
|
+
eye = torch.eye(n, dtype=A.dtype, device=A.device).expand(A.shape)
|
|
680
|
+
result = solve_spd(A, eye)
|
|
639
681
|
return _restore(result, orig)
|
|
640
682
|
|
|
641
683
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trnsolver
|
|
3
|
-
Version: 0.22.
|
|
3
|
+
Version: 0.22.1
|
|
4
4
|
Summary: Linear solvers and eigendecomposition for AWS Trainium via NKI
|
|
5
5
|
Author-email: Scott Friedman <scttfrdmn@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -30,7 +30,7 @@ Provides-Extra: dev
|
|
|
30
30
|
Requires-Dist: pytest<9,>=7.0; extra == "dev"
|
|
31
31
|
Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
|
|
32
32
|
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
33
|
-
Requires-Dist: ruff
|
|
33
|
+
Requires-Dist: ruff==0.17.3; extra == "dev"
|
|
34
34
|
Requires-Dist: scipy>=1.11; extra == "dev"
|
|
35
35
|
Requires-Dist: trnblas>=0.9; extra == "dev"
|
|
36
36
|
Requires-Dist: trntensor>=0.24; extra == "dev"
|
|
@@ -255,12 +255,14 @@ CPU baselines (torch.linalg, scipy.linalg, trnsolver PyTorch path) run on every
|
|
|
255
255
|
|
|
256
256
|
## Known issues in earlier releases
|
|
257
257
|
|
|
258
|
-
Silent wrong-result bugs fixed in the 2026-10-31 to 2026-11-
|
|
258
|
+
Silent wrong-result bugs fixed in the 2026-10-31 to 2026-11-04 releases. Details are in the [CHANGELOG](CHANGELOG.md).
|
|
259
259
|
|
|
260
260
|
| Bug | Affected | Fixed in |
|
|
261
261
|
|---|---|---|
|
|
262
262
|
| `eigh` on the NKI Householder path (`TRNSOLVER_REQUIRE_NKI=1` or a non-native NKI device): float64 input gave garbage results, and n = 1 returned `(1, 1)` eigenvalues; `eigh_generalized` inherited both (#83) | through 0.20.0 (n = 1 shape: 0.4.0–0.20.0) | 0.21.0 |
|
|
263
263
|
| Complex Hermitian and batched input to `cholesky(upper=True)`, `solve_spd`, `inv_spd`, `inv_sqrt_spd`, `eigh_generalized`, `eigh_randomized`, `pinv` and `ssor_preconditioner` used `.T` instead of `.mH` (#64) | every release through 0.20.0 (`pinv` since 0.5.0, `ssor_preconditioner` since 0.8.0) | 0.21.0 |
|
|
264
|
+
| `cg` dropped the imaginary part of complex input (unconjugated inner products cast to real), so a complex Hermitian system returned a wrong `x` with only a `UserWarning`; a complex `A` with a real `b` also lost `A`'s imaginary part (#100) | every release through 0.21.0 | 0.22.0 |
|
|
265
|
+
| `cg` gave a wrong gradient with respect to `A` (it differentiated a fixed polynomial in `A`; rel. err 0.55 at n = 5), and `schur` returned `Q`, `T` that silently contributed zero gradient (#76) | every release through 0.21.0 | 0.22.0 |
|
|
264
266
|
|
|
265
267
|
## Related projects in the trnsci suite
|
|
266
268
|
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|