1 of 35

Large Language Models

Lecture 10

Advanced Attention Mechanisms

Krishnendu Ghosh

2 of 35

Self Attention

3 of 35

Causal (Forward Masked) Attention

4 of 35

Causal (Forward Masked) Attention

5 of 35

Causal (Forward Masked) Attention

6 of 35

Why do we need to do better?

7 of 35

Why do we need to do better?

8 of 35

Why do we need to do better?

9 of 35

Why do we need to do better?

Row 1: "I" predicts: love

Row 2: "I love" predicts: machine

Row 3: "I love machine" predicts: learning

Row 4: "I love machine learning" predicts: next token

​

Q. Is it only for Causal models?

10 of 35

KV Cache based (Forward Masked)

Attention

11 of 35

Sliding Window Attention

12 of 35

Sliding Window Attention

13 of 35

What happens to the KV Cache?

14 of 35

Multi-Head Self Attention

15 of 35

Multi-Query Attention (MQA)

16 of 35

Do we lose out on something?

17 of 35

Uptraining: Converting MHA to MQA

18 of 35

What can still go wrong?

19 of 35

Grouped Query Attention

20 of 35

What did we gain?

21 of 35

So are we all set?

Key Takeaways

22 of 35

A bit more about the GPU

23 of 35

What was happening so far

24 of 35

The magic: Fused Kernel

25 of 35

The magic does not end here!

More optimization

26 of 35

The magic does not end here!

Tiling

27 of 35

Does the story end here?

What’s the problem?

28 of 35

The softmax denominator problem

29 of 35

Summary Statistics: the final touch!

30 of 35

Summary Statistics: the final touch!

31 of 35

How well did they do?

32 of 35

So, finally solved attention hurdle?

33 of 35

Key Takeaways

34 of 35

Want more? Follow:

35 of 35

Source: https://lcs2-iitd.github.io/ELL881-AIL821-2401/lectures/