def init(self, ...):
        # Create matrices: Q, K, V, out_proj
        ...
    def forward(self, x, context=None, mask=None):
       # Compute out = SoftMax(Q*K/sqrt(d))V
       # Return out_proj(out)
       …

gets replaced with


class CrossAttention(nn.Module):
    def init(self, ...):
        self.mha = nn.MultiheadAttention(...)
    def forward(self, x, context):
    return self.mha(x, context, context)
```