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

Question regarding Equation 5 Random Mixing in the Paper #13

Open
f-fuchs opened this issue May 23, 2024 · 1 comment
Open

Question regarding Equation 5 Random Mixing in the Paper #13

f-fuchs opened this issue May 23, 2024 · 1 comment

Comments

@f-fuchs
Copy link

f-fuchs commented May 23, 2024

Should the matrix multiplication not be swapped?

$$ RandomMixing(X) = XW_R \Rightarrow RandomMixing(X) = W_RX $$

I think the dimension don`t work for the original equation because you are multiplying a $N \times C$ matrix with a $N \times N$ matrix. Secondly, in the source code I think you are actually multiplying the weight matrix with the input matrix.

class RandomMixing(nn.Module):
    def __init__(self, num_tokens=196, **kwargs):
        super().__init__()
        self.random_matrix = nn.parameter.Parameter(
            data=torch.softmax(torch.rand(num_tokens, num_tokens), dim=-1), 
            requires_grad=False)
    def forward(self, x):
        B, H, W, C = x.shape
        x = x.reshape(B, H*W, C)
        x = torch.einsum('mn, bnc -> bmc', self.random_matrix, x)
        x = x.reshape(B, H, W, C)
        return x
@yuweihao
Copy link
Collaborator

yuweihao commented May 23, 2024

Hi @f-fuchs , yes, you are right. This is a typo. it should be $W_RX$, I will fix it in the next arXiv version.

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

2 participants