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

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

Closed
lan2720 opened this issue May 20, 2022 · 3 comments · Fixed by #212
Closed

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

lan2720 opened this issue May 20, 2022 · 3 comments · Fixed by #212
Labels
good first issue Good for newcomers

Comments

@lan2720
Copy link

lan2720 commented May 20, 2022

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

@TylerYep TylerYep added the good first issue Good for newcomers label May 20, 2022
@TylerYep
Copy link
Owner

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.

@scaomath
Copy link

elif isinstance(inputs, dict):
# TODO avoid overwriting the previous size every time
size = []
elem_bytes = list(inputs.values())[0].element_size()
for _, output in inputs.items():
size = list(output.size())
if batch_dim is not None:
size = [size[:batch_dim] + [1] + size[batch_dim + 1 :]]

@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?

@TylerYep
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
3 participants