From 9ff3ab7c476b6632568350614c8baef25d0f9486 Mon Sep 17 00:00:00 2001 From: zoooo0820 Date: Mon, 31 Oct 2022 11:04:43 +0000 Subject: [PATCH 1/3] remove functions not belong to public-api from __all__ --- python/paddle/audio/datasets/esc50.py | 2 +- python/paddle/audio/datasets/tess.py | 2 +- python/paddle/distributed/communication/__init__.py | 2 -- python/paddle/geometric/message_passing/__init__.py | 6 +----- python/paddle/geometric/sampling/__init__.py | 4 +--- python/paddle/incubate/multiprocessing/__init__.py | 2 -- python/paddle/tensor/ops.py | 9 --------- 7 files changed, 4 insertions(+), 23 deletions(-) diff --git a/python/paddle/audio/datasets/esc50.py b/python/paddle/audio/datasets/esc50.py index 1d3e0e07baf74..b50845eda2ebb 100644 --- a/python/paddle/audio/datasets/esc50.py +++ b/python/paddle/audio/datasets/esc50.py @@ -20,7 +20,7 @@ from paddle.dataset.common import DATA_HOME from .dataset import AudioClassificationDataset -__all__ = ['ESC50'] +__all__ = [] class ESC50(AudioClassificationDataset): diff --git a/python/paddle/audio/datasets/tess.py b/python/paddle/audio/datasets/tess.py index b180d704e6824..a379aedc6026b 100644 --- a/python/paddle/audio/datasets/tess.py +++ b/python/paddle/audio/datasets/tess.py @@ -20,7 +20,7 @@ from paddle.dataset.common import DATA_HOME from .dataset import AudioClassificationDataset -__all__ = ['TESS'] +__all__ = [] class TESS(AudioClassificationDataset): diff --git a/python/paddle/distributed/communication/__init__.py b/python/paddle/distributed/communication/__init__.py index 95d6c31580a88..97043fd7ba688 100644 --- a/python/paddle/distributed/communication/__init__.py +++ b/python/paddle/distributed/communication/__init__.py @@ -11,5 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -__all__ = ["stream"] diff --git a/python/paddle/geometric/message_passing/__init__.py b/python/paddle/geometric/message_passing/__init__.py index f215e5be74a48..c07f9bc40c6b3 100644 --- a/python/paddle/geometric/message_passing/__init__.py +++ b/python/paddle/geometric/message_passing/__init__.py @@ -16,8 +16,4 @@ from .send_recv import send_ue_recv # noqa: F401 from .send_recv import send_uv # noqa: F401 -__all__ = [ - 'send_u_recv', - 'send_ue_recv', - 'send_uv', -] +__all__ = [] diff --git a/python/paddle/geometric/sampling/__init__.py b/python/paddle/geometric/sampling/__init__.py index 282fb8fd56792..2e5b24fdd60b7 100644 --- a/python/paddle/geometric/sampling/__init__.py +++ b/python/paddle/geometric/sampling/__init__.py @@ -14,6 +14,4 @@ from .neighbors import sample_neighbors # noqa: F401 -__all__ = [ - 'sample_neighbors', -] +__all__ = [] diff --git a/python/paddle/incubate/multiprocessing/__init__.py b/python/paddle/incubate/multiprocessing/__init__.py index 27c23be3a8941..df0f98f74d58b 100644 --- a/python/paddle/incubate/multiprocessing/__init__.py +++ b/python/paddle/incubate/multiprocessing/__init__.py @@ -19,8 +19,6 @@ from multiprocessing import * # noqa: F403 -__all__ += multiprocessing.__all__ # type: ignore[attr-defined] - # Only support linux for now # Only support file_system sharing strategy. diff --git a/python/paddle/tensor/ops.py b/python/paddle/tensor/ops.py index 4c3f7c55c494b..60fdfe927af9e 100644 --- a/python/paddle/tensor/ops.py +++ b/python/paddle/tensor/ops.py @@ -73,9 +73,6 @@ __all__ = [] -for _OP in set(__all__): - globals()[_OP] = generate_layer_fn(_OP) - # It is a hot fix in some unittest using: # fluid.layers.scale(x=x, scale=10.0, out=out_var) # e.g.: test_program_code.py, test_dist_train.py @@ -83,10 +80,6 @@ globals()['_elementwise_div'] = generate_layer_fn('elementwise_div') -__all__ += __activations_noattr__ -__all__ += __unary_func__ -__all__ += __inplace_unary_func__ - for _OP in set(__activations_noattr__): _new_OP = _OP if _OP in __deprecated_func_name__: @@ -506,8 +499,6 @@ """) -__all__ += ['erf'] - _erf_ = generate_layer_fn('erf') From 30760c1ad6bb64a59a76c240c891966ed1437efd Mon Sep 17 00:00:00 2001 From: zoooo0820 Date: Wed, 2 Nov 2022 06:51:37 +0000 Subject: [PATCH 2/3] fix code style --- python/paddle/tensor/ops.py | 184 ++++++++++++++++++++++++------------ 1 file changed, 125 insertions(+), 59 deletions(-) diff --git a/python/paddle/tensor/ops.py b/python/paddle/tensor/ops.py index 60fdfe927af9e..f056bda6157f2 100644 --- a/python/paddle/tensor/ops.py +++ b/python/paddle/tensor/ops.py @@ -14,17 +14,27 @@ from __future__ import print_function import os -from .layer_function_generator import generate_layer_fn, generate_activation_fn, generate_inplace_fn, add_sample_code +from .layer_function_generator import ( + generate_layer_fn, + generate_activation_fn, + generate_inplace_fn, + add_sample_code, +) from ..framework import core from ..framework import convert_np_dtype_to_dtype_ from ..static import Variable -from ..fluid.data_feeder import convert_dtype, check_variable_and_dtype, check_type, check_dtype +from ..fluid.data_feeder import ( + convert_dtype, + check_variable_and_dtype, + check_type, + check_dtype, +) from ..fluid.framework import in_dygraph_mode from .. import _C_ops, _legacy_C_ops __deprecated_func_name__ = { 'tanh_shrink': 'tanhshrink', - 'logsigmoid': 'log_sigmoid' + 'logsigmoid': 'log_sigmoid', } __activations_noattr__ = [ @@ -102,7 +112,8 @@ globals()[_OP] = _func add_sample_code( - globals()["sigmoid"], r""" + globals()["sigmoid"], + r""" Examples: .. code-block:: python @@ -114,10 +125,12 @@ print(out) # [0.40131234 0.450166 0.52497919 0.57444252] -""") +""", +) add_sample_code( - globals()["silu"], r""" + globals()["silu"], + r""" Examples: .. code-block:: python @@ -129,10 +142,12 @@ print(out) # [ 0.7310586 1.7615942 2.8577224, 3.9280552 ] -""") +""", +) add_sample_code( - globals()["logsigmoid"], r""" + globals()["logsigmoid"], + r""" Examples: .. code-block:: python @@ -144,10 +159,12 @@ print(out) # [-0.91301525 -0.79813887 -0.64439666 -0.55435524] -""") +""", +) add_sample_code( - globals()["exp"], r""" + globals()["exp"], + r""" Examples: .. code-block:: python @@ -158,10 +175,12 @@ print(out) # [0.67032005 0.81873075 1.10517092 1.34985881] -""") +""", +) add_sample_code( - globals()["expm1"], r""" + globals()["expm1"], + r""" Examples: .. code-block:: python @@ -172,10 +191,12 @@ print(out) # [-0.32967997, -0.18126924, 0.10517092, 0.34985882] -""") +""", +) add_sample_code( - globals()["tanh"], r""" + globals()["tanh"], + r""" Examples: .. code-block:: python @@ -186,10 +207,12 @@ print(out) # [-0.37994896 -0.19737532 0.09966799 0.29131261] -""") +""", +) add_sample_code( - globals()["atan"], r""" + globals()["atan"], + r""" Examples: .. code-block:: python @@ -200,10 +223,12 @@ print(out) # [-0.38050638 -0.19739556 0.09966865 0.29145679] -""") +""", +) add_sample_code( - globals()["tanh_shrink"], r""" + globals()["tanh_shrink"], + r""" Examples: .. code-block:: python @@ -215,10 +240,12 @@ print(out) # [-0.020051, -0.00262468, 0.000332005, 0.00868739] -""") +""", +) add_sample_code( - globals()["sqrt"], r""" + globals()["sqrt"], + r""" Examples: .. code-block:: python @@ -229,10 +256,12 @@ print(out) # [0.31622777 0.4472136 0.54772256 0.63245553] -""") +""", +) add_sample_code( - globals()["rsqrt"], r""" + globals()["rsqrt"], + r""" Examples: .. code-block:: python @@ -243,10 +272,12 @@ print(out) # [3.16227766 2.23606798 1.82574186 1.58113883] -""") +""", +) add_sample_code( - globals()["abs"], r""" + globals()["abs"], + r""" Examples: .. code-block:: python @@ -257,10 +288,12 @@ print(out) # [0.4 0.2 0.1 0.3] -""") +""", +) add_sample_code( - globals()["ceil"], r""" + globals()["ceil"], + r""" Examples: .. code-block:: python @@ -271,10 +304,12 @@ print(out) # [-0. -0. 1. 1.] -""") +""", +) add_sample_code( - globals()["floor"], r""" + globals()["floor"], + r""" Examples: .. code-block:: python @@ -285,10 +320,12 @@ print(out) # [-1. -1. 0. 0.] -""") +""", +) add_sample_code( - globals()["cos"], r""" + globals()["cos"], + r""" Examples: .. code-block:: python @@ -299,10 +336,12 @@ print(out) # [0.92106099 0.98006658 0.99500417 0.95533649] -""") +""", +) add_sample_code( - globals()["tan"], r""" + globals()["tan"], + r""" Examples: .. code-block:: python @@ -313,10 +352,12 @@ print(out) # [-0.42279324, -0.20271005, 0.10033467, 0.30933627] -""") +""", +) add_sample_code( - globals()["acos"], r""" + globals()["acos"], + r""" Examples: .. code-block:: python @@ -327,10 +368,12 @@ print(out) # [1.98231317 1.77215425 1.47062891 1.26610367] -""") +""", +) add_sample_code( - globals()["sin"], r""" + globals()["sin"], + r""" Examples: .. code-block:: python @@ -341,10 +384,12 @@ print(out) # [-0.38941834 -0.19866933 0.09983342 0.29552021] -""") +""", +) add_sample_code( - globals()["asin"], r""" + globals()["asin"], + r""" Examples: .. code-block:: python @@ -355,10 +400,12 @@ print(out) # [-0.41151685 -0.20135792 0.10016742 0.30469265] -""") +""", +) add_sample_code( - globals()["cosh"], r""" + globals()["cosh"], + r""" Examples: .. code-block:: python @@ -369,10 +416,12 @@ print(out) # [1.08107237 1.02006676 1.00500417 1.04533851] -""") +""", +) add_sample_code( - globals()["sinh"], r""" + globals()["sinh"], + r""" Examples: .. code-block:: python @@ -383,10 +432,12 @@ print(out) # [-0.41075233 -0.201336 0.10016675 0.30452029] -""") +""", +) add_sample_code( - globals()["asinh"], r""" + globals()["asinh"], + r""" Examples: .. code-block:: python @@ -397,10 +448,12 @@ print(out) # [-0.39003533, -0.19869010, 0.09983408, 0.29567307] -""") +""", +) add_sample_code( - globals()["acosh"], r""" + globals()["acosh"], + r""" Examples: .. code-block:: python @@ -411,10 +464,12 @@ print(out) # [0. , 1.76274729, 2.06343699, 2.29243159] -""") +""", +) add_sample_code( - globals()["atanh"], r""" + globals()["atanh"], + r""" Examples: .. code-block:: python @@ -425,10 +480,12 @@ print(out) # [-0.42364895, -0.20273256, 0.10033535, 0.30951962] -""") +""", +) add_sample_code( - globals()["round"], r""" + globals()["round"], + r""" Examples: .. code-block:: python @@ -439,10 +496,12 @@ print(out) # [-1. -0. 1. 2.] -""") +""", +) add_sample_code( - globals()["reciprocal"], r""" + globals()["reciprocal"], + r""" Examples: .. code-block:: python @@ -453,10 +512,12 @@ print(out) # [-2.5 -5. 10. 3.33333333] -""") +""", +) add_sample_code( - globals()["square"], r""" + globals()["square"], + r""" Examples: .. code-block:: python @@ -467,10 +528,12 @@ print(out) # [0.16 0.04 0.01 0.09] -""") +""", +) add_sample_code( - globals()["softplus"], r""" + globals()["softplus"], + r""" Examples: .. code-block:: python @@ -482,10 +545,12 @@ print(out) # [0.513015, 0.598139, 0.744397, 0.854355] -""") +""", +) add_sample_code( - globals()["softsign"], r""" + globals()["softsign"], + r""" Examples: .. code-block:: python @@ -497,7 +562,8 @@ print(out) # [-0.285714, -0.166667, 0.0909091, 0.230769] -""") +""", +) _erf_ = generate_layer_fn('erf') From 599f8b2c2dd1ad084849361e27efd64ae23f3b0a Mon Sep 17 00:00:00 2001 From: zoooo0820 Date: Tue, 8 Nov 2022 06:30:17 +0000 Subject: [PATCH 3/3] fix error in distributed --- python/paddle/distributed/__init__.py | 48 +++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/python/paddle/distributed/__init__.py b/python/paddle/distributed/__init__.py index 658d942bec025..43f819dd770a1 100644 --- a/python/paddle/distributed/__init__.py +++ b/python/paddle/distributed/__init__.py @@ -51,7 +51,7 @@ from .collective import P2POp # noqa: F401 from .collective import reduce_scatter # noqa: F401 -from .communication import * # noqa: F401 +from .communication import stream from .auto_parallel import shard_op # noqa: F401 from .auto_parallel import shard_tensor # noqa: F401 @@ -66,15 +66,43 @@ from . import cloud_utils # noqa: F401 -from .sharding import * # noqa: F401 +from .sharding import group_sharded_parallel, save_group_sharded_model __all__ = [ # noqa - "spawn", "launch", "scatter", "broadcast", "ParallelEnv", "new_group", - "init_parallel_env", "gloo_init_parallel_env", "gloo_barrier", - "gloo_release", "QueueDataset", "split", "CountFilterEntry", - "ShowClickEntry", "get_world_size", "get_group", "all_gather", - "all_gather_object", "InMemoryDataset", "barrier", "all_reduce", "alltoall", - "alltoall_single", "send", "reduce", "recv", "ReduceOp", "wait", "get_rank", - "ProbabilityEntry", "ParallelMode", "is_initialized", - "destroy_process_group", "isend", "irecv", "reduce_scatter", "stream" + "spawn", + "launch", + "scatter", + "broadcast", + "ParallelEnv", + "new_group", + "init_parallel_env", + "gloo_init_parallel_env", + "gloo_barrier", + "gloo_release", + "QueueDataset", + "split", + "CountFilterEntry", + "ShowClickEntry", + "get_world_size", + "get_group", + "all_gather", + "all_gather_object", + "InMemoryDataset", + "barrier", + "all_reduce", + "alltoall", + "alltoall_single", + "send", + "reduce", + "recv", + "ReduceOp", + "wait", + "get_rank", + "ProbabilityEntry", + "ParallelMode", + "is_initialized", + "destroy_process_group", + "isend", + "irecv", + "reduce_scatter", ]