未验证 提交 3d6fb260 编写于 作者: P pangyoki 提交者: GitHub

fix collections.Iterable in python3.10 (#42295)

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