-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Fix v2 transforms in spawn mp context #8067
Changes from all commits
ad22dca
9e584c7
5132eab
52f05fb
b8e2e1b
e948758
33dc494
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -6,6 +6,7 @@ | |||
|
||||
import contextlib | ||||
from collections import defaultdict | ||||
from copy import copy | ||||
|
||||
import torch | ||||
|
||||
|
@@ -198,8 +199,19 @@ def __getitem__(self, idx): | |||
def __len__(self): | ||||
return len(self._dataset) | ||||
|
||||
# TODO: maybe we should use __getstate__ and __setstate__ instead of __reduce__, as recommended in the docs. | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See just above this link There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can try, but I think it is not possible. The "state" in |
||||
def __reduce__(self): | ||||
return wrap_dataset_for_transforms_v2, (self._dataset, self._target_keys) | ||||
# __reduce__ gets called when we try to pickle the dataset. | ||||
# In a DataLoader with spawn context, this gets called `num_workers` times from the main process. | ||||
|
||||
# We have to reset the [target_]transform[s] attributes of the dataset | ||||
# to their original values, because we previously set them to None in __init__(). | ||||
dataset = copy(self._dataset) | ||||
dataset.transform = self.transform | ||||
dataset.transforms = self.transforms | ||||
dataset.target_transform = self.target_transform | ||||
|
||||
return wrap_dataset_for_transforms_v2, (dataset, self._target_keys) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH, I don't really understand why we needed to have The whole logic seems really strange, i.e. calling yet again
@pmeier can you remind me the details of this? Do you think we could support pickleability of these datasets in a different way that would require this "fix"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
by default. Thus, we implement the We have the dynamic type in the first place to support |
||||
|
||||
|
||||
def raise_not_supported(description): | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails, I think it's because Kinetics doesn't convert its
transform
attribute into atransforms
attribute, but I haven't double-checked. If that's OK I'd like to merge this PR right now to get it behind us, and investigate that separately just after.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK with investigating later. Will have a look.