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] fix data race risk of cache_randomness #2927

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Changes from all commits
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 mmcv/transforms/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved.

import copy
import functools
import inspect
import weakref
Expand Down Expand Up @@ -80,7 +81,10 @@ def __call__(self, *args, **kwargs):

def __get__(self, obj, cls):
self.instance_ref = weakref.ref(obj)
return self
# Return a copy to avoid multiple transform instances sharing
# one `cache_randomness` instance, which may cause data races
# in multithreading cases.
return copy.copy(self)
zhouzaida marked this conversation as resolved.
Show resolved Hide resolved
ly015 marked this conversation as resolved.
Show resolved Hide resolved


def avoid_cache_randomness(cls):
Expand Down
Loading