Matrix Multiplier

Experimental alpha. Expect breaking changes and major bugs. Your feedback is much appreciated.

Matrix Multiplier

Multiplies two grids of numbers, the main input on the left and the side input on the right. In attention it does two jobs: comparing every query with every key, with Transpose on, and mixing the values by the weights that come out of the softmax.

matrix multiplication

Shapes

[…×n×k] and […×k×m] in, […×n×m] out. With Transpose on, the side input is […×m×k]. The sizes in front must match, or the side input can be a single [k×m] grid shared by all.

Settings

  • Transpose: off by default. Flips the side input's last two sizes before multiplying.

Parameters

None: both inputs come from other machines.

In PyTorch

scores = q @ k.transpose(-2, -1)
mixed = weights @ v

Making it

The Fabricator makes it from a photomask of Matrix Multiply: verify the spec on a Bench, or find a salvaged mask in the ruins, which makes it unfused. See The Bench and the Fabricator.