That's for one head and one sequence, in fp16: 16-bit floats, 2 bytes each. A MiB is 220 bytes. At T=8,192 the score matrix holds 67 million scores, 128 MiB, before you store the weights or anything for the backward pass.
Scores per head, by length
T = 4
16
T = 8
64
Double the length, and the scores quadruple.
Double the context and the matrix gets four times bigger. Memory grows with the square of the context.
In the editor, write score_mib(T, heads, batch, bytes_per): the memory of every score matrix in a batch. The second line is a model with 32 heads and a batch of 8 at 4,096 tokens.
Pick an answer above to see the rest
Instructions
1
Write score_mib(T, heads=1, batch=1, bytes_per=2): the memory of one T by T score matrix for each head of each sequence, in MiB.
2
A MiB is 2**20 bytes, and fp16 takes 2 bytes per score.