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

[refactor] Import ABC from collections.abc for Python 3.10 compatibility #1214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion mmf/common/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def apply_fn(self, fn: Callable, fields: Optional[List[str]] = None):
if key not in fields:
continue
self[key] = fn(self[key])
if isinstance(self[key], collections.MutableSequence):
if isinstance(self[key], collections.abc.MutableSequence):
for idx, item in enumerate(self[key]):
self[key][idx] = fn(item)
elif isinstance(self[key], dict):
Expand Down
2 changes: 1 addition & 1 deletion mmf/common/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def convert_batch_to_sample_list(
def to_device(
sample_list: Union[SampleList, Dict[str, Any]], device: device_type = "cuda"
) -> SampleList:
if isinstance(sample_list, collections.Mapping):
if isinstance(sample_list, collections.abc.Mapping):
sample_list = convert_batch_to_sample_list(sample_list)
# to_device is specifically for SampleList
# if user is passing something custom built
Expand Down
4 changes: 2 additions & 2 deletions mmf/models/transformers/heads/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ def _process_head_output(
head_name: str,
sample_list: Dict[str, Tensor],
) -> Dict[str, Tensor]:
if isinstance(outputs, collections.MutableMapping) and "losses" in outputs:
if isinstance(outputs, collections.abc.MutableMapping) and "losses" in outputs:
return outputs

if isinstance(outputs, collections.MutableMapping) and "scores" in outputs:
if isinstance(outputs, collections.abc.MutableMapping) and "scores" in outputs:
logits = outputs["scores"]
else:
logits = outputs
Expand Down
4 changes: 2 additions & 2 deletions mmf/utils/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) Facebook, Inc. and its affiliates.

import collections
import collections.abc
import functools
import json
import logging
Expand Down Expand Up @@ -288,7 +288,7 @@ def log_progress(info: Union[Dict, Any], log_format="simple"):
caller, key = _find_caller()
logger = logging.getLogger(caller)

if not isinstance(info, collections.Mapping):
if not isinstance(info, collections.abc.Mapping):
logger.info(info)

if log_format == "simple":
Expand Down