All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
-
_MIN_NKI_FLOPS_PINNEDdispatch threshold (#33) — second FLOP gate for when operands are already XLA-resident (to_xlapre-applied). Profiler data (trn1.2xlarge,scripts/run_neuron_profile.sh --dispatch-timing) shows the NKI crossover drops from ~2 GFLOPs to ~900 MFLOPs when host→device transfer is eliminated. Default: 1 GFLOPs. Override withTRNTENSOR_MIN_NKI_FLOPS_PINNED. Dispatch automatically detects XLA-resident inputs and uses the lower threshold. -
docs/design/matmul_dispatch_findings.md— full per-step timing analysis documenting XLA dispatch latency (~0.67 ms fixed overhead), transfer costs, and the unpinned vs pre-pinned crossover. Raw JSON timing data included.
-
precision=kwarg foreinsumandplan_contraction(#28 partial) — three modes:"fast"(default, no change),"kahan"(promotes all operands tofloat64before contracting viatorch.einsum, casts result back to original dtype — gives ~15.9 significant digits; bypasses NKI dispatch for CPU compatibility),"dd"(raisesNotImplementedErrorpending trnblas Phase 2 double-double GEMM).precisionis included in the plan cache key so"fast"and"kahan"plans cache independently. Useful for DF-MP2 / CCSD energy convergence where fp32's ~7.2 digits are insufficient. -
dtypemixed-precision override foreinsum(#22) — accepts string aliases ("bf16","fp16","f32") ortorch.dtypeinstances. When set, all operands are cast to the requested dtype before contracting and the result is returned in that dtype. Matches Neuron SDK autocast recommendations; usedtype="bf16"to route fp32 models through the NKI bf16 matmul path without changing the model's weight dtype. -
Neuron profiler script (
scripts/run_neuron_profile.sh) — captures a Neuron Profiler 2.0 trace ofmatmul_kernelorbatched_matmul_kernelvia SSM on thetrntensor-ci-trn1instance. Supports--probe(API discovery),--kernel matmul|bmm, and--shape small|medium|large. Adapted from the trnblas profiler pattern (double-base64 encoding, auto start/stop). -
Dispatch autotune script (
scripts/autotune_dispatch.py) (#33 partial) — sweeps(M, K, N)shapes and measures NKI vs PyTorch wall-clock time to find the empirical FLOP crossover on the current hardware. Reports the recommendedTRNTENSOR_MIN_NKI_FLOPSvalue;--write-cachepersists the result to/var/tmp/trntensor-autotune/threshold.json. The dispatch layer reads this cache at startup (env varTRNTENSOR_AUTOTUNE_CACHEoverrides path; explicitTRNTENSOR_MIN_NKI_FLOPSalways wins).
-
Greedy contraction-path search for 3+ operand
einsum(#18) —plan_contraction()now returnsstrategy="path"for three or more operands._greedy_path_searchselects the cheapest binary contraction order by minimizing per-step FLOP cost; the resultingContractionPlan.contraction_pathdrives_execute_path, which routes each binary step through the full backend selection stack so large sub-contractions still dispatch to NKI. -
multi_einsumshared-operand XLA residency (#19) — When NKI dispatch is active,multi_einsumdetects operand tensors that appear in more than one contraction (by object identity) and pre-pins them to the XLA device once before executing the loop. Eliminates redundant host↔device transfers for workloads like DF-MP2 where the three-center integral tensorBfeeds many pair contractions. Falls back to the existing per-contraction loop on CPU. -
Subscript and shape validation with descriptive errors (#26) —
plan_contraction()now validates subscripts up-front and raisesValueErrorwith precise messages: wrong operand count, rank mismatch, and inconsistent index sizes are all caught before any torch operation runs. Eliminates cryptic downstream errors fromtorch.einsum. -
PEP 561
py.typedmarker (#25) —trntensornow ships apy.typedfile so type checkers (mypy, pyright, etc.) recognise the package as typed and apply inline annotations. -
alpha/betascaling foreinsum(#20) — matches cuTENSOR's GEMM-style interface:einsum(subscripts, A, B, alpha=α, beta=β, out=C)returnsα * contract(A, B) + β * C. Defaults (alpha=1, beta=0, out=None) preserve existing behaviour exactly. Useful for accumulation patterns and in-place gradient updates without an extra allocation. -
Contraction plan cache (#29 partial) —
plan_contraction()caches results by(subscripts, operand shapes). Repeated calls with the same subscript and shapes skip replanning entirely.clear_plan_cache()andplan_cache_info()are exported from the top-level API. -
Tensor Train (TT) decomposition (#23) —
tt_decompose(tensor, max_rank)decomposes a d-dimensional tensor into a chain of 3-tensor cores via TT-SVD (Oseledets 2011), bond dimension capped atmax_rank.tt_reconstruct(cores)contracts the chain back. Useful for DMRG-style high-dimensional compression. -
Non-negative CP and warm-start CP (#24) —
cp_decomposegains two new keyword arguments:nonneg=Trueswitches ALS to multiplicative updates to enforce non-negative factors;factors=accepts a list of pre-computed factor matrices to warm-start from, skipping random initialization. Both options compose.
trntensor.to_xla(tensor)/trntensor.from_xla(tensor)— explicit operand residency on the Trainium XLA device. Pre-pinning operands lets repeated trntensor calls skip per-dispatch host↔device transfer, which otherwise dominates at current kernel sizes. The full DF-MP2 pipeline (ao_to_mo_transform→mp2_energy) with all operands pre-pinned pays transfer cost once instead of once per call. The dispatch layer's_to_xlahelper takes a fast path when every operand is already on XLA, returning the result on XLA — the caller decides when to pull back viafrom_xla. Closes #34.trntensor.ao_to_mo_transform(eri, C_occ, C_vir)— fused 4-index AO→MO integral transform with K-tiling over the basis index (#37). One NKI program computesB[i,a,P] = Σ_{μν} C_occ[μ,i] · C_vir[ν,a] · eri[μ,ν,P]. Tiles over μ (step 1) and ν (step 2) in TILE_K=128 chunks sonbasisup to 512 is supported; dispatch pads to the nearest TILE_K multiple. Shape constraints:nbasis ≤ 512,nocc ≤ 128,nvir ≤ 512. Composes withmp2_energyfor the full DF-MP2 pipeline from AO integrals to correlation energy. Validated on trn1 (hardware) and via the CPU simulator CI job.- NKI CPU simulator dispatch via
TRNTENSOR_USE_SIMULATOR=1. Routes kernels throughnki.simulate(kernel)(numpy_args)on CPU, bypassingtorch_xla+ NEFF compile. Iteration loop drops from ~5 min per SSM round-trip to seconds. Correctness-only — MLIR verifier errors remain hardware-only. nki-simulatorCI job onubuntu-latest— runs thenki_simulator-marked suite againstnki>=0.3.0from the AWS pip index on every push + PR. Zero AWS cost for the correctness gate.tests/test_nki_sim.py— simulator-backed correctness suite, markernki_simulator. Covers matmul, batched matmul,ao_to_mo_transform(including K-tiled nbasis=256 and non-aligned nbasis=200), andmp2_energy.scripts/run_simulator_tests.sh— SSM runner for the simulator suite on the trn1 DLAMI.docs/developing_kernels.md— NKI kernel development guide with trntensor-specific env vars and file locations.
- Migrated to NKI 0.3.0 / Neuron SDK 2.29. Canonical
nki.*namespace; the legacyneuronxcc.nki.*shim is no longer used. Kernels updated for the NKI 0.3.0 breaking-change surface:nisa.nc_matmul(dst=, stationary=, moving=, accumulate=True)(all kwargs);nl.copy(psum)returns a view — usenl.ndarray+nisa.tensor_copyinstead; tensor-tensornl.dividedropped — usemultiply × reciprocal. - Dev workflow migrated to uv.
uv sync --extra devreplacespip install -e ".[dev]"; CI usesastral-sh/setup-uv@v6anduv run pytest/uvx ruff.uv.lockis committed for reproducible installs. - Removed the
[neuron]optional-dependencies extra.nkiis installed from the AWS Neuron pip index in CI or provided by the Deep Learning AMI's pre-built venv on hardware. CONTRIBUTING.mdupdated to reflect the uv-based setup.
mp2_energy_kernel1D-load ambiguity on pre-pinned XLA ε inputs (#38). Reshapeeps_occ/eps_virto 2D(N, 1)at the dispatch boundary; partition-dim inference is unambiguous regardless of residency state.mp2_energy_kernel0-D SBUF rejection (SBUF tensors must have at least 2 dimensions). Per-(i,j)reduction now uses a persistent(1, 1)SBUF accumulator (nl.zeros((1, 1), ...)) instead of a directnl.sumstore._to_xlafast-path now callsxm.mark_step()when operands are already on XLA, forcing pending lazy computations to materialize before the next kernel dispatch.
- The full DF-MP2 pipeline (
ao_to_mo_transform→mp2_energy) with every operand pre-pinned exposes an NKI compiler bug on trn1: the combined XLA lazy graph provokestrn2-only shared memoryinstructions that fail verification on trn1. Workaround:from_xlathe intermediateBbetween the two calls. Tracked in #39 for upstream AWS escalation.
set_backend("nki")now raisesRuntimeErroron non-Neuron hosts instead of silently accepting the backend and failing later. Matches the sibling-suite pattern.- CI actions bumped to
actions/checkout@v6+actions/setup-python@v6(Node.js 24), ahead of GitHub's June 2026 default switch. - pyproject metadata normalized across the trnsci suite (author email, URLs, classifier list).
- Standalone
docs.ymlremoved — docs are now served viatrnsci.devthrough the umbrella's combined build.notify-umbrella.ymlpings the umbrella on docs changes. infra/terraform/main.tf: user-data clone URL corrected totrnsci/trntensor.
benchmarks/bench_einsum.py— pytest-benchmark cases for einsum dispatch and decompositions. CPU baseline numbers populated indocs/benchmarks.md.tests/test_nki.py— backend-dispatch unit tests (CPU path).
- mkdocs site with
index,installation,quickstart,api,architecture,aws_setup infra/terraform/for on-hardware CI instance provisioningscripts/run_neuron_tests.shand benchmark helpers- GitHub Actions
ci.yml,docs.yml,publish.yml IssuesandDocumentationURLs in pyproject.tomltests/test_plan.py— dedicated planner unit tests (parsing, strategy selection, FLOP estimates); extended CP / Tucker coverage (all-zero tensor, rank > min dim, unequal mode ranks)
- Bumped
neuronxccfloor from>=2.15to>=2.24to unify with the rest of the trnsci suite.torch-neuronxfloor bumped to>=2.9.
- Initial scaffold: einsum with contraction planning, CP / Tucker decompositions
- NKI dispatch with fused-contraction kernel stubs
examples/df_mp2_einsum.py— DF-MP2 energy via einsum