MrYxJ / calculate-flops.pytorch

The calflops is designed to calculate FLOPs、MACs and Parameters in all various neural networks, such as Linear、 CNN、 RNN、 GCN、Transformer(Bert、LlaMA etc Large Language Model)
https://pypi.org/project/calflops/
MIT License
587 stars 21 forks source link

How to calculate model with more than one input? #17

Open yuanzhi-zhu opened 9 months ago

yuanzhi-zhu commented 9 months ago

For models with two inputs, can I wrapper them like this?

class Wrapper(nn.Module):
    def __init__(self, model):
        super(Wrapper, self).__init__()
        self.model = model
    def forward(self, x):
        class_labels = torch.eye(1000, device=device)[torch.randint(0, 1000, (x.shape[0],))]
        return self.model(x, class_labels)