From 6bfdef727e480fa6c2c8bbbe5fc739c0b8479a91 Mon Sep 17 00:00:00 2001 From: XiaoguangHu <46782768+XiaoguangHu01@users.noreply.github.com> Date: Sun, 10 Jan 2021 20:27:49 -0600 Subject: [PATCH] clean redundant API alias in 2.0 - part 2 (#30013) * delete paddle.nn.functional.assign * fix dynamic to static error --- .../dygraph/dygraph_to_static/basic_api_transformer.py | 6 +++--- python/paddle/fluid/layers/tensor.py | 6 +++--- python/paddle/fluid/tests/unittests/test_inplace.py | 2 +- python/paddle/nn/functional/__init__.py | 1 - python/paddle/nn/functional/common.py | 2 -- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/basic_api_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/basic_api_transformer.py index cf5723a7463..198c2920eec 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/basic_api_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/basic_api_transformer.py @@ -116,14 +116,14 @@ def is_to_variable(node): def to_assign_node(node): - # Transform dygraph api `fluid.dygraph.to_variable` alias `paddle.to_tensor` to static api `paddle.nn.functional.assign`. + # Transform dygraph api `fluid.dygraph.to_variable` alias `paddle.to_tensor` to static api `paddle.assign`. # NOTE: # 1. Api `to_variable` supports data type {float16, float32, float64, int16, int32, int64, uint8, uint16}, # but api `assign` only supports {float32, float64, int32, int64, bool}; # 2. If the input of api `assign` is numpy.ndarray, its size cannot be greater than 1024 * 1024. assert isinstance(node, gast.Call) - assign_api = gast.parse('paddle.nn.functional.assign').body[0].value + assign_api = gast.parse('paddle.assign').body[0].value node.func = assign_api if node.args: @@ -132,7 +132,7 @@ def to_assign_node(node): else: for idx, kw in enumerate(node.keywords): if kw.arg == 'value' or kw.arg == 'data': - node.keywords[idx].arg = 'input' + node.keywords[idx].arg = 'x' node.keywords = [node.keywords[idx]] node.args = [] break diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index d99482d61ca..dcd5495dc1a 100644 --- a/python/paddle/fluid/layers/tensor.py +++ b/python/paddle/fluid/layers/tensor.py @@ -563,9 +563,9 @@ def assign(input, output=None): [3, 4], [1, 3]]).astype(np.int64) result1 = paddle.zeros(shape=[3, 3], dtype='float32') - paddle.nn.functional.assign(array, result1) # result1 = [[1, 1], [3 4], [1, 3]] - result2 = paddle.nn.functional.assign(data) # result2 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]] - result3 = paddle.nn.functional.assign(np.array([[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]], dtype='float32')) # result3 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]] + paddle.assign(array, result1) # result1 = [[1, 1], [3 4], [1, 3]] + result2 = paddle.assign(data) # result2 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]] + result3 = paddle.assign(np.array([[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]], dtype='float32')) # result3 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]] """ helper = LayerHelper('assign', **locals()) check_type(input, 'input', (Variable, numpy.ndarray), 'assign') diff --git a/python/paddle/fluid/tests/unittests/test_inplace.py b/python/paddle/fluid/tests/unittests/test_inplace.py index 45c208293e1..08a7fe80ea1 100644 --- a/python/paddle/fluid/tests/unittests/test_inplace.py +++ b/python/paddle/fluid/tests/unittests/test_inplace.py @@ -30,7 +30,7 @@ class TestInplace(unittest.TestCase): var[0] = 1.1 self.assertEqual(var.inplace_version, 1) - paddle.nn.functional.assign(paddle.ones(shape=[3]), var) + paddle.assign(paddle.ones(shape=[3]), var) # NOTE(liym27): assign(input, output) is an inplace operation for output. # There is inplace-related processing for api assign, var.inplace_version should be 2 not 1. diff --git a/python/paddle/nn/functional/__init__.py b/python/paddle/nn/functional/__init__.py index abe34d2b3d7..501d9fcfd40 100644 --- a/python/paddle/nn/functional/__init__.py +++ b/python/paddle/nn/functional/__init__.py @@ -68,7 +68,6 @@ from .common import pad #DEFINE_ALIAS from .common import cosine_similarity #DEFINE_ALIAS from .common import unfold #DEFINE_ALIAS # from .common import bilinear_tensor_product #DEFINE_ALIAS -from .common import assign #DEFINE_ALIAS from .common import interpolate #DEFINE_ALIAS from .common import upsample #DEFINE_ALIAS from .common import bilinear #DEFINE_ALIAS diff --git a/python/paddle/nn/functional/common.py b/python/paddle/nn/functional/common.py index fac5ca2f793..0859d05af1c 100644 --- a/python/paddle/nn/functional/common.py +++ b/python/paddle/nn/functional/common.py @@ -23,7 +23,6 @@ from ...fluid import dygraph_utils # from ...fluid import one_hot #DEFINE_ALIAS # from ...fluid.layers import pad2d #DEFINE_ALIAS from ...fluid.layers import unfold #DEFINE_ALIAS -from ...fluid.layers import assign #DEFINE_ALIAS from ...fluid.layers import squeeze #DEFINE_ALIAS from ...fluid.layers import unsqueeze #DEFINE_ALIAS from ...tensor import clip @@ -53,7 +52,6 @@ __all__ = [ 'pad', 'unfold', # 'bilinear_tensor_product', - 'assign', 'interpolate', 'upsample', 'bilinear', -- GitLab