提交 f5e78a11 编写于 作者: P pangyoki 提交者: jzhang533

Cherry-pick-PR42295, fix collections.Iterable in python3.10

上级 880c2a94
......@@ -16,6 +16,10 @@ import collections
import paddle
from paddle.distribution import categorical, distribution
try:
from collections.abc import Iterable
except:
from collections import Iterable
class Multinomial(distribution.Distribution):
......@@ -138,7 +142,7 @@ class Multinomial(distribution.Distribution):
Args:
sample_shape (tuple, optional): [description]. Defaults to ().
"""
if not isinstance(shape, collections.Iterable):
if not isinstance(shape, Iterable):
raise TypeError('sample shape must be Iterable object.')
samples = self._categorical.sample([self.total_count, ] + list(shape))
......
......@@ -6754,7 +6754,10 @@ def lod_append(x, level):
x = fluid.layers.data(name='x', shape=[6, 10], lod_level=1)
out = fluid.layers.lod_append(x, [1,1,1,1,1,1])
"""
from collections import Iterable
try:
from collections.abc import Iterable
except:
from collections import Iterable
if x is None:
raise ValueError("Input(x) can't be None.")
if (not isinstance(level, Iterable)) and (not isinstance(level, Variable)):
......
......@@ -34,6 +34,10 @@ from paddle.fluid.framework import Variable, _varbase_creator, _dygraph_tracer,
from paddle.fluid.dygraph.jit import _SaveLoadConfig
from paddle.fluid.dygraph.io import _construct_program_holders, _construct_params_and_buffers
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX, INFER_PARAMS_INFO_SUFFIX
try:
from collections.abc import Iterable
except:
from collections import Iterable
__all__ = []
......@@ -424,7 +428,7 @@ def _parse_every_object(obj, condition_func, convert_func):
elif type(obj) == set:
return set(_parse_every_object(list(obj), condition_func, convert_func))
else:
if isinstance(obj, collections.Iterable) and not isinstance(
if isinstance(obj, Iterable) and not isinstance(
obj,
(str, np.ndarray, core.VarBase, core.eager.Tensor, core.LoDTensor)):
raise NotImplementedError(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册