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

FlopCountAnalysis issues #153

Open
cavalleria opened this issue Nov 28, 2024 · 0 comments
Open

FlopCountAnalysis issues #153

cavalleria opened this issue Nov 28, 2024 · 0 comments

Comments

@cavalleria
Copy link

i use bellow code to test mha flops. but it's same flops and params when nhead=4 or 8

import torch
import torch.nn as nn


class MHAModel(nn.Module):
    def __init__(self, dim, nhead, dropout):
        super(MHAModel, self).__init__()

        self.mha = nn.MultiheadAttention(dim_out, nhead, dropout=dropout, batch_first=True)

    def forward(self, x):
        x = self.mha(x, x, x)[0]
        return x


from fvcore.nn import FlopCountAnalysis, flop_count_table

dim_out = 448
seq_len = 300
nhead = 4
dropout = 0.1

net = MHAModel(dim=dim_out, nhead=nhead, dropout=dropout)
net.eval()
data = torch.randn((1, seq_len, dim_out))
flops = FlopCountAnalysis(net, (data))
print(flop_count_table(flops, max_depth=4))

image

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

1 participant