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

Handle UserDict in all utils #179

Merged
merged 1 commit into from
Sep 30, 2021
Merged

Handle UserDict in all utils #179

merged 1 commit into from
Sep 30, 2021

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Sep 30, 2021

Currently, all the reclusive utility functions defined in the utils module handle nested lists and dictionaries of a base type (usually tensors) but not UserDict, which is not considered an instance of dict.

This cause problems with the BatchEncoding type in Transformers (which is a UserDict so is not considered a subclass of dict) as pointed out by #178. This PR addresses that issue.

Fixes #178

@sgugger sgugger requested a review from LysandreJik September 30, 2021 16:18
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sgugger sgugger merged commit 5343b4e into main Sep 30, 2021
@sgugger sgugger deleted the handle_user_dict branch September 30, 2021 16:24
@mariosasko
Copy link
Contributor

@sgugger @LysandreJik Instead of adding UserDict to the isinstance class tuple, you can use collections.abc.Mapping to cover both the dict and the UserDict types (e.g. PyTorch DataLoader uses such check in its default collate_fn to stack dict-like objects).

@sgugger
Copy link
Collaborator Author

sgugger commented Sep 30, 2021

Oh thanks for the tip! I will clean the code to use that when I have a bit of time (unless you want to suggest a PR!)

@mariosasko
Copy link
Contributor

I'm busy currently, so probably won't find time to fix this myself.

@mariosasko
Copy link
Contributor

I did find time to fix this, so I've opened a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mixed type batches in data loader
3 participants