Understand and implement the attention mechanism, a key element of transformer-based LLMs, using PyTorch.