Implement MultiHeadSelfAttention(d_model, num_heads) as an nn.Module. The constructor must:
d_model is divisible by num_heads. Let d_head = d_model // num_heads.nn.Linear(d_model, d_model) projections, all bias-free: self.q_proj, self.k_proj, self.v_proj, self.out_proj.The forward(x, mask=None) method takes input of shape (B, T, d_model) and:
x to queries, keys, and values.(B, num_heads, T, d_head).mask is provided (shape (T, T) of 0 and -inf), adds it to the scores before softmax.V and reshapes back to (B, T, d_model).out_proj and returns.view + one transpose to get the head axis next to the batch axis.-inf entries become zero post-softmax.