I don’t get an error, which would state that kdim and vdim should be equal to the embed_dim as seen here:
embed_dim = 10
num_heads = 2

multihead_attn = nn.MultiheadAttention(embed_dim, num_heads)

L, S, N, E = 2, 3, 4, embed_dim
query = torch.randn(L, N, E)
key = torch.randn(S, N, E)
value = torch.randn(S, N, E)
attn_output, attn_output_weights = multihead_attn(query, key, value)


# with different kdim, vdim
kdim = 5
vdim = 6
multihead_attn = nn.MultiheadAttention(embed_dim, num_heads, kdim=kdim, vdim=vdim)

L, S, N, E = 2, 3, 4, embed_dim
query = torch.randn(L, N, E)
key = torch.randn(S, N, kdim)
value = torch.randn(S, N, vdim)
attn_output, attn_output_weights = multihead_attn(query, key, value)

Could you post a code snippet to reproduce this issue, as I might misunderstand it?