Repository navigation
v0.17.0
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
raisedNotImplementedErrorwheneverHAS_NKIwas true.- Under an initialized
torch.distributedgroup with
world_size == n_shards > 1, rankrnow computes only shardr'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
selectsnkiunder a"neuron"process group,torchunder any other
group, andmockotherwise. Override it with
TRNTENSOR_ALLREDUCE=mock|torch|nki|autoorparallel.set_allreduce_backend().
An explicittorch/nkirequest that cannot be honored raises
RuntimeError; it never falls back to replicated compute. trntensor.nki.collectives.nki_all_reduce_sumis an@nki.jitkernel
usingnki.collectives.all_reduce(op=add)on namedshared_hbmbuffers,
invoked viatorch_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_hbmgave wrong values at LNC=2.scripts/run_reduce_parallel_multirank.pyruns multi-rank checks: one
process per rank, core pinning, hard timeouts, and per-rank logs. It
checksij,jk->ikwithjsharded 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--cpufor a gloo pre-flight. Rank cores must be an
aligned pair or quad (0-1, 2-3, 0-3).
- Under an initialized
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_errorselects 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-timeRuntimeWarningand returns
"kahan"instead of silently missing the target. It does not raise.
Targets below K·2⁻⁵³ still raiseValueError. Because of theu_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 (eritile as the stationary operand, ν-major
scratch), so step 2 loads its stationary tile with a plain DMA. The
formernl.load_transpose2dof a strided HBM slice was rejected by the
BIR verifier (checkDMATranspose: "transposing dimensions should be
continuous"). The ν loop is nowTILE_K-wide, so the dispatcher pads
nbasisto 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 passesBas
(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 aaccᵀ · onesmatmul on the Tensor Engine.matmul_kernel/batched_matmul_kerneluse_sr=True: NKI 0.7's
nisa.activationhas noout_dtype/round_modekwargs; the
downcast now callsnisa.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 staletest_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) theuse_srflag no longer chooses the rounding mode. On Trn2,
withNEURON_RT_STOCHASTIC_ROUNDING_ENunset or0, both
use_sr=Trueanduse_sr=Falseround 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_matmulnow emit a one-timeRuntimeWarning
when SR is requested on the native NKI path without
NEURON_RT_STOCHASTIC_ROUNDING_EN=1, then still compute
(round-to-nearest). This coversprecision="sr"ineinsum/
multi_einsumandtarget_forward_error=when it picks"sr". The CPU
fallback andnki.simulatepaths 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);
hardwareTestStochasticRoundingRuntimeintests/test_nki_kernels.py
(markersneuron+neuron_sr), gated by thesr_runtimefixture.
The fixture skips unless the variable was1at process start.
- Docs (
tests/test_nki_compile.py(nki_simulatormarker): runs the NKI
frontend (trace → MLIR → verify) on CPU for every kernel at trn1, trn2,
and trn2 lnc=2. Catches the verifier errorsnki.simulatemisses.