Skip to content

Commit

Permalink
Fix deepcopy of _Sync fns and fix comparison in test_apply_func.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gardner1 committed Nov 7, 2021
1 parent 9130a26 commit fc77d6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from collections.abc import Generator
from dataclasses import asdict, dataclass, replace
from dataclasses import asdict, dataclass, fields, replace
from functools import partial, wraps
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

Expand Down Expand Up @@ -74,6 +74,11 @@ def _generate_sync_fn(self) -> None:
# ignore typing, bad support for `partial`: mypy/issues/1484
self._fn: Callable = partial(fn, reduce_op=self.op, group=self.group) # type: ignore [arg-type]

def __deepcopy__(self, memo: dict) -> "_Sync":
result = _Sync(**{field.name: getattr(self, field.name) for field in fields(self) if field.init})
memo[id(self)] = result
return result

@property
def __call__(self) -> Any:
return self._fn
Expand Down
5 changes: 4 additions & 1 deletion tests/utilities/test_apply_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def __eq__(self, o: object) -> bool:
return NotImplemented
else:
return (
self.example_ids == o.example_ids and self.feature == o.feature and torch.equal(self.label, o.label)
self.example_ids == o.example_ids
and self.feature == o.feature
and torch.equal(self.label, o.label)
and self.some_constant == o.some_constant
)

@dataclasses.dataclass
Expand Down

0 comments on commit fc77d6c

Please sign in to comment.