Repository navigation
v0.22.0 — einsum correctness fix
Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
Headline: correctness fix: in every release through 0.21.0, on every backend, einsum planned matmul/bmm without checking index order, so transposed or permuted outputs came back in the wrong layout (ij,jk->ki returned A@B, silently for square operands) and non-canonical batched operands raised. 228 of 364 two-operand cases were wrong or raised (#65, #64). Also: df_exchange tiling minimises partial SYRK tiles, so K at n_ao=970 drops from 118 to 94 ms (#66).
Fixed
einsumreturned the wrong layout for transposed or permuted outputs
(silent). Affects every release through 0.21.0, on every backend
(PyTorch included). The planner chose thematmul/bmmstrategy without
checking index order, soeinsum("ij,jk->ki", A, B)returnedA @ B
(shape(i, k), and for square operands the transpose with no error), the
permuted batched outputs (bij,bjk->bkietc.) returned(b, i, k), and
non-canonical batched operands (bji,...,...,bkj,ibj,...) raised.
matmulis now planned only for outputs[A free, B free]andbmmonly
for exactlybij,bjk->bik; the rest run throughtorch.einsum(#64).
Changed
df_exchangetiles naux to minimise the SYRK's partial aux tiles (#66, #60).
K at n_ao = 970 takes 93.8 ms instead of 118 ms at LNC=2, and 187 ms
instead of 230 ms at LNC=1. The error against float64 is 6.2e-7 (was
8.1e-7) relative to max |K|.- Aux chunks can now be 128 multiples with a short last chunk of
naux mod width. Before, the width had to divide naux.
df_half_packed_kerneltakestpandtailand gathers from the packed
rows viewed as(npair·naux / W, W),W = gcd(naux, tp).Bis still
not copied. df_half_tilingfirst minimises the 128-row tiles over the SYRK
launches (df_syrk_tiles), because each partial tile there costs a full
one. Next it prefers a divisor of naux, then the old order.- At naux = 4686 that means chunks of 256 with a 78 tail, 37 tiles
instead of 44. - n_ao = 250 and 490 keep their previous tilings, which already reach
the minimum.
- At naux = 4686 that means chunks of 256 with a 78 tail, 37 tiles
df_groupsfolds a lone short last chunk into the previous launch group.- The launch-1 SBUF budget is now 176 KiB (was 160 KiB), so that
TP = 256, NUB = 8, NVC = 16 fits at n_ao = 970. This tiling is 7 ms
faster than NVC = 8. - naux with no divisor in [32, 512] now runs the kernels, not aten.
TRNTENSOR_DF_K_TPforces the chunk width.
- Aux chunks can now be 128 multiples with a short last chunk of