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

Fix max_depth recursion crash in AsynchronousLoader #191

Merged
merged 5 commits into from Sep 11, 2020

Conversation

DaGuT
Copy link
Contributor

@DaGuT DaGuT commented Sep 8, 2020

Some people use dict samples with strings, numpy array etc. They are returned from dataloader and are passed to model. Later those are parsed/replaced/removed inside of step/forward function.

Example of such dict (I use it):
{'image': tensor([WHATEVER]), 'path': [WHATEVER_STRING], 'target': tensor([WHATEVER_NUMPY]), 'meta': {'PatientAge': tensor([WHATEVER]), 'PatientSex': tensor([WHATEVER]), 'StudyDate': tensor([WHATEVER])}, 'mask': tensor([WHATEVER]), 'bboxes': [[tensor([WHATEVER]), tensor([WHATEVER]), tensor([WHATEVER])]]}

Sadly, async loader was crashing as max depth of recursion was reached (e.g. when it meets string, it just infinitely goes to else in original AsyncLoader).

I went to torch.utils.data.default_collate (as it's said that code is based on it), took few lines from there and it works now. :)

So it will no longer crash at named_tuples, dict-like objects and strings. Those will all be processed.

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs? (no need, it's just a small bugfix)
  • Did you write any new necessary tests?

What does this PR do?

Fixes issue when anything other than torch.tensor containing thing is passed to AsynchronousLoader (more details above)

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

Some people use dict samples with strings, numpy array etc. They are returned from dataloader and are passed to model. Later those are parsed/replaced/removed inside of step/forward function.

Example of such dict (I use it):
`{'image': tensor([WHATEVER]), 'path': [WHATEVER_STRING], 'target': tensor([WHATEVER_NUMPY]), 'meta': {'PatientAge': tensor([WHATEVER]), 'PatientSex': tensor([WHATEVER]), 'StudyDate': tensor([WHATEVER])}, 'mask': tensor([WHATEVER]), 'bboxes': [[tensor([WHATEVER]), tensor([WHATEVER]), tensor([WHATEVER])]]}`

Sadly, async loader was crashing as max depth of recursion was reached (e.g. when it meets string, it just infinitely goes to else in original AsyncLoader). 

I went to torch.utils.data.default_collate (as it's said that code is based on it), took few lines from there and it works now.

So it will no longer crash at named_tuples, dict-like objects and strings. Those will all be processed.
@mergify mergify bot requested a review from Borda September 8, 2020 10:53
@DaGuT DaGuT closed this Sep 8, 2020
@DaGuT DaGuT reopened this Sep 8, 2020
@codecov
Copy link

codecov bot commented Sep 8, 2020

Codecov Report

Merging #191 into master will decrease coverage by 0.24%.
The diff coverage is 14.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #191      +/-   ##
==========================================
- Coverage   87.81%   87.57%   -0.25%     
==========================================
  Files          89       89              
  Lines        4236     4250      +14     
==========================================
+ Hits         3720     3722       +2     
- Misses        516      528      +12     
Flag Coverage Δ
#unittests 87.57% <14.28%> (-0.25%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pl_bolts/datamodules/async_dataloader.py 21.21% <14.28%> (-1.87%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5326c69...d04a41e. Read the comment docs.

@pep8speaks
Copy link

pep8speaks commented Sep 8, 2020

Hello @DaGuT! Thanks for updating this PR.

Line 19:1: W293 blank line contains whitespace

Comment last updated at 2020-09-08 11:38:16 UTC

@DaGuT
Copy link
Contributor Author

DaGuT commented Sep 8, 2020

Small note:
Idk if it is related to the patch, but with AsyncLoader it works almost twice slower than without (batch 12, q_size=12).

@Borda Borda added the fix fixing issues... label Sep 10, 2020
@williamFalcon williamFalcon merged commit 850db3d into Lightning-Universe:master Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix fixing issues...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants