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

Bug fix: MultiOutSizeLinear masks outputs to 0 when dimension of parameter >1 and dim * patch_size is not present in out_feat_size. #46

Merged
merged 2 commits into from
May 29, 2024

Conversation

gorold
Copy link
Contributor

@gorold gorold commented May 26, 2024

This PR fixes a major bug for the MultiOutSizeLinear class.

When dim > 1 in the following code snippet,

self.proj = convert_to_module(
tree_map(
lambda dim: (
proj_layer(in_features, dim * out_features, **kwargs)
if isinstance(out_features, int)
else proj_layer(
in_features, tuple(dim * of for of in out_features), **kwargs
)
),
args_dim,
)
)

it causes for feat_size in self.out_features_ls be dim * patch_size, whereas out_feat_size contains the patch sizes. This means that certain patch sizes could be ignored.
for idx, feat_size in enumerate(self.out_features_ls):
weight = self.weight[idx] * self.mask[idx]
bias = self.bias[idx] if self.bias is not None else 0
out = out + (
torch.eq(out_feat_size, feat_size).unsqueeze(-1)
* (einsum(weight, x, "out inp, ... inp -> ... out") + bias)
)

For the current configuration, this means that outputs with patch sizes 8 and 16 are always masked to 0.

Closes #44

@gorold gorold changed the title Bug fix: MultiOutSizeLinear masks outputs to 0 when dimension of parameter >1 and dim * patch_size is not present in out_features_ls. Bug fix: MultiOutSizeLinear masks outputs to 0 when dimension of parameter >1 and dim * patch_size is not present in out_feat_size. May 26, 2024
@gorold
Copy link
Contributor Author

gorold commented May 29, 2024

lgtm :)

@gorold gorold merged commit f217492 into main May 29, 2024
1 check passed
@gorold gorold deleted the bug/out-proj-mask branch May 29, 2024 06:44
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

Successfully merging this pull request may close these issues.

weights_logits:4 the MultiOutSizeLinear.forward out is alwayls zero
1 participant