Skip to content

add lazily filled dict for prototype datasets #5219

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

Closed
wants to merge 3 commits into from

Conversation

pmeier
Copy link
Collaborator

@pmeier pmeier commented Jan 19, 2022

This is my proposed solution to #5187 (comment). Since we only need the mapping during iteration, we can also delay its instantiation until then. Thoughts?

cc @pmeier @bjuncek

@facebook-github-bot
Copy link

facebook-github-bot commented Jan 19, 2022

💊 CI failures summary and remediations

As of commit ff79a88 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

image_files_map = dict(
(image_id, rel_posix_path.rsplit("/", maxsplit=1)[1]) for image_id, rel_posix_path in image_files_dp
)
image_files_dp = Mapper(image_files_dp, self._2011_image_key, input_col=1)
Copy link
Contributor

Choose a reason for hiding this comment

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

What we can do here is a in_memory_cache over image_files_dp. Then, we could add an API to convert a IterDataPipe to a lazy loaded MapDataPipe to represent the LazyDict.
If we use LazyDict here, I have concern that image_files_map would be missing from the DataLoader graph.
cc: @VitalyFedyunin

Copy link
Contributor

Choose a reason for hiding this comment

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

Besides, I think the DataLoader would complain this datapipe graph in the second epoch because image_files_dp is never used after the first epoch then Demux would also be non-serializable same as the comment I made in the other PR.

So, a fix from Demux is not avoidable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seems like a good thing to test in general. What should a test look like. Is something like

for _ in dataset.cycle(2):
    pass

enough? If yes, my proposal passes this test.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean if we put the dataset (datapipes) into DataLoader, the second epoch of DataLoader would break.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So something like

data_loader = DataLoader2(dataset)

for epoch in range(2):
    for sample in data_loader:
        pass

?

Copy link
Contributor

@ejguan ejguan Jan 19, 2022

Choose a reason for hiding this comment

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

Yeah. I have asked Kevin to fix such issue in demux.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My proposal still works. I've pushed the test I'm running against. There are multiple failures for other datasets, but cub200 is not one of them.

@@ -173,9 +177,8 @@ def _make_datapipe(
)

Copy link
Contributor

Choose a reason for hiding this comment

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

A second thought. Could we simply filter image_files_dp from archive_dp here and create the image_files_map dictionary?

Then, we can do demux over archive_dp again and drop data in image_files_dp.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So basically splitting of image_files_dp from the graph?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. Then, we can materialize the data from it like a meta-datapipe.

@pmeier
Copy link
Collaborator Author

pmeier commented May 24, 2022

The agreed upon idiom is that we can iterate before the full pipeline is built, but we have to exhaust it completely. See #6065 for fixes to ImageNet and CUB200.

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

Successfully merging this pull request may close these issues.

3 participants