Skip to content

fix cachedataset w persistent workers problem by deep copying#2121

Merged
rijobro merged 14 commits intoProject-MONAI:devfrom
rijobro:cachedataset_persistentworkers
May 7, 2021
Merged

fix cachedataset w persistent workers problem by deep copying#2121
rijobro merged 14 commits intoProject-MONAI:devfrom
rijobro:cachedataset_persistentworkers

Conversation

@rijobro
Copy link
Copy Markdown
Contributor

@rijobro rijobro commented Apr 30, 2021

Fixes #2116.

Description

When using CacheDataset combined with persistent_workers=True in the DataLoader, it seems that the <key>_transforms are duplicated for the first random transform onwards.

So for a transform of Compose([Spacingd, RandAffined, ToTensord]), then on the second pass through the data, we would have img_transforms as: Spacing, RandAffined, ToTensord, RandAffined, ToTensord. This implies a shallow copy at some point.

I've put the copy in the CacheDataset but I worry that this may cause unnecessary copying of the data. Having said that, I can't see where else to put it... I'm open to ideas.

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@rijobro rijobro requested review from Nic-Ma, ericspod and wyli and removed request for Nic-Ma April 30, 2021 14:24
Copy link
Copy Markdown
Contributor

@Nic-Ma Nic-Ma left a comment

Choose a reason for hiding this comment

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

Looks good to me.
Could you please help run the CacheDataset tutorial twice with / without deepcopy to make sure it will not affect the training speed and memory usage?
https://github.com/Project-MONAI/tutorials/blob/master/acceleration/dataset_type_performance.ipynb

Thanks.

@Nic-Ma
Copy link
Copy Markdown
Contributor

Nic-Ma commented May 6, 2021

Hi @rijobro ,

Do you have update on this PR?

Thanks.

@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented May 6, 2021

Sorry, put the comment in a resolved conversation. All looks good to me, I'll just have a look at the github action error.

@rijobro
Copy link
Copy Markdown
Contributor Author

rijobro commented May 6, 2021

@wyli @Nic-Ma I don't understand the output of the flake8 check. I re-ran the job just in case, but still don't know what's wrong. Any ideas?

@wyli
Copy link
Copy Markdown
Contributor

wyli commented May 6, 2021

looks like an issue with the latest pytype google/pytype#909

@rijobro rijobro mentioned this pull request May 6, 2021
1 task
@wyli wyli closed this in #2153 May 6, 2021
@wyli wyli reopened this May 6, 2021
@rijobro rijobro enabled auto-merge (squash) May 7, 2021 11:08
@rijobro rijobro merged commit 4259151 into Project-MONAI:dev May 7, 2021
@rijobro rijobro deleted the cachedataset_persistentworkers branch May 7, 2021 12:15
@Nic-Ma
Copy link
Copy Markdown
Contributor

Nic-Ma commented May 7, 2021

BTW, I tested this PR in our CacheDataset tutorial:
https://github.com/Project-MONAI/tutorials/blob/master/acceleration/dataset_type_performance.ipynb

  1. There is no speed or memory usage difference with / without deepcopy.
  2. With "persistent_workers=True", the training speed of every epoch is about 1 second faster.

Thanks.

yanielc pushed a commit to yanielc/MONAI that referenced this pull request May 10, 2021
…t-MONAI#2121)

fix cachedataset w persistent workers problem by deep copying first non-deterministic transform

Signed-off-by: Yaniel Cabrera <[email protected]>
yanielc pushed a commit to yanielc/MONAI that referenced this pull request May 13, 2021
…t-MONAI#2121)

fix cachedataset w persistent workers problem by deep copying first non-deterministic transform

Signed-off-by: Yaniel Cabrera <[email protected]>
yanielc pushed a commit to yanielc/MONAI that referenced this pull request May 13, 2021
…t-MONAI#2121)

fix cachedataset w persistent workers problem by deep copying first non-deterministic transform

Signed-off-by: Yaniel Cabrera <[email protected]>
wyli pushed a commit that referenced this pull request May 26, 2021
fix cachedataset w persistent workers problem by deep copying first non-deterministic transform
wyli pushed a commit that referenced this pull request May 26, 2021
fix cachedataset w persistent workers problem by deep copying first non-deterministic transform
wyli pushed a commit that referenced this pull request May 26, 2021
fix cachedataset w persistent workers problem by deep copying first non-deterministic transform
wyli pushed a commit that referenced this pull request May 26, 2021
fix cachedataset w persistent workers problem by deep copying first non-deterministic transform
wyli pushed a commit that referenced this pull request May 26, 2021
fix cachedataset w persistent workers problem by deep copying first non-deterministic transform
wyli pushed a commit that referenced this pull request May 27, 2021
fix cachedataset w persistent workers problem by deep copying first non-deterministic transform
wyli pushed a commit that referenced this pull request May 27, 2021
fix cachedataset w persistent workers problem by deep copying first non-deterministic transform
wyli pushed a commit that referenced this pull request May 27, 2021
fix cachedataset w persistent workers problem by deep copying first non-deterministic transform
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.

Collate error on the key 'img_transforms' of dictionary data.

3 participants