{ "lesson": "61-cross-attention-fusion", "title": "Cross-Attention Fusion", "questions": [ { "stage": "pre", "question": "What is the operational difference between early fusion and late fusion in vision-language modeling?", "options": [ "Late fusion uses more memory", "Early fusion is illegal", "Early fusion concatenates image and text tokens into one sequence; late fusion keeps them separate and bridges via cross-attention at each block", "Early fusion runs first in wall-clock time" ], "correct": 2, "explanation": "Chameleon and Emu3 are early-fusion; Flamingo and BLIP-2 are late-fusion. The architectural choice changes mask shapes and KV caching." }, { "stage": "pre", "question": "In a decoder block with both self-attention and cross-attention, which one uses a causal mask?", "options": [ "Neither", "Both", "Cross-attention only", "Self-attention only; the image is fully observed and cross-attention has no temporal order" ], "correct": 3, "explanation": "Text generation is autoregressive, so text self-attention is causal. Image tokens are all visible before any text is decoded." }, { "stage": "check", "question": "Why is the cross-attention KV cache built once per image?", "options": [ "Image keys and values do not change as text is decoded, so projecting memory once and reusing the K and V across all decode steps is the whole inference speedup", "It avoids using the GPU", "PyTorch requires caching", "Caching saves disk space" ], "correct": 0, "explanation": "The vision encoder runs once. Its KV projection is computed once. Each text token reuses the cache for free." }, { "stage": "check", "question": "What is the output shape of cross-attention when text length is Nt=10 and image length is Nv=197 with hidden=256?", "options": [ "(B, 10, 256)", "(B, 207, 256)", "(B, 10, 197)", "(B, 197, 256)" ], "correct": 0, "explanation": "Cross-attention output shape follows the query stream, so output is (B, Nt, hidden) regardless of key length." }, { "stage": "check", "question": "Why is no mask used on cross-attention?", "options": [ "Masks always cause NaN", "Masks are too expensive", "The image is fully observed before text generation begins; every text position may attend to every patch", "PyTorch does not support cross masks" ], "correct": 2, "explanation": "There is no temporal order on image patches and no leakage to prevent, so cross-attention sees the whole image." }, { "stage": "post", "question": "Which extension would you add to recover Flamingo-style stability during training?", "options": [ "Remove the FFN", "Insert a learned tanh gate on the cross-attention residual so the model can start from text-only behavior and grow into the image stream", "Drop the self-attention layer", "Use only one attention head" ], "correct": 1, "explanation": "Flamingo's tanh gate starts at zero, recovers text-only behavior at init, and gives the model a smooth ramp into cross-attention." } ] }