torchinfo icon indicating copy to clipboard operation
torchinfo copied to clipboard

AttributeError: 'tuple' object has no attribute 'size'

Open lan2720 opened this issue 2 years ago • 1 comments

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

from transformers import BertModel
from torchinfo import summary

bert_base_path =  '/my/local/path/to/bert-base-chinese'

teacher_encoder = BertModel.from_pretrained(bert_base_path)
teacher_encoder.config.output_hidden_states = True
# teacher_encoder.config.num_labels = len(config["ner_labels"])
summary(teacher_encoder, input_size=[(2,512), (2,512), (2,512)],
        dtypes=['torch.IntTensor', 'torch.IntTensor', 'torch.IntTensor'],
        device='cpu')
  • Version torchinfo 1.5.4(pip install)

image

lan2720 avatar May 20 '22 07:05 lan2720

This is happening because torchinfo currently does not have a sophisticated way of handling dicts containing tensors.

Would appreciate PRs improving this functionality! The calculate_size function is where the changes should occur.

TylerYep avatar May 20 '22 08:05 TylerYep

https://github.com/TylerYep/torchinfo/blob/ed0a7aa3f61171d2a7f4af8e7958124304c7ef91/torchinfo/layer_info.py#L127-L134

@TylerYep What is the current dev roadmap for this function calculate_size? Would you take a PR that adds this functionality supporting dicts containing lists or tuples?

scaomath avatar Jan 18 '23 21:01 scaomath

Yes, PRs are welcome (but check the current Pull Requests first, there may be other contributors working on the exact same functionality)

TylerYep avatar Jan 18 '23 21:01 TylerYep