Skip to content

v0.17.0

Choose a tag to compare

@scttfrdmn scttfrdmn released this 31 Oct 04:53
· 237 commits to main since this release
v0.17.0
23c0dad

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=jacobi selects it when
    method is not given. Opt-in: the default auto dispatch, including the
    aten cutover for n < 512, is unchanged.

    • On the native neuron device (FP32, n <= 128) it runs the one-sided
      (Hestenes) Jacobi kernel in trnsolver/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 op trnsolver::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 X form, which keeps FP32 orthogonality at about 1e-6.
    • Elsewhere (CPU, FP64, the XLA lineage, n > 128) it runs the torch
      implementation in trnsolver/_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 against torch.linalg.eigh on 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).
  • Native PyTorch dispatch on TorchNeuron (#40, trnsci/trnsci#35). On
    TorchNeuron (Neuron SDK 2.33+, torch-neuronx 2.14, PyTorch 2.14,
    Trn2/Trn3) every hardware NKI kernel is registered as a PyTorch custom op
    with torch_neuronx.nki_op and launched on device="neuron", with no
    torch_xla import. 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_neuronx exports nki_op and a neuron device is available, XLA
      when torch_xla is installed, otherwise none. The XLA path (Trn1) is
      unchanged: kernels run on torch_xla.device() followed by
      torch_xla.sync(), as before. The simulator path is unchanged.
    • The custom ops are registered lazily (trnsolver/nki/_native.py is
      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|cpu forces the dispatch path (a
      suite-wide variable). Forcing an unavailable path raises.
    • TRNSCI_XLA_DEPRECATION=1 makes 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.py sets NKI_ENABLE_TRACE_CACHE=0 by default;
      CPU-runnable path-selection, routing and lazy-registration tests;
      @pytest.mark.neuron native-path tests (not yet run on hardware). The
      two test_eigh_neuron.py tests that call kernels on torch_xla tensors
      are skipped off the XLA path.

Changed

  • Householder tridiagonalization keeps its scalar work on the host.
    _householder_tridiag reads column k of the working matrix once per step
    and computes the norm, sign, v, v·v, v·w and u on 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.
  • gmres keeps its Hessenberg matrix and least-squares solve on the
    host.
    Every entry was already read back as a Python float; the Krylov
    basis stays on b's device. Removes per-element device writes and a
    device lstsq. CPU results are bit-identical.
  • schur runs on a CPU copy of the input and returns Q, T on the
    input's device, like the eigh QR iteration (#42). CPU inputs are
    unchanged.