torchinfo
torchinfo copied to clipboard
AttributeError: 'tuple' object has no attribute 'size'
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)
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.
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?
Yes, PRs are welcome (but check the current Pull Requests first, there may be other contributors working on the exact same functionality)