Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems about groups #19

Open
liqi0126 opened this issue Feb 17, 2020 · 4 comments
Open

Problems about groups #19

liqi0126 opened this issue Feb 17, 2020 · 4 comments

Comments

@liqi0126
Copy link

Should not the key_conv, query_conv and value_conv be defined with group parameters? I am not clear what group parameters do in the following lines.

k_out = k_out.contiguous().view(batch, self.groups, self.out_channels // self.groups, height, width, -1)
v_out = v_out.contiguous().view(batch, self.groups, self.out_channels // self.groups, height, width, -1)
q_out = q_out.view(batch, self.groups, self.out_channels // self.groups, height, width, 1)
out = q_out * k_out
out = F.softmax(out, dim=-1)
out = torch.einsum('bnchwk,bnchwk -> bnchw', out, v_out).view(batch, -1, height, width)

@mrngbaeb
Copy link

The 'groups' are not like the groups for group convolutions. In this case, each of the multi-attention heads takes in the full input dimension (not 1/n_groups of it). Computationally, this is done as one convolution and then reshaped to separate the heads.

@liqi0126
Copy link
Author

However, it seems like not to separate k_out, v_out and q_out into groups gives the same out results in the above codes. So what does the group parameter exactly do?

@zenghui420
Copy link

Seems like q_out and k_out should be 'matrix-multiplied' at dim=2 (the one with the size self.out_channels // self.groups).

@xyecoding
Copy link

xyecoding commented Oct 10, 2021

According to the listed code lines, it seems that self.groups has no effect on the result. I beleive no matter how to set self.groups, the code can only realize the case "group=1".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants