The nn.MultiHeadAttention module returns attn_outpu and attn_output_weights as described in the docs 16. Based on the error message it seems you might be trying to unpack a wrong number of return values.