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

Could I compute relative_position_bias in __init__() instead of forward() ? #189

Open
Alobal opened this issue Apr 7, 2022 · 1 comment

Comments

@Alobal
Copy link

Alobal commented Apr 7, 2022

Hi,

the relative_position_bias seems to be a constant index of self.relative_position_bias_table, why should it be computed in forward() every time?

For the code, why the following code can't be computed in WindowAttention.__init__()?

relative_position_bias = self.relative_position_bias_table[self.relative_position_index.view(-1)].view(
        self.window_size[0] * self.window_size[1], self.window_size[0] * self.window_size[1], -1)  # Wh*Ww,Wh*Ww,nH
relative_position_bias = relative_position_bias.permute(2, 0, 1).contiguous()  # nH, Wh*Ww, Wh*Ww

Thank you for your time to solve my confusion~

@Beastmaster
Copy link

I have the same question. relative_position_bias are selected by indexes from a predefined tensor, also it's shape won't change during training

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