trnsolver 0.22.1__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.
- {trnsolver-0.22.1 → trnsolver-0.24.0}/CHANGELOG.md +122 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/CONTRIBUTING.md +11 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/PKG-INFO +1 -1
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/api/factor.md +11 -13
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/api/iterative.md +28 -5
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/api/nki.md +1 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/pyproject.toml +2 -2
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/bench_gp_precond.py +104 -15
- trnsolver-0.24.0/scripts/conformance_expect.py +65 -0
- trnsolver-0.24.0/scripts/probe_cg_reduction.py +219 -0
- trnsolver-0.24.0/tests/conftest.py +154 -0
- trnsolver-0.24.0/tests/test_block_neuron.py +246 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_cg_block.py +29 -0
- trnsolver-0.24.0/tests/test_cg_reduction.py +520 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_conformance.py +94 -8
- trnsolver-0.24.0/tests/test_device_known.py +76 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_factor.py +40 -38
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_kernel_dtype_guard.py +0 -2
- trnsolver-0.24.0/tests/test_psum_accumulate_lint.py +188 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_subspace.py +11 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/__init__.py +1 -1
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/block.py +254 -31
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/factor.py +12 -51
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/iterative.py +91 -21
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/nki/subspace.py +21 -17
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/subspace.py +11 -1
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver.egg-info/PKG-INFO +1 -1
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver.egg-info/SOURCES.txt +5 -0
- trnsolver-0.22.1/tests/conftest.py +0 -82
- trnsolver-0.22.1/tests/test_block_neuron.py +0 -135
- {trnsolver-0.22.1 → trnsolver-0.24.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/.github/pull_request_template.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/.github/workflows/ci.yml +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/.github/workflows/neuron.yml +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/.github/workflows/notify-umbrella.yml +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/.github/workflows/publish.yml +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/.gitignore +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/.pre-commit-config.yaml +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/CLAUDE.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/CODE_OF_CONDUCT.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/LICENSE +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/README.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/benchmarks/bench_cuda.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/benchmarks/bench_solver.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/benchmarks/conftest.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/api/eigen.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/architecture.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/aws_setup.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/benchmarks.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/developing_kernels.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/index.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/installation.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/docs/quickstart.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/examples/df_store.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/examples/scf_df_mp2.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/examples/scf_df_rhf.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/examples/scf_eigen.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/infra/terraform/README.md +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/infra/terraform/gpu.tf +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/infra/terraform/main.tf +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/mkdocs.yml +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/bench_eager_handle.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/bench_jacobi.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/bench_jacobi_multicore.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/bench_occupied_subspace.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/bench_scf.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/bench_scf_ladder.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/probe_large_n_split.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/run_cuda_tests.sh +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/run_neuron_tests.sh +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/run_simulator_tests.sh +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/scripts/stop_neuron_ci.sh +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/setup.cfg +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_bench_scf_ladder.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_compile.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_complex_rhs.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_dtype.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_eigen.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_eigh_cutover.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_eigh_neuron.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_hermitian_batch.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_iterative.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_iterative_autograd.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_iterative_rhs_scale.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_jacobi.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_jacobi_onezero_arg.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_native_dispatch.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_nki_compile.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_nki_native.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_nki_sim.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_nki_tail_audit.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_orthogonalize.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_scf_df_mp2.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_scf_df_rhf.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/tests/test_trace_cache_safety.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/_jacobi.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/eigen.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/nki/__init__.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/nki/_native.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/nki/dispatch.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/nki/eigh_pool.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/nki/jacobi.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver/orthogonalize.py +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver.egg-info/dependency_links.txt +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver.egg-info/requires.txt +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/trnsolver.egg-info/top_level.txt +0 -0
- {trnsolver-0.22.1 → trnsolver-0.24.0}/uv.lock +0 -0
|
@@ -7,6 +7,128 @@ 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-28
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Device conformance runs are signal-only (trnsci/trnsci#35).** On a
|
|
15
|
+
device run (`--backend nki --conformance-device neuron`), the known
|
|
16
|
+
platform-limit cases in `tests/test_conformance.py` are marked
|
|
17
|
+
`xfail(strict=False)` by category rules: `complex-linalg` (41 cases, #98)
|
|
18
|
+
and `device-fp64` (60 cases, #147, which takes over #144's
|
|
19
|
+
`test_gmres_truncated[2-2]` marker). CPU runs are unchanged and still run
|
|
20
|
+
every case. The run ends with a summary (passed, xfailed and XPASS by
|
|
21
|
+
category, NEW failures); `--conformance-json PATH` writes it as JSON, and
|
|
22
|
+
`scripts/conformance_expect.py` merges chunked runs and exits 1 on NEW
|
|
23
|
+
failures. Test-only; no library change.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **`subspace_filter_kernel` / `subspace_step_kernel` PSUM accumulation
|
|
28
|
+
groups now open with a matmul write (trnsci/trnsci#185).** The kernels
|
|
29
|
+
zeroed PSUM tiles with `nl.zeros(..., buffer=nl.psum)` (a memset) and then
|
|
30
|
+
accumulated into them with `nisa.nc_matmul(..., accumulate=True)`. The
|
|
31
|
+
`nc_matmul` docs make that undefined behaviour on NeuronCore-v3 (Trn2):
|
|
32
|
+
accumulating onto PSUM that a non-matmul instruction initialised is not
|
|
33
|
+
supported, and the first write must use `accumulate=False`. Device results
|
|
34
|
+
matched the references so far, but they relied on that behaviour. The five
|
|
35
|
+
sites (the on-chip `X Q` fold, the F-apply, the residual-norm reduction,
|
|
36
|
+
the Gram blocks and `E = Y - X M`) pass `accumulate=(j > 0)` over their
|
|
37
|
+
static loops, and their PSUM tiles are plain `nl.ndarray`s, so the
|
|
38
|
+
redundant memsets are gone. The two `matmul_kernel` variants in
|
|
39
|
+
`nki/dispatch.py` already wrote with `accumulate=False` and are unchanged.
|
|
40
|
+
Simulator outputs are bitwise equal to 0.23.0 at the test shapes. A new
|
|
41
|
+
static lint (`tests/test_psum_accumulate_lint.py`) fails when a zeroed
|
|
42
|
+
PSUM tile is a matmul accumulation target, or when a tile is only ever
|
|
43
|
+
accumulated into.
|
|
44
|
+
|
|
45
|
+
## [0.23.0] — 2026-11-10
|
|
46
|
+
|
|
47
|
+
Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
|
|
48
|
+
|
|
49
|
+
Headline: `solve_spd` reads `B.shape == A.shape[:-1]` as a batch of vectors in every case, as `torch.linalg.solve` does (#130, completes #79; breaking for the formerly ambiguous shape). `cg`, `gmres` and `cg_block` reductions over n no longer depend on the LNC split (#128). `pivoted_cholesky(pad_rows=True)` keeps a device `rows_fn` to a few shapes (trnsci/trnsci#109). `occupied_subspace` raises on complex F (#132).
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
|
|
53
|
+
- **`pivoted_cholesky(..., pad_rows=True)`: a few data-independent `rows_fn`
|
|
54
|
+
shapes (trnsci/trnsci#109).** With `block` > 1, the number of pivots a
|
|
55
|
+
round accepts depends on the values of K, so a device `rows_fn` (one NEFF
|
|
56
|
+
per shape) compiled in almost every round. A compile-only pre-warm could
|
|
57
|
+
not reach those shapes, because the pivots depend on the data. The GP n = 1e6
|
|
58
|
+
build hit 57 compiles in 63 calls and went from 143 s to 207 s.
|
|
59
|
+
`pad_rows=True` pads each call to a power of two, capped at `block`, by
|
|
60
|
+
repeating the last index, and drops the extra rows. That leaves at most
|
|
61
|
+
⌈log₂ block⌉ + 1 shapes. The factor is bitwise unchanged. The default is
|
|
62
|
+
False, so `rows_fn` callers that need distinct indices are unaffected.
|
|
63
|
+
Trn2, n = 1e5, cold NEFF cache, one logical core: 21 → 3 shapes, rows
|
|
64
|
+
83.6 → 16.5 s, build 100.3 → 29.1 s.
|
|
65
|
+
- **`scripts/bench_gp_precond.py`:** `--pad-rows` (on by default), `--prewarm`
|
|
66
|
+
(compiles every padded shape first, which also works in compile-only mode),
|
|
67
|
+
and `host_s`, the host fp64 part of `cholesky_s`. `cholesky_s` includes the
|
|
68
|
+
device rows (`rows_s`). Read that way, the window-5 "cholesky 150 s against
|
|
69
|
+
90 s" was 82 s against 80 s on the host, plus the cold compiles.
|
|
70
|
+
|
|
71
|
+
### Changed
|
|
72
|
+
|
|
73
|
+
- **`solve_spd` reads an ambiguous `B` as a batch of vectors, as
|
|
74
|
+
`torch.linalg.solve` does (#130, completes #79). Breaking for callers who
|
|
75
|
+
pass that shape.** With A `(*, n, n, n)` and B `(*, n, n)` (`B.shape ==
|
|
76
|
+
A.shape[:-1]` and A's last batch dim equals n), `B` is now `(*, n)`
|
|
77
|
+
vectors and the result is `(*, n, n)`. 0.22.1 and earlier read it as
|
|
78
|
+
`(*, n, k)` matrices broadcast over A's batch and returned `(*, n, n, n)`;
|
|
79
|
+
0.22.1 warned with a `FutureWarning` (#131), which is removed. For the old
|
|
80
|
+
result, pass `B.unsqueeze(-3)` for a 3-D A, or `B.unsqueeze(0)` in
|
|
81
|
+
general; both mean the same in every release. The same holds with
|
|
82
|
+
`iterative_refinement=True`. The conformance case `solve_spd_vec-batch{N}`
|
|
83
|
+
passes (it was `xfail(strict=True)`).
|
|
84
|
+
|
|
85
|
+
### Fixed
|
|
86
|
+
|
|
87
|
+
- **`cg` and `gmres` no longer depend on the LNC split (#128).** They take
|
|
88
|
+
`reduction=` as `cg_block` does: `"pairwise"` (the default for both),
|
|
89
|
+
`"host64"` or `"device"` (the previous code). `None` reads
|
|
90
|
+
`TRNSOLVER_CG_REDUCTION` for `cg` and `TRNSOLVER_GMRES_REDUCTION` for
|
|
91
|
+
`gmres`. On the device, `rᴴz`, `pᴴAp`, the norms and the Gram-Schmidt
|
|
92
|
+
dots are now elementwise products, folded by the same fixed tree and
|
|
93
|
+
finished in float64 on the host. `gmres` also forms `x + V y` as
|
|
94
|
+
fixed-order axpys. Host tensors keep their float64 products. Trn2, LNC=2,
|
|
95
|
+
n = 1e5, the GP `KernelOperator` on one vector (289 ms per call):
|
|
96
|
+
`cg` goes from 299.7 to 299.9 ms per iteration (+0.1%), and `gmres` from
|
|
97
|
+
375.9 to 337.6 ms (−10%, because the old path cast to float64 on the
|
|
98
|
+
device for every dot).
|
|
99
|
+
- **`cg_block` no longer depends on the LNC split (#128).** Device aten
|
|
100
|
+
reductions over n (`sum`, `vector_norm`, matmul) add in an order that
|
|
101
|
+
depends on how the work is split across logical cores. On Trn2 at
|
|
102
|
+
n = 1e5, R = 33, `cg_block`'s inner products differed by 4.9e-4 between
|
|
103
|
+
LNC=1 and LNC=2, and the GP posterior mean by 4.5e-4. The new
|
|
104
|
+
`reduction=` argument (or `TRNSOLVER_CG_REDUCTION`) chooses how the inner
|
|
105
|
+
products and norms reduce over n:
|
|
106
|
+
- `"pairwise"` (the new default): zero-pad the rows to m · 2^L (m ≤ 64),
|
|
107
|
+
fold with L elementwise adds of contiguous halves on the device (a fixed
|
|
108
|
+
tree that depends on n only), then sum the m leaves in float64 on the
|
|
109
|
+
host. It is about 2x more accurate than the device sum.
|
|
110
|
+
- `"host64"`: copy the whole (n, R) product to the host and reduce it in
|
|
111
|
+
float64. This is the most accurate option, at one (n, R) D2H per
|
|
112
|
+
reduction.
|
|
113
|
+
- `"device"`: the previous device sums. They are fastest, but
|
|
114
|
+
LNC-dependent; this mode is kept for performance comparison.
|
|
115
|
+
|
|
116
|
+
The residual norm and rᵀz now share one fold, so the default costs two
|
|
117
|
+
small host syncs per iteration. `PivotedLowRankPreconditioner(apply=
|
|
118
|
+
"projected")` takes the same `reduction=` for its two Qᵀ V reductions
|
|
119
|
+
(#117). With `"pairwise"`, it forms them as 128-row block products in one
|
|
120
|
+
bmm, folded in the same fixed order. `pivoted_lowrank_preconditioner` and
|
|
121
|
+
`slq_logdet` pass `reduction` through. The float64 policy and
|
|
122
|
+
`TRNSOLVER_REQUIRE_NKI` behaviour are unchanged.
|
|
123
|
+
|
|
124
|
+
- **`occupied_subspace` with a complex Hermitian F raises `TypeError` (#132).**
|
|
125
|
+
0.21.0 through 0.22.1 cast a complex64 / complex128 F to float32, dropping
|
|
126
|
+
its imaginary part, and returned the occupied subspace of `F.real` with no
|
|
127
|
+
error or warning (at n = 12: lowest eigenvalue -7.50 against the right
|
|
128
|
+
-7.14). The filtered subspace iteration is real, so complex F now raises;
|
|
129
|
+
use `eigh` for a complex Hermitian F. Integer and half-precision F are
|
|
130
|
+
still upcast to float32.
|
|
131
|
+
|
|
10
132
|
## [0.22.1] — 2026-11-07
|
|
11
133
|
|
|
12
134
|
Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
|
|
@@ -85,6 +85,17 @@ Before opening a PR:
|
|
|
85
85
|
- [ ] If you added a public symbol, the project's `docs/api.md` lists it
|
|
86
86
|
- [ ] PR description says *what* changed and *why*, not just *what*
|
|
87
87
|
|
|
88
|
+
## Releasing
|
|
89
|
+
|
|
90
|
+
`.github/workflows/publish.yml` publishes to PyPI (trusted publishing) when a GitHub Release is published. A tag containing `-` (`vX.Y.Z-rc1`) goes to TestPyPI.
|
|
91
|
+
|
|
92
|
+
- [ ] Release PR (`release: vX.Y.Z`): bump `version` in `pyproject.toml` and `__version__` in `trnsolver/__init__.py`, and move the `[Unreleased]` CHANGELOG entries under `## [X.Y.Z] - YYYY-MM-DD`.
|
|
93
|
+
- [ ] After the merge, run `gh release create vX.Y.Z --target <merge sha>`, then confirm the publish run and the new version on PyPI.
|
|
94
|
+
- [ ] **Update umbrella docs/extras** in one [trnsci/trnsci](https://github.com/trnsci/trnsci) PR:
|
|
95
|
+
- if users should require this release (always for a fix to silent wrong results), bump `trnsolver` in the umbrella `pyproject.toml` `[solver]` and `[all]` extras, and cut a `trnsci` meta-package release;
|
|
96
|
+
- update the `[[described:trnsolver=X.Y.Z]]` rows in `docs/roadmap.md` and `docs/nki_validation_status.md`, with the [#35](https://github.com/trnsci/trnsci/issues/35) Trn2 validation link;
|
|
97
|
+
- check that `python scripts/check_docs_drift.py` exits 0. The weekly docs-drift workflow opens a `docs-stale` issue for anything missed.
|
|
98
|
+
|
|
88
99
|
## Issues
|
|
89
100
|
|
|
90
101
|
Label each issue one of: `bug`, `feature`, `question`, `docs`, `infra`. Bugs include repro steps and expected-vs-actual output. Features describe the use case.
|
|
@@ -28,23 +28,21 @@ Solves `A X = B` via Cholesky — faster than `solve` when `A` is SPD.
|
|
|
28
28
|
`B` is `(n,)`, `(*, n, k)`, or a batch of vectors `(*, n)` with
|
|
29
29
|
`B.shape == A.shape[:-1]`, as `torch.linalg.solve` reads it.
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
`(*, n, n)`;
|
|
38
|
-
|
|
31
|
+
This includes A `(*, n, n, n)` with B `(*, n, n)`, where A's last batch dim
|
|
32
|
+
equals `n`: `B` is a batch of vectors and `X` is `(*, n, n)`, as in
|
|
33
|
+
`torch.linalg.solve`.
|
|
34
|
+
|
|
35
|
+
!!! note "Changed in 0.23.0 (#130)"
|
|
36
|
+
trnsolver 0.22.1 and earlier read that `B` as `(*, n, k)` right-hand-side
|
|
37
|
+
matrices broadcast over A's batch (result `(*, n, n, n)`; 0.22.1 warned,
|
|
38
|
+
#79). For that result, pass the explicit form, which means the same in
|
|
39
|
+
every release:
|
|
39
40
|
|
|
40
41
|
```python
|
|
41
|
-
X = trnsolver.solve_spd(A, B.unsqueeze(-
|
|
42
|
-
X = trnsolver.solve_spd(A, B.unsqueeze(
|
|
42
|
+
X = trnsolver.solve_spd(A, B.unsqueeze(-3)) # 3-D A: one shared (n, k) right-hand side
|
|
43
|
+
X = trnsolver.solve_spd(A, B.unsqueeze(0)) # any A: the 0.22.1 reading
|
|
43
44
|
```
|
|
44
45
|
|
|
45
|
-
For a 3-D `A`, `B.unsqueeze(-3)` is the current result; with more batch
|
|
46
|
-
dims, `B.unsqueeze(0)` is.
|
|
47
|
-
|
|
48
46
|
## `inv_spd(A)`
|
|
49
47
|
|
|
50
48
|
Returns `A⁻¹` for SPD `A` via Cholesky.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Both solvers operate on the host (PyTorch). The matvec / inner-product hot path would benefit from NKI Level 1/2 kernels in `trnblas`, but the iteration loop itself stays on CPU.
|
|
4
4
|
|
|
5
|
-
## `cg(A, b, x0=None, tol=1e-6, maxiter=1000, M=None)`
|
|
5
|
+
## `cg(A, b, x0=None, tol=1e-6, maxiter=1000, M=None, *, reduction=None)`
|
|
6
6
|
|
|
7
7
|
Conjugate Gradient for SPD `A`. `A` may be a tensor or a callable `A(x) → A @ x`.
|
|
8
8
|
|
|
@@ -10,6 +10,7 @@ Conjugate Gradient for SPD `A`. `A` may be a tensor or a callable `A(x) → A @
|
|
|
10
10
|
- **`tol`** — relative residual tolerance
|
|
11
11
|
- **`maxiter`** — iteration cap
|
|
12
12
|
- **`M`** — optional preconditioner (tensor or callable applying `M⁻¹`)
|
|
13
|
+
- **`reduction`** — how `rᴴz`, `pᴴAp` and `‖r‖` reduce over n (#128): `"pairwise"` (default), `"host64"` or `"device"`, as in [`cg_block`](#cg_blocka-b-mnone--tol1e-6-maxiternone-check_every10-x0none-return_coeffsfalse-reductionnone). `None` reads `TRNSOLVER_CG_REDUCTION`. Host tensors are multiplied in float64 in every mode, as before. On the device the product is in the working dtype, then folded and finished in float64 on the host.
|
|
13
14
|
|
|
14
15
|
Returns `(x, iters, residual)`.
|
|
15
16
|
|
|
@@ -17,10 +18,21 @@ Returns `(x, iters, residual)`.
|
|
|
17
18
|
x, iters, residual = trnsolver.cg(A_spd, b, tol=1e-8)
|
|
18
19
|
```
|
|
19
20
|
|
|
20
|
-
## `gmres(A, b, x0=None, tol=1e-6, maxiter=200, restart=30)`
|
|
21
|
+
## `gmres(A, b, x0=None, tol=1e-6, maxiter=200, restart=30, *, reduction=None)`
|
|
21
22
|
|
|
22
23
|
GMRES for general (non-symmetric) systems. Same calling convention as `cg`. `restart` controls the Krylov subspace size before restart.
|
|
23
24
|
|
|
25
|
+
`reduction` (#128) applies to the modified Gram-Schmidt inner products and the norms: `"pairwise"` (default), `"host64"` or `"device"`. With `"pairwise"` / `"host64"`, the update `x + V y` is formed as fixed-order axpys instead of a matmul. `None` reads `TRNSOLVER_GMRES_REDUCTION`.
|
|
26
|
+
|
|
27
|
+
Cost on Trn2 (LNC=2, one logical core, n = 1e5, the GP exemplar's `KernelOperator` applied to one vector, 289 ms per call, 60 iterations):
|
|
28
|
+
|
|
29
|
+
| solver | `device` ms/iter | `pairwise` ms/iter | `host64` ms/iter |
|
|
30
|
+
|---|---|---|---|
|
|
31
|
+
| `cg` | 299.7 | 299.9 (+0.1%) | 296.7 |
|
|
32
|
+
| `gmres` (restart 30) | 375.9 | 337.6 (−10%) | 324.6 |
|
|
33
|
+
|
|
34
|
+
`gmres` gets faster because the old path cast both vectors to float64 on the device for every Gram-Schmidt dot.
|
|
35
|
+
|
|
24
36
|
```python
|
|
25
37
|
x, iters, residual = trnsolver.gmres(A, b, tol=1e-6)
|
|
26
38
|
```
|
|
@@ -38,9 +50,19 @@ Raises `ValueError` if any diagonal entry is within `1e-15` of zero. More-capabl
|
|
|
38
50
|
|
|
39
51
|
## Block CG on matrix-free operators (#97)
|
|
40
52
|
|
|
41
|
-
### `cg_block(A, B, M=None, *, tol=1e-6, maxiter=None, check_every=10, X0=None, return_coeffs=False)`
|
|
53
|
+
### `cg_block(A, B, M=None, *, tol=1e-6, maxiter=None, check_every=10, X0=None, return_coeffs=False, reduction=None)`
|
|
54
|
+
|
|
55
|
+
Column-batched preconditioned CG for SPD `A` with an `(n, R)` right-hand side (or `(n,)`). `A` and `M` are callables on `(n, R)` blocks, or tensors. Each iteration makes **one** call `A(P)` on the whole block. Converged columns freeze, but the full block is still passed in, so every call has the same shape. Convergence is per column, `‖rⱼ‖ ≤ tol·‖bⱼ‖`. The stopping test reads back to the host only every `check_every` iterations.
|
|
56
|
+
|
|
57
|
+
`reduction` sets how the inner products and norms reduce over n (#128). `None` reads `TRNSOLVER_CG_REDUCTION`.
|
|
58
|
+
|
|
59
|
+
| `reduction` | How | LNC=1 vs LNC=2 | Cost |
|
|
60
|
+
|---|---|---|---|
|
|
61
|
+
| `"pairwise"` (default) | zero-pad to m · 2^L rows (m ≤ 64), L elementwise adds of contiguous halves on the device, then the m leaves summed in float64 on the host | bitwise equal | two small D2H syncs per iteration |
|
|
62
|
+
| `"host64"` | the whole (n, R) product is copied to the host and reduced in float64 | bitwise equal; most accurate | one (n, R) D2H per reduction |
|
|
63
|
+
| `"device"` | device `sum` / `vector_norm` (the previous behaviour) | differs (5e-4 relative at n = 1e5) | fastest; for comparison |
|
|
42
64
|
|
|
43
|
-
|
|
65
|
+
Device reductions over n add in an order that depends on how the compiler splits the work across logical cores. Elementwise ops do not. So `"pairwise"` and `"host64"` give the same bits at any LNC, provided the operator `A` (and `M`) does too.
|
|
44
66
|
|
|
45
67
|
Returns `(X, info)`. `info` has these keys:
|
|
46
68
|
|
|
@@ -115,7 +137,8 @@ How `"projected"` works:
|
|
|
115
137
|
- It applies `Q (Σ² + sI)⁻¹ QᵀV + (I − QQᵀ)V/s` with the projection done twice.
|
|
116
138
|
- One pass leaves an error of about u·√k·‖V‖ along Q, which the 1/s weight amplifies. That is the `"native"` failure. The second pass removes that error.
|
|
117
139
|
- On CPU fp32 it takes the same CG iteration counts as `"host64"` on the GP cases that stall `"native"`.
|
|
140
|
+
- Its two QᵀV products reduce over n, so they take `reduction=` as `cg_block` does (`PivotedLowRankPreconditioner(L, shift, apply="projected", reduction=None)`; `None` reads `TRNSOLVER_CG_REDUCTION`). With `"pairwise"`, QᵀV is formed as 128-row block products `Q_iᵀ V_i` in one bmm, then the blocks are folded as above and finished in float64 on the host (#128).
|
|
118
141
|
|
|
119
|
-
### `lanczos_tridiag_from_cg(alpha, beta, col_iterations=None)`, `slq_logdet(A, n, num_probes=32, num_iters=50, generator=None, M=None, *, dtype=torch.float32, device=None, tol=1e-10)`
|
|
142
|
+
### `lanczos_tridiag_from_cg(alpha, beta, col_iterations=None)`, `slq_logdet(A, n, num_probes=32, num_iters=50, generator=None, M=None, *, dtype=torch.float32, device=None, tol=1e-10, reduction=None)`
|
|
120
143
|
|
|
121
144
|
`lanczos_tridiag_from_cg` builds the per-column Lanczos tridiagonals from CG coefficients. `slq_logdet` gives the stochastic Lanczos quadrature estimate of `log det(A)` and returns `(estimate, info)`. `info` has `std_error`, `quadratures` and `cg_info`.
|
|
@@ -81,6 +81,7 @@ The same rule holds across the trnsci suite (trnsci/trnsolver#89).
|
|
|
81
81
|
| `TRNSOLVER_REQUIRE_NKI=1` | Kernel-path failures re-raise instead of silently falling back to PyTorch, and inputs no kernel takes (float64, integer, bool) raise `NotImplementedError` (see [Precision and dtypes](#precision-and-dtypes)). Used by the validation suite to catch silent kernel breakage. |
|
|
82
82
|
| `TRNSOLVER_FP64_ON_DEVICE=1` | Under backend `"auto"`, float64 / complex128 operands on the `neuron` device stay there and compute with device aten at fp32 precision, instead of on the host at float64 (see [Precision and dtypes](#precision-and-dtypes)). For callers who prefer speed. Read at import. |
|
|
83
83
|
| `TRNSOLVER_EIGH_NKI_MIN_N=<n>` | On the native `neuron` device (and for host tensors on a TorchNeuron host), `eigh` uses `torch.linalg.eigh` for matrices with fewer than `n` rows and the NKI path otherwise. The NKI path is single-tile (n ≤ 128) and falls back to `torch.linalg.eigh` above that. Default 512; `0` always uses NKI. Ignored when `TRNSOLVER_REQUIRE_NKI=1`. (#42) |
|
|
84
|
+
| `TRNSOLVER_CG_REDUCTION=pairwise\|host64\|device` | How `cg_block` and the projected preconditioner reduce over n when `reduction=` is not passed (#128). `pairwise` (default) and `host64` give the same bits at LNC=1 and LNC=2; `device` is the previous device-sum path, which is faster but LNC-dependent. See [`cg_block`](iterative.md). |
|
|
84
85
|
| `TRNSOLVER_EIGH_METHOD=auto\|jacobi` | `eigh` method when `method=` is not passed. `jacobi` selects the batched Jacobi solver (#48). Default `auto`. |
|
|
85
86
|
| `TRNSOLVER_JACOBI_GROUP=<g>` | Jacobi kernel: tiles per launch (rounded down to a power of two). Default 128 (n ≤ 32: scalar kernel; 33 ≤ n ≤ 128: block kernel), split across the two physical cores of a logical NeuronCore. |
|
|
86
87
|
| `TRNSOLVER_JACOBI_CHAINS=<c>` | Jacobi kernel: independent dependency chains per step. Default 8 for n ≤ 32, 2 for the block kernel. |
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools>=
|
|
2
|
+
requires = ["setuptools>=77.0", "setuptools-scm>=8.0"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "trnsolver"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.24.0"
|
|
8
8
|
description = "Linear solvers and eigendecomposition for AWS Trainium via NKI"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -6,6 +6,8 @@ Needs trnsparse (>= the #104 multicore kernel_matmul).
|
|
|
6
6
|
|
|
7
7
|
python scripts/bench_gp_precond.py build --n 1e5 [--seq] # preconditioner build time
|
|
8
8
|
python scripts/bench_gp_precond.py conv --n 5e4 # CG: host64 vs projected
|
|
9
|
+
python scripts/bench_gp_precond.py conv --n 1e5 --applies projected \
|
|
10
|
+
--reductions device,pairwise,host64 --L-cache L.pt --save-dir DIR # #128
|
|
9
11
|
python scripts/bench_gp_precond.py gp --n 1e6 # GP posterior mean (C3)
|
|
10
12
|
|
|
11
13
|
--cpu runs the same on the CPU (trnsparse pytorch backend).
|
|
@@ -16,8 +18,10 @@ Output is one JSON line per measurement (prefix RESULT) plus human-readable line
|
|
|
16
18
|
from __future__ import annotations
|
|
17
19
|
|
|
18
20
|
import argparse
|
|
21
|
+
import hashlib
|
|
19
22
|
import json
|
|
20
23
|
import math
|
|
24
|
+
import os
|
|
21
25
|
import time
|
|
22
26
|
|
|
23
27
|
import torch
|
|
@@ -95,6 +99,7 @@ class DeviceRows:
|
|
|
95
99
|
self.device = device
|
|
96
100
|
self.calls = self.rows = 0
|
|
97
101
|
self.t_rows = 0.0
|
|
102
|
+
self.shapes = set()
|
|
98
103
|
|
|
99
104
|
def rows_fn(self, idx):
|
|
100
105
|
t = time.perf_counter()
|
|
@@ -104,6 +109,7 @@ class DeviceRows:
|
|
|
104
109
|
self.t_rows += time.perf_counter() - t
|
|
105
110
|
self.calls += 1
|
|
106
111
|
self.rows += idx.numel()
|
|
112
|
+
self.shapes.add(idx.numel())
|
|
107
113
|
return out
|
|
108
114
|
|
|
109
115
|
def sub_fn(self, idx):
|
|
@@ -112,7 +118,21 @@ class DeviceRows:
|
|
|
112
118
|
return trnsparse.kernel_matmul_reference(Xi, Xi, eye, "rbf", LS, OS)
|
|
113
119
|
|
|
114
120
|
|
|
115
|
-
def
|
|
121
|
+
def prewarm(X, device, block):
|
|
122
|
+
"""Compile every rows_fn shape pad_rows can produce (powers of two up to block).
|
|
123
|
+
|
|
124
|
+
The shapes don't depend on the data, so this also works in TorchNeuron
|
|
125
|
+
compile-only mode, unlike a pre-warm build (trnsci/trnsci#109).
|
|
126
|
+
"""
|
|
127
|
+
dr = DeviceRows(X, device)
|
|
128
|
+
t0 = time.perf_counter()
|
|
129
|
+
sizes = sorted({min(1 << b, block) for b in range(max(1, block).bit_length())})
|
|
130
|
+
for j in sizes:
|
|
131
|
+
dr.rows_fn(torch.arange(j))
|
|
132
|
+
return time.perf_counter() - t0, sizes
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def build(X, op, device, *, rank, block, relax, apply, seq=False, pad_rows=True):
|
|
116
136
|
t = {}
|
|
117
137
|
t0 = time.perf_counter()
|
|
118
138
|
if seq:
|
|
@@ -121,10 +141,19 @@ def build(X, op, device, *, rank, block, relax, apply, seq=False):
|
|
|
121
141
|
else:
|
|
122
142
|
dr = DeviceRows(X, device)
|
|
123
143
|
L = trnsolver.pivoted_cholesky(
|
|
124
|
-
op.diag,
|
|
144
|
+
op.diag,
|
|
145
|
+
dr.rows_fn,
|
|
146
|
+
rank,
|
|
147
|
+
block=block,
|
|
148
|
+
relax=relax,
|
|
149
|
+
sub_fn=dr.sub_fn,
|
|
150
|
+
pad_rows=pad_rows,
|
|
125
151
|
)
|
|
126
|
-
info = dict(calls=dr.calls, rows=dr.rows, rows_s=round(dr.t_rows, 2))
|
|
152
|
+
info = dict(calls=dr.calls, rows=dr.rows, shapes=len(dr.shapes), rows_s=round(dr.t_rows, 2))
|
|
153
|
+
# cholesky_s includes the device rows (rows_s); host_s is the host fp64 part alone.
|
|
127
154
|
t["cholesky_s"] = time.perf_counter() - t0
|
|
155
|
+
if info["rows_s"] is not None:
|
|
156
|
+
t["host_s"] = t["cholesky_s"] - info["rows_s"]
|
|
128
157
|
t0 = time.perf_counter()
|
|
129
158
|
Ld = L.to(device=device, dtype=torch.float32)
|
|
130
159
|
M = trnsolver.PivotedLowRankPreconditioner(Ld, op.noise, apply=apply)
|
|
@@ -152,12 +181,21 @@ def cmd_build(a):
|
|
|
152
181
|
op = trnsparse.KernelOperator(X, "rbf", LS, OS, a.noise, device=a.device)
|
|
153
182
|
for apply in a.applies.split(","):
|
|
154
183
|
L, M, t, info = build(
|
|
155
|
-
X,
|
|
184
|
+
X,
|
|
185
|
+
op,
|
|
186
|
+
a.device,
|
|
187
|
+
rank=a.rank,
|
|
188
|
+
block=a.block,
|
|
189
|
+
relax=a.relax,
|
|
190
|
+
apply=apply,
|
|
191
|
+
seq=a.seq,
|
|
192
|
+
pad_rows=a.pad_rows,
|
|
156
193
|
)
|
|
157
194
|
ta = time_apply(M, n, a.device)
|
|
158
195
|
print(
|
|
159
196
|
f"n={n} rank={info['rank']} seq={a.seq} block={a.block} relax={a.relax} apply={apply}: "
|
|
160
|
-
f"cholesky {t['cholesky_s']:.1f}s (rows on device {info['rows_s']}s,
|
|
197
|
+
f"pad_rows={a.pad_rows}: cholesky {t['cholesky_s']:.1f}s (rows on device {info['rows_s']}s, "
|
|
198
|
+
f"{info['calls']} calls, {info.get('shapes')} shapes; host {t.get('host_s', 0):.1f}s) "
|
|
161
199
|
f"factor {t['factor_s']:.1f}s total {t['precond_s']:.1f}s; apply(n,33) {ta * 1e3:.0f} ms; "
|
|
162
200
|
f"trace_rem {info['trace_rem']:.4e}",
|
|
163
201
|
flush=True,
|
|
@@ -178,10 +216,10 @@ def cmd_build(a):
|
|
|
178
216
|
break
|
|
179
217
|
|
|
180
218
|
|
|
181
|
-
def solve(op, B, M, a):
|
|
219
|
+
def solve(op, B, M, a, reduction=None):
|
|
182
220
|
t0 = time.perf_counter()
|
|
183
221
|
sol, info = trnsolver.cg_block(
|
|
184
|
-
op, B, M=M, tol=a.tol, maxiter=a.maxiter, check_every=a.check_every
|
|
222
|
+
op, B, M=M, tol=a.tol, maxiter=a.maxiter, check_every=a.check_every, reduction=reduction
|
|
185
223
|
)
|
|
186
224
|
sync()
|
|
187
225
|
return sol, info, time.perf_counter() - t0
|
|
@@ -199,16 +237,25 @@ def cmd_conv(a):
|
|
|
199
237
|
X, y, Xt, ft = synthetic_field(n, 3, noise=a.noise)
|
|
200
238
|
op = trnsparse.KernelOperator(X, "rbf", LS, OS, a.noise, device=a.device)
|
|
201
239
|
B = torch.cat([y[:, None], _rademacher(n, 32, 1)], 1).to(device=a.device, dtype=torch.float32)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
240
|
+
if a.L_cache and os.path.exists(a.L_cache):
|
|
241
|
+
L = torch.load(a.L_cache) # float64 host factor from an earlier run
|
|
242
|
+
else:
|
|
243
|
+
dr = DeviceRows(X, a.device)
|
|
244
|
+
L = trnsolver.pivoted_cholesky(
|
|
245
|
+
op.diag, dr.rows_fn, a.rank, block=a.block, relax=a.relax, sub_fn=dr.sub_fn
|
|
246
|
+
)
|
|
247
|
+
if a.L_cache:
|
|
248
|
+
torch.save(L, a.L_cache)
|
|
206
249
|
Ld = L.to(device=a.device, dtype=torch.float32)
|
|
207
250
|
first = None
|
|
208
|
-
for
|
|
209
|
-
|
|
251
|
+
runs = [(ap, red) for ap in a.applies.split(",") for red in a.reductions.split(",")]
|
|
252
|
+
for apply, red in runs:
|
|
253
|
+
red = red or None
|
|
254
|
+
M = trnsolver.PivotedLowRankPreconditioner(Ld, a.noise, apply=apply, reduction=red)
|
|
210
255
|
ta = time_apply(M, n, a.device)
|
|
211
|
-
|
|
256
|
+
if a.warm:
|
|
257
|
+
solve(op, B, M, a, red) # first call compiles; time the second
|
|
258
|
+
sol, info, ts = solve(op, B, M, a, red)
|
|
212
259
|
alpha = sol[:, 0].detach().cpu().double()
|
|
213
260
|
mean = trnsparse.kernel_matmul_reference(Xt, X, alpha, "rbf", LS, OS)
|
|
214
261
|
r = dict(
|
|
@@ -216,6 +263,8 @@ def cmd_conv(a):
|
|
|
216
263
|
n=n,
|
|
217
264
|
noise=a.noise,
|
|
218
265
|
apply=apply,
|
|
266
|
+
reduction=M.reduction,
|
|
267
|
+
lnc=os.environ.get("NEURON_LOGICAL_NC_CONFIG", "2"),
|
|
219
268
|
iterations=info["iterations"],
|
|
220
269
|
col_iters_max=int(info["col_iterations"].max()),
|
|
221
270
|
converged=bool(info["converged"].all()),
|
|
@@ -224,9 +273,18 @@ def cmd_conv(a):
|
|
|
224
273
|
sampled_res=sampled_residual(X, y, alpha, a.noise, n),
|
|
225
274
|
solve_s=round(ts, 1),
|
|
226
275
|
s_per_iter=round(ts / max(1, info["iterations"] + 1), 2),
|
|
276
|
+
ms_per_iter=round(1e3 * ts / max(1, info["iterations"] + 1), 1),
|
|
227
277
|
apply_ms=round(ta * 1e3, 1),
|
|
228
278
|
rmse=float((mean - ft).pow(2).mean().sqrt()),
|
|
279
|
+
sha_X=hashlib.sha256(sol.detach().cpu().numpy().tobytes()).hexdigest()[:16],
|
|
280
|
+
sha_mean=hashlib.sha256(mean.numpy().tobytes()).hexdigest()[:16],
|
|
229
281
|
)
|
|
282
|
+
if a.save_dir:
|
|
283
|
+
os.makedirs(a.save_dir, exist_ok=True)
|
|
284
|
+
torch.save(
|
|
285
|
+
dict(X=sol.detach().cpu(), mean=mean, info=r),
|
|
286
|
+
f"{a.save_dir}/conv_{apply}_{M.reduction}.pt",
|
|
287
|
+
)
|
|
230
288
|
if first is None:
|
|
231
289
|
first = (mean, sol.detach().cpu())
|
|
232
290
|
else:
|
|
@@ -249,7 +307,14 @@ def cmd_gp(a):
|
|
|
249
307
|
B = torch.cat([y[:, None], _rademacher(n, a.probes, 1)], 1).to(device=a.device, dtype=op.dtype)
|
|
250
308
|
t["setup_s"] = time.perf_counter() - t0
|
|
251
309
|
L, M, tb, binfo = build(
|
|
252
|
-
X,
|
|
310
|
+
X,
|
|
311
|
+
op,
|
|
312
|
+
a.device,
|
|
313
|
+
rank=min(a.rank, n),
|
|
314
|
+
block=a.block,
|
|
315
|
+
relax=a.relax,
|
|
316
|
+
apply=a.apply,
|
|
317
|
+
pad_rows=a.pad_rows,
|
|
253
318
|
)
|
|
254
319
|
t.update(tb)
|
|
255
320
|
t["precond_rank"] = binfo["rank"]
|
|
@@ -300,8 +365,27 @@ def main():
|
|
|
300
365
|
ap.add_argument(
|
|
301
366
|
"--seq", action="store_true", help="build: the one-row-per-step host build (baseline)"
|
|
302
367
|
)
|
|
368
|
+
ap.add_argument(
|
|
369
|
+
"--pad-rows",
|
|
370
|
+
action=argparse.BooleanOptionalAction,
|
|
371
|
+
default=True,
|
|
372
|
+
help="pad device row calls to power-of-two shapes (trnsci/trnsci#109)",
|
|
373
|
+
)
|
|
374
|
+
ap.add_argument(
|
|
375
|
+
"--prewarm",
|
|
376
|
+
action="store_true",
|
|
377
|
+
help="compile the pad_rows shapes first (timed separately as prewarm_s)",
|
|
378
|
+
)
|
|
303
379
|
ap.add_argument("--apply", default="projected")
|
|
304
380
|
ap.add_argument("--applies", default="host64,projected")
|
|
381
|
+
ap.add_argument(
|
|
382
|
+
"--reductions",
|
|
383
|
+
default="",
|
|
384
|
+
help="conv: cg_block reduction modes, comma-separated (default: the library default)",
|
|
385
|
+
)
|
|
386
|
+
ap.add_argument("--L-cache", default=None, help="conv: load / save the factor L here")
|
|
387
|
+
ap.add_argument("--save-dir", default=None, help="conv: save X and the mean per run")
|
|
388
|
+
ap.add_argument("--warm", action="store_true", help="conv: run each solve twice, time the 2nd")
|
|
305
389
|
ap.add_argument("--probes", type=int, default=32)
|
|
306
390
|
ap.add_argument("--tol", type=float, default=1e-6)
|
|
307
391
|
ap.add_argument("--maxiter", type=int, default=1000)
|
|
@@ -314,6 +398,11 @@ def main():
|
|
|
314
398
|
torch.set_num_threads(a.threads)
|
|
315
399
|
a.device = "cpu" if a.cpu else "neuron"
|
|
316
400
|
trnsparse.set_backend("pytorch" if a.cpu else "nki")
|
|
401
|
+
if a.prewarm and a.cmd != "conv":
|
|
402
|
+
X = synthetic_field(int(a.n), 3, noise=a.noise)[0]
|
|
403
|
+
tp, sizes = prewarm(X, a.device, a.block)
|
|
404
|
+
print(f"prewarm: {len(sizes)} shapes {sizes} in {tp:.1f}s", flush=True)
|
|
405
|
+
emit(kind="prewarm", n=int(a.n), prewarm_s=round(tp, 2), shapes=sizes)
|
|
317
406
|
{"build": cmd_build, "conv": cmd_conv, "gp": cmd_gp}[a.cmd](a)
|
|
318
407
|
|
|
319
408
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Merge device conformance summaries and list the NEW failures.
|
|
3
|
+
|
|
4
|
+
A device conformance run (``pytest tests/test_conformance.py --backend nki
|
|
5
|
+
--conformance-device neuron``) marks known platform limits as
|
|
6
|
+
``xfail(strict=False)`` with a ``[device-known:<category>]`` reason, and prints
|
|
7
|
+
a summary at the end. Runs on a Trainium box are split into chunks, so pass
|
|
8
|
+
``--conformance-json PATH`` to each chunk and merge them here::
|
|
9
|
+
|
|
10
|
+
pytest tests/test_conformance.py --backend nki --conformance-device neuron \\
|
|
11
|
+
-k "<chunk>" --conformance-json chunk1.json
|
|
12
|
+
python scripts/conformance_expect.py chunk*.json
|
|
13
|
+
|
|
14
|
+
Prints passed, xfailed by category, XPASS by category (a known category that
|
|
15
|
+
now passes: a signal, not a failure) and the NEW failures. Exits 1 if there
|
|
16
|
+
are NEW failures, else 0.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import argparse
|
|
22
|
+
import json
|
|
23
|
+
import sys
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def merge(paths):
|
|
27
|
+
out = {"passed": 0, "skipped": 0, "xfailed": {}, "xpassed": {}, "new_failures": []}
|
|
28
|
+
for p in paths:
|
|
29
|
+
with open(p) as fh:
|
|
30
|
+
s = json.load(fh)
|
|
31
|
+
out["passed"] += s["passed"]
|
|
32
|
+
out["skipped"] += s["skipped"]
|
|
33
|
+
for key in ("xfailed", "xpassed"):
|
|
34
|
+
for cat, ids in s[key].items():
|
|
35
|
+
out[key].setdefault(cat, []).extend(ids)
|
|
36
|
+
out["new_failures"].extend(s["new_failures"])
|
|
37
|
+
return out
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def report(s, verbose=False):
|
|
41
|
+
lines = ["conformance expectations (device run)"]
|
|
42
|
+
lines.append(f" passed: {s['passed']} skipped: {s['skipped']}")
|
|
43
|
+
for key, label in (("xfailed", "xfailed"), ("xpassed", "XPASS (known category now passes)")):
|
|
44
|
+
lines.append(f" {label}: {sum(len(v) for v in s[key].values())}")
|
|
45
|
+
for cat, ids in sorted(s[key].items()):
|
|
46
|
+
lines.append(f" {cat}: {len(ids)}")
|
|
47
|
+
if verbose or key == "xpassed":
|
|
48
|
+
lines.extend(f" {i}" for i in ids)
|
|
49
|
+
lines.append(f" NEW failures: {len(s['new_failures'])}")
|
|
50
|
+
lines.extend(f" {i}" for i in s["new_failures"])
|
|
51
|
+
return "\n".join(lines)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def main(argv=None):
|
|
55
|
+
ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
|
|
56
|
+
ap.add_argument("json", nargs="+", help="--conformance-json files from device runs")
|
|
57
|
+
ap.add_argument("-v", "--verbose", action="store_true", help="list xfailed IDs too")
|
|
58
|
+
args = ap.parse_args(argv)
|
|
59
|
+
s = merge(args.json)
|
|
60
|
+
print(report(s, args.verbose))
|
|
61
|
+
return 1 if s["new_failures"] else 0
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
sys.exit(main())
|