Skip to content

v0.22.0 — einsum correctness fix

Choose a tag to compare

@scttfrdmn scttfrdmn released this 01 Nov 05:57
· 146 commits to main since this release
v0.22.0
998c62e

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

  • einsum returned the wrong layout for transposed or permuted outputs
    (silent). Affects every release through 0.21.0, on every backend
    (PyTorch included). The planner chose the matmul / bmm strategy without
    checking index order, so einsum("ij,jk->ki", A, B) returned A @ B
    (shape (i, k), and for square operands the transpose with no error), the
    permuted batched outputs (bij,bjk->bki etc.) returned (b, i, k), and
    non-canonical batched operands (bji,..., ...,bkj, ibj,...) raised.
    matmul is now planned only for outputs [A free, B free] and bmm only
    for exactly bij,bjk->bik; the rest run through torch.einsum (#64).

Changed

  • df_exchange tiles 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_kernel takes tp and tail and gathers from the packed
      rows viewed as (npair·naux / W, W), W = gcd(naux, tp). B is still
      not copied.
    • df_half_tiling first 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.
    • df_groups folds 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_TP forces the chunk width.