Skip to content

Commit

Permalink
Import ABC from collections.abc for Python 3.10 compatibility. (#1851)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeff Rasley <[email protected]>
  • Loading branch information
tirkarthi and jeffra authored Mar 23, 2022
1 parent 208d45b commit c7af747
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions deepspeed/autotuning/tuner/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import itertools
from ..utils import *
import collections
import collections.abc


def index_to_feature(p, dims):
Expand Down Expand Up @@ -53,7 +53,7 @@ def flatten(d, parent_key='', sep='_'):
items = []
for k, v in d.items():
new_key = parent_key + sep + k if parent_key else k
if isinstance(v, collections.MutableMapping):
if isinstance(v, collections.abc.MutableMapping):
items.extend(flatten(v, new_key, sep=sep).items())
else:
items.append((new_key, v))
Expand Down
5 changes: 3 additions & 2 deletions deepspeed/runtime/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import json
import collections
import collections.abc


# adapted from https://stackoverflow.com/a/50701137/9201239
Expand All @@ -31,13 +32,13 @@ def iterencode(self, o, _one_shot=False, level=0):
return f"{o:e}"
else:
return f"{o}"
elif isinstance(o, collections.Mapping):
elif isinstance(o, collections.abc.Mapping):
x = [
f'\n{prefix}"{k}": {self.iterencode(v, level=level)}' for k,
v in o.items()
]
return "{" + ', '.join(x) + f"\n{prefix_close}" + "}"
elif isinstance(o, collections.Sequence) and not isinstance(o, str):
elif isinstance(o, collections.abc.Sequence) and not isinstance(o, str):
return f"[{ f', '.join(map(self.iterencode, o)) }]"
return "\n, ".join(super().iterencode(o, _one_shot))

Expand Down

0 comments on commit c7af747

Please sign in to comment.