podcasts / The attention family / episode / question
Question

Why is implementing multi-head attention with a for loop slow?

Answered from Introduction to Multi-Head Attention (MHA) | The attention family series - Lecture 8 · The attention family · 2026-10-03

Sreedath Panat times a loop-based multi-head attention wrapper in Google Colab: one forward pass took 0.003 seconds with 2 heads, about an order of magnitude longer with 400 heads, and 0.63 seconds with 4,000 heads. The reason he gives is that every head adds its own separate matrix multiplication, and a GPU handles many small separate multiplications far less efficiently than one large one, since each has to be shipped, loaded and returned. He adds that the latency hits inference as well as training.

Source: our own transcription of the episode. The full conversation is on The attention family (2026-10-03). Read the whole episode summary →

▸More from this episode

Q1Why do transformers use multiple attention heads, according to Vizuara?Q2How are the outputs of multiple attention heads combined into one context vector per token?Q3How many dimensions does each attention head get in GPT-2 and GPT-3?Q5What is the weight split approach to multi-head attention that Vizuara teaches?Q6Why do you transpose dimensions 1 and 2 when computing batched multi-head attention?
Transcribe your links. Paste a YouTube, Google Drive or podcast link and WhipScribe gives you the transcript. Transcribe a link →