Repository navigation
v0.17.0
Native TorchNeuron dispatch (Trn2/Trn3) alongside the PyTorch/XLA path (Trn1, maintenance); validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0) — see trnsci/trnsci#35.
Headline performance: batched Jacobi eigh(A, method="jacobi") kernel on Trn2, 40.2 ms vs 60.5 ms for CPU LAPACK at n=32, B=1024 (#50); the native eigh cutover to torch.linalg.eigh below n=512 stays the default.
Added
-
eigh(A, method="jacobi"): batched Jacobi eigensolver (#48). Accepts
(n, n)or(..., n, n);TRNSOLVER_EIGH_METHOD=jacobiselects it when
methodis not given. Opt-in: the defaultautodispatch, including the
aten cutover for n < 512, is unchanged.- On the native
neurondevice (FP32, n <= 128) it runs the one-sided
(Hestenes) Jacobi kernel intrnsolver/nki/jacobi.py: up to 128 tiles
of 128 / n matrices each (512 matrices at n = 32) held in SBUF for a
whole sweep, one launch per
sweep, a convergence check after the expected sweep count (6-8 for
random matrices), at most 15 sweeps. Native optrnsolver::jacobi_sweeps. - Each step uses the Tensor Engine as an exact partition permutation
(the block-diagonal step permutation is the stationary operand, shared
by every tile) and applies the n/2 rotations on the Vector Engine in the
X + K^T Xform, which keeps FP32 orthogonality at about 1e-6. - Elsewhere (CPU, FP64, the XLA lineage, n > 128) it runs the torch
implementation intrnsolver/_jacobi.py: parallel-ordered two-sided
Jacobi with each step as batched matmuls. - Tuning:
TRNSOLVER_JACOBI_GROUP(tiles per launch) and
TRNSOLVER_JACOBI_CHAINS(independent dependency chains per step). - Tests:
tests/test_jacobi.py(schedules, layout, torch path and the
device host driver againsttorch.linalg.eighon CPU; kernel vs a torch
model in the simulator; NKI 0.7 MLIR verify;@pytest.mark.neuron). - Bench:
scripts/bench_jacobi.py(CPU LAPACK, torch-on-device, compiled,
kernel).
- On the native
-
Native PyTorch dispatch on TorchNeuron (#40, trnsci/trnsci#35). On
TorchNeuron (Neuron SDK 2.33+,torch-neuronx2.14, PyTorch 2.14,
Trn2/Trn3) every hardware NKI kernel is registered as a PyTorch custom op
withtorch_neuronx.nki_opand launched ondevice="neuron", with no
torch_xlaimport. Ops:trnsolver::matvec,rank2_update,matmul,
matmul_fp32out,apply_reflectors. Kernel bodies are unchanged.- The dispatch path is detected on the first kernel launch: native when
torch_neuronxexportsnki_opand aneurondevice is available, XLA
whentorch_xlais installed, otherwise none. The XLA path (Trn1) is
unchanged: kernels run ontorch_xla.device()followed by
torch_xla.sync(), as before. The simulator path is unchanged. - The custom ops are registered lazily (
trnsolver/nki/_native.pyis
imported only once the native path is selected), so CPU-only installs
and the XLA lineage see no import-time side effects. - Every host wrapper (
_call_matvec,_call_rank2_update,_call_matmul,
_call_matmul_fp32out,_call_apply_reflectors) goes through one
launch helper,dispatch._launch. TRNSCI_NKI_DISPATCH=auto|native|xla|cpuforces the dispatch path (a
suite-wide variable). Forcing an unavailable path raises.TRNSCI_XLA_DEPRECATION=1makes the XLA path emit one
DeprecationWarning. Off by default; the suite turns it on at
TorchNeuron GA.- New
[torchneuron]extra (torch>=2.14,torch-neuronx>=2.14,
nki>=0.6);[neuron]stays the PyTorch/XLA lineage. - Tests:
conftest.pysetsNKI_ENABLE_TRACE_CACHE=0by default;
CPU-runnable path-selection, routing and lazy-registration tests;
@pytest.mark.neuronnative-path tests (not yet run on hardware). The
twotest_eigh_neuron.pytests that call kernels ontorch_xlatensors
are skipped off the XLA path.
- The dispatch path is detected on the first kernel launch: native when
Changed
- Householder tridiagonalization keeps its scalar work on the host.
_householder_tridiagreads column k of the working matrix once per step
and computes the norm, sign,v,v·v,v·wanduon CPU copies; only
the working matrix and the two kernels stay on the device. The fixup of
row and column k is two slice writes instead of four. The reflectors are
accumulated on the host. This replaces about six device.item()syncs
and several element writes per step. The algorithm is unchanged, and CPU
and simulator results are bit-identical. gmreskeeps its Hessenberg matrix and least-squares solve on the
host. Every entry was already read back as a Python float; the Krylov
basis stays onb's device. Removes per-element device writes and a
devicelstsq. CPU results are bit-identical.schurruns on a CPU copy of the input and returnsQ,Ton the
input's device, like the eigh QR iteration (#42). CPU inputs are
unchanged.