Skip to content

NKI: ScalarE activation rsqrt error on Trn2 reaches ~349,000 ULP (2.9% relative) inside its documented range; documented bound is 40,000 ULP #1501

Backlog

Description

@scttfrdmn

Summary: on Trn2 (NeuronCore-v3), ScalarE nisa.activation(op=nl.rsqrt) reaches a maximum error of 348,900 ULP, 2.9% relative, for inputs inside its documented valid range [2⁻⁸⁷, 2⁹⁷]. The NKI API "Supported Activation Functions" table documents a bound of 40,000 ULP.

The p99.9 error is about 2.8e5 ULP, so the errors are spread across the range, not confined to its edges. The same probe measured:

  • ScalarE sqrt: 65,520 ULP max, within the documented 65,536;
  • ScalarE log: 396 ULP away from x = 1, against the documented 40, and 8,445 ULP near x = 1, where log x → 0 inflates the relative error;
  • ScalarE exp and reciprocal: 22 and 122 ULP, both better than the documented 400.

Environment: trn2.3xlarge, Deep Learning AMI Neuron torch-neuronx 2.14.0 (Ubuntu 24.04) SDK 2.33.1, neuronx-cc 2.28.7631, nki 0.7.0, runtime 2.35.33, LNC=2.

Method:

  • 262,144 fp32 inputs, log-uniform over [2⁻⁸⁷, 2⁹⁷], laid out as a [128, 2048] SBUF tile;
  • nisa.activation(dst=r, op=nl.rsqrt, data=x);
  • ULP error measured against the fp64 result rounded to fp32.

The probe is open source: scripts/probe_lut_ulp.py in trnsci/trnblas#134. Its full table also covers the GpSimd and VectorE alternatives. GpSimd tensor_scalar(op0=rsqrt) and GpSimd tensor_tensor(op=power) are ≤ 1 ULP, and VectorE nisa.reciprocal is correctly rounded.

Minimal reproduction (eager, torch-neuronx native):

import numpy as np, torch, torch_neuronx
import nki, nki.isa as nisa, nki.language as nl

@nki.jit
def k(x):
    out = nl.ndarray(x.shape, dtype=nl.float32, buffer=nl.shared_hbm)
    t = nl.load(x)
    r = nl.ndarray(x.shape, dtype=nl.float32, buffer=nl.sbuf)
    nisa.activation(dst=r, op=nl.rsqrt, data=t)
    nl.store(out, value=r)
    return out

rng = np.random.default_rng(0)
x = np.exp2(rng.uniform(-87, 97, size=(128, 2048))).astype(np.float32)
got = torch_neuronx.wrap_nki(k)(torch.from_numpy(x).to("neuron")).cpu().numpy()
ref = (1.0 / np.sqrt(x.astype(np.float64))).astype(np.float32)
ulp = np.abs(got.astype(np.float64) - ref) / np.spacing(np.abs(ref))
print(ulp.max(), np.quantile(ulp, 0.999), (np.abs(got - ref) / ref).max())
# Trn2 measured: ~3.5e5, ~2.8e5, ~2.9e-2

Asks:

  1. Correct the documented bound for ScalarE rsqrt on NeuronCore-v3, or say which sub-range the 40,000 ULP figure applies to.
  2. State the log bound's conditions; near x = 1 a relative-error bound needs qualification.
  3. Optionally, add a pointer in the activation table to the accurate alternatives on v3: GpSimd rsqrt / power, and VectorE reciprocal.

Activity

  1. added
    bug
    on Nov 24, 2026
  2. scttfrdmn commented on Nov 24, 2026

    @scttfrdmn
    Author

    I ran the minimal reproduction above as written on the same trn2.3xlarge (SDK 2.33.1). It prints 348703.0 186587.39 0.029394751: max ULP, p99.9 ULP and max relative error. The p99.9 for this input set is 1.87e5. The 2.8e5 in the description came from the full probe's input distribution; the max and relative error match.

  3. github-actions commented on Nov 24, 2026

    @github-actions

    Hi @scttfrdmn, Thank you for filing the issue! We will take a look and get back to you.

  4. scttfrdmn commented on Nov 25, 2026

    @scttfrdmn
    Author

    Correction to the description (measured per input range, same box and toolchain): the large errors are concentrated at the extremes of the documented range, not spread across it. My p99.9 figure was inflated by log-uniform sampling of a very wide range. ScalarE activation rsqrt, max ULP / max relative error per input band (262,144 log-uniform inputs per band):

    input band max ULP p99.9 ULP max rel err
    [2⁻⁸⁷, 2⁻⁶⁴] 349,157 296,517 2.94e-2
    [2⁻⁶⁴, 2⁻⁵²] 10,904 10,584 6.5e-4
    [2⁻⁵², 2⁻³²] 10,860 10,383 6.5e-4
    [2⁻³², 2³²] 7 7 4.5e-7
    [2³², 2⁵²] 1,044 953 6.5e-5
    [2⁵², 2⁸⁰] 21,408 20,708 1.35e-3
    [2⁸⁰, 2⁹⁷] 32,878 26,169 2.08e-3

    So the documented 40,000-ULP bound is exceeded only in [2⁻⁸⁷, 2⁻⁶⁴]. The function is accurate (7 ULP) over [2⁻³², 2³²]. The ask becomes:

    1. correct the bound, or narrow the documented valid range for v3 (e.g. state the bound per sub-range, or start the valid range at 2⁻⁶⁴);
    2. ideally publish the per-range accuracy for the other LUT functions.

    A sibling measurement for ScalarE sqrt shows the same pattern: 8.4e-7 over [2⁻⁵², 2⁵²], degrading toward both ends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Trn2bugtraining

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions