Whenever you're ready, walk me through how you'd approach this.
How would you implement single-head and multi-head attention in PyTorch, including masking out later tokens?
Implement both modules from first principles rather than calling nn.MultiheadAttention. The implementation should accept batched sequences, apply scaled dot-product attention, prevent each position from attending to future positions, and preserve the expected tensor shapes. Explain how projections, head reshaping, masking, softmax, dropout, and output projection differ between the two implementations. Include a small correctness test demonstrating that future-token attention weights are zero.