Implement a basic self-attention mechanism in PyTorch from scratch for an LLM at Mistral AI, ensuring correct tensor dimensions throughout.