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 randomness for threading #7925

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion monai/transforms/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ def execute_compose(

for _transform in transforms[start:end]:
if threading:
_transform = deepcopy(_transform) if isinstance(_transform, ThreadUnsafe) else _transform
if isinstance(_transform, ThreadUnsafe):
if isinstance(_transform, Randomizable):
# update the random state before deepcopy, otherwise there is no randomness
_transform.set_random_state()
_transform = deepcopy(_transform)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that this needs a lock

data = apply_transform(
_transform, data, map_items, unpack_items, lazy=lazy, overrides=overrides, log_stats=log_stats
)
Expand Down
Loading