Skip to content

v0.17.0

Choose a tag to compare

@scttfrdmn scttfrdmn released this 31 Oct 04:54
· 195 commits to main since this release
v0.17.0
f913f10

Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron device) — see trnsci/trnsci#35.

Added

  • Reduce-parallel sharding on real multi-rank all-reduce (Phase 4 prototype).
    Before this change, reduce-parallel and mixed output/reduce-parallel einsums
    raised NotImplementedError whenever HAS_NKI was true.
    • Under an initialized torch.distributed group with
      world_size == n_shards > 1, rank r now computes only shard r's
      partial on its own device. The partials are combined with a real
      all-reduce. Single-process runs keep _mock_allreduce.
    • The backend is chosen by trntensor.parallel.allreduce_backend. auto
      selects nki under a "neuron" process group, torch under any other
      group, and mock otherwise. Override it with
      TRNTENSOR_ALLREDUCE=mock|torch|nki|auto or parallel.set_allreduce_backend().
      An explicit torch/nki request that cannot be honored raises
      RuntimeError; it never falls back to replicated compute.
    • trntensor.nki.collectives.nki_all_reduce_sum is an @nki.jit kernel
      using nki.collectives.all_reduce(op=add) on named shared_hbm buffers,
      invoked via torch_neuronx.wrap_nki(k)[(lnc,)]. This is the pattern
      measured bit-exact on Trn2 (SDK 2.33, NKI 0.7.0, LNC=2) in trnsci spike B4.
      private_hbm gave wrong values at LNC=2.
    • scripts/run_reduce_parallel_multirank.py runs multi-rank checks: one
      process per rank, core pinning, hard timeouts, and per-rank logs. It
      checks ij,jk->ik with j sharded at n = 512–2048 against the
      single-device result (fp32 rel err ≤ 1e-5) and requires all ranks to
      agree. It also reports bit-exactness against a fixed-order sum, plus
      timings. Pass --cpu for a gloo pre-flight. Rank cores must be an
      aligned pair or quad (0-1, 2-3, 0-3).

Fixed

  • Precision promises (Trn2 spike B5, #42).

    • precision="kahan" on Neuron-device (or other non-fp64) operands now
      contracts on the host in true fp64 and moves the result back. Before,
      the "fp64" einsum ran on the device, which has no fp64 datapath. On Trn2
      fp32 results measured ~1.4 ulp (max componentwise 8.4e-8 at N=128),
      above the K·2⁻⁵³ + u bound that a real fp64 accumulation plus one
      rounding satisfies. The bound was right; the extra rounding was the bug.
    • Error bounds now include the final rounding of the result to its dtype
      (u_out): "fast" K·u + u_out, "sr" √K·u + u_out, "dd" K·u² + u_out,
      "kahan" K·2⁻⁵³ + u_out. select_precision_for_error selects on these
      bounds. When the target is below the floor (≈ 3.9e-3 for bf16 results,
      6.0e-8 for fp32), it emits a one-time RuntimeWarning and returns
      "kahan" instead of silently missing the target. It does not raise.
      Targets below K·2⁻⁵³ still raise ValueError. Because of the u_out
      term, some bf16 targets near 2⁻⁸ now select a more accurate mode than
      before.
  • NKI 0.7 / neuronx-cc 2.28 kernel compile on Trn2 (#41).

    • ao_to_mo_transform_kernel: step 1 now computes the intermediate
      already transposed (eri tile as the stationary operand, ν-major
      scratch), so step 2 loads its stationary tile with a plain DMA. The
      former nl.load_transpose2d of a strided HBM slice was rejected by the
      BIR verifier (checkDMATranspose: "transposing dimensions should be
      continuous"). The ν loop is now TILE_K-wide, so the dispatcher pads
      nbasis to a multiple of 128 instead of 512.
    • mp2_energy_kernel: removed the (128, 1) → (1, 128) reshape
      ("Partition dim size must be preserved") and the cross-partition
      nl.sum(axis=(0, 1)). The dispatcher now passes B as
      (nocc, naux, nvir) (plain loads, no DMA transposes) and ε_occ / ε_vir
      pre-broadcast across the 128 partitions; the kernel row-reduces per
      lane and finishes with a accᵀ · ones matmul on the Tensor Engine.
    • matmul_kernel / batched_matmul_kernel use_sr=True: NKI 0.7's
      nisa.activation has no out_dtype / round_mode kwargs; the
      downcast now calls nisa.activation(dst=..., op=nl.copy, data=psum).
      Stochastic rounding is a runtime setting on this toolchain, not a
      per-instruction one.
  • tests/test_nki_kernels.py: replaced the stale test_oversize_raises
    (nvir > 128 no longer raises since M-tiling landed) with a correctness
    check at nvir = 200.

Added

  • trntensor.forward_error_bound(mode, dtype, K): the componentwise error
    bound each precision mode promises, including output rounding (#42).
  • Stochastic-rounding runtime guard (#41). On NKI 0.7 (Neuron SDK
    2.33) the use_sr flag no longer chooses the rounding mode. On Trn2,
    with NEURON_RT_STOCHASTIC_ROUNDING_EN unset or 0, both
    use_sr=True and use_sr=False round to nearest even and are
    deterministic. With =1, both round stochastically. The Neuron Runtime
    sets the mode for the whole process when it initializes.
    nki_matmul / nki_batched_matmul now emit a one-time RuntimeWarning
    when SR is requested on the native NKI path without
    NEURON_RT_STOCHASTIC_ROUNDING_EN=1, then still compute
    (round-to-nearest). This covers precision="sr" in einsum /
    multi_einsum and target_forward_error= when it picks "sr". The CPU
    fallback and nki.simulate paths are unaffected. New
    trntensor.nki.dispatch.sr_runtime_enabled().
    • Docs (docs/api/einsum.md, docs/api/plan.md) and docstrings explain
      that the variable has to be set at process start, and that with it set
      every downcast in the process rounds stochastically, including
      precision="fast".
    • Tests: tests/test_sr_runtime.py (CPU, native path stubbed);
      hardware TestStochasticRoundingRuntime in tests/test_nki_kernels.py
      (markers neuron + neuron_sr), gated by the sr_runtime fixture.
      The fixture skips unless the variable was 1 at process start.
  • tests/test_nki_compile.py (nki_simulator marker): runs the NKI
    frontend (trace → MLIR → verify) on CPU for every kernel at trn1, trn2,
    and trn2 lnc=2. Catches the verifier errors nki.simulate misses.