Start by outlining the Transformer architecture and the typical bug-prone areas, then systematically inspect each component (attention, residual, dropout, positional encoding) for correctness. For each bug, explain the expected behavior, why the current implementation is wrong, and provide a corrected version with justification.
Pro tip: Demonstrate deep understanding by not only fixing bugs but also explaining how each bug would manifest during training (e.g., loss divergence, poor performance) and how to test for it.
Sketch the Transformer's data flow and identify all components that could contain bugs, such as attention, feed-forward, residual connections, layer normalization, dropout, and positional encoding.
Check scaling of QK^T, masking (padding and causal), softmax dimension, and tensor shapes for multi-head attention. Verify that the scaling factor is 1/sqrt(d_k) and masks are applied correctly before softmax.
Ensure residual connections are added correctly (e.g., x + sublayer(x)) and layer normalization is applied appropriately (pre-norm vs post-norm). Check for missing residual connections or incorrect order.
Verify dropout is applied only during training and in the correct places (after attention, after feed-forward, on embeddings). Ensure positional encoding is added to embeddings and not mixed up with other tensors.
Trace tensor shapes through the network to catch shape mismatches. For each bug found, explain the correct implementation and provide a fix, ensuring consistency with the original Transformer paper.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.