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

Results gathering with varying tensor shapes (e.g. last batch) #3019

Closed
awaelchli opened this issue Aug 17, 2020 · 1 comment · Fixed by #3020
Closed

Results gathering with varying tensor shapes (e.g. last batch) #3019

awaelchli opened this issue Aug 17, 2020 · 1 comment · Fixed by #3020
Assignees
Labels
bug Something isn't working help wanted Open to be worked on

Comments

@awaelchli
Copy link
Member

awaelchli commented Aug 17, 2020

🐛 Bug

Results object reduction when batch sizes are different won't work because torch.stack get's different input shapes. This can happen if your dataloader returns a smaller batch for the last iteration, for example.

def recursive_stack(result: MutableMapping):
    for k, v in result.items():
        if isinstance(v, dict):
            recursive_stack(v)
        if isinstance(v, list) and len(v) > 0 and isinstance(v[0], torch.Tensor):
            v = torch.stack(v)
            result[k] = v

Context
From slack discussion by @artgor
https://pytorch-lightning.slack.com/archives/CRBLFHY79/p1597604494424600

@awaelchli awaelchli added bug Something isn't working help wanted Open to be worked on labels Aug 17, 2020
@awaelchli awaelchli self-assigned this Aug 17, 2020
@awaelchli
Copy link
Member Author

will submit a PR within the next hours

@awaelchli awaelchli changed the title Results reduction when batch size changes over time (e.g. last batch) Results gathering with varying tensor shapes (e.g. last batch) Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Open to be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant