From 49638f256b4fdf35a3e34d347222ca3ab43ce28b Mon Sep 17 00:00:00 2001 From: Jiangxinz Date: Thu, 24 Jun 2021 14:37:12 +0800 Subject: [PATCH] fix undef var (#33691) --- python/paddle/distributed/fleet/launch_utils.py | 7 ++++--- .../fluid/tests/unittests/asp/test_asp_pruning_1d.py | 1 + .../tests/unittests/asp/test_asp_pruning_2d_greedy.py | 1 + .../fluid/tests/unittests/parallel_dygraph_transformer.py | 1 + .../fluid/tests/unittests/xpu/test_batch_norm_op_xpu.py | 2 +- tools/CrossStackProfiler/NetFileReader.py | 1 + 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/python/paddle/distributed/fleet/launch_utils.py b/python/paddle/distributed/fleet/launch_utils.py index ee5eb807fad..4b1eef72ee9 100644 --- a/python/paddle/distributed/fleet/launch_utils.py +++ b/python/paddle/distributed/fleet/launch_utils.py @@ -29,6 +29,7 @@ import struct import paddle import paddle.fluid as fluid +from distutils.util import strtobool logger = logging.getLogger("root") logger.propagate = False @@ -349,7 +350,7 @@ def add_arguments(argname, type, default, help, argparser, **kwargs): add_argument("name", str, "Jonh", "User name.", parser) args = parser.parse_args() """ - type = distutils.util.strtobool if type == bool else type + type = strtobool if type == bool else type argparser.add_argument( "--" + argname, default=default, @@ -685,7 +686,7 @@ def get_device_proc_info(args): gpus = get_gpus(args.gpus) if args.nproc_per_node is not None: assert (len(gpus) % int(args.nproc_per_node)) ==0, \ - "gpus' number:{} mod args.nproc_per_node:{} must == 0".format(len(gpus), arg.nproc_per_node) + "gpus' number:{} mod args.nproc_per_node:{} must == 0".format(len(gpus), args.nproc_per_node) n = int(len(gpus) / int(args.nproc_per_node)) devices_per_proc = [ @@ -699,7 +700,7 @@ def get_device_proc_info(args): xpus = get_xpus(args.xpus) if args.nproc_per_node is not None: assert (len(xpus) % int(args.nproc_per_node)) == 0, \ - "xpus' number:{} mod args.nproc_per_node:{} must == 0".format(len(xpus), arg.nproc_per_node) + "xpus' number:{} mod args.nproc_per_node:{} must == 0".format(len(xpus), args.nproc_per_node) n = int(len(xpus) / int(args.nproc_per_node)) devices_per_proc = [ diff --git a/python/paddle/fluid/tests/unittests/asp/test_asp_pruning_1d.py b/python/paddle/fluid/tests/unittests/asp/test_asp_pruning_1d.py index ee4b2c002f5..6ebc89b1873 100644 --- a/python/paddle/fluid/tests/unittests/asp/test_asp_pruning_1d.py +++ b/python/paddle/fluid/tests/unittests/asp/test_asp_pruning_1d.py @@ -15,6 +15,7 @@ from __future__ import print_function +import unittest import paddle from paddle.fluid.contrib import sparsity from paddle.fluid.tests.unittests.asp.asp_pruning_base import TestASPHelperPruningBase diff --git a/python/paddle/fluid/tests/unittests/asp/test_asp_pruning_2d_greedy.py b/python/paddle/fluid/tests/unittests/asp/test_asp_pruning_2d_greedy.py index 4bdd310f020..8ec8ab48525 100644 --- a/python/paddle/fluid/tests/unittests/asp/test_asp_pruning_2d_greedy.py +++ b/python/paddle/fluid/tests/unittests/asp/test_asp_pruning_2d_greedy.py @@ -15,6 +15,7 @@ from __future__ import print_function +import unittest import paddle from paddle.fluid.contrib import sparsity from paddle.fluid.tests.unittests.asp.asp_pruning_base import TestASPHelperPruningBase diff --git a/python/paddle/fluid/tests/unittests/parallel_dygraph_transformer.py b/python/paddle/fluid/tests/unittests/parallel_dygraph_transformer.py index cfc2ccd4cf7..f149637641a 100644 --- a/python/paddle/fluid/tests/unittests/parallel_dygraph_transformer.py +++ b/python/paddle/fluid/tests/unittests/parallel_dygraph_transformer.py @@ -20,6 +20,7 @@ import six import paddle import paddle.fluid as fluid from paddle.fluid.dygraph import Embedding, LayerNorm, Linear, to_variable, Layer +from paddle.optimizer.lr import NoamDecay from test_dist_base import runtime_main, TestParallelDyGraphRunnerBase """ diff --git a/python/paddle/fluid/tests/unittests/xpu/test_batch_norm_op_xpu.py b/python/paddle/fluid/tests/unittests/xpu/test_batch_norm_op_xpu.py index 1cdec863b2a..8132a78f696 100644 --- a/python/paddle/fluid/tests/unittests/xpu/test_batch_norm_op_xpu.py +++ b/python/paddle/fluid/tests/unittests/xpu/test_batch_norm_op_xpu.py @@ -141,7 +141,7 @@ class TestXPUBatchNormOp(unittest.TestCase): else: raise ValueError( "Unsupported data layout! Only NCHW and NHWC is supported, but received " - + data_layout) + + self.data_layout) np.random.seed(1024) self.x_np = np.random.random_sample(self.shape).astype(self.dtype) self.scale_np = np.random.random_sample( diff --git a/tools/CrossStackProfiler/NetFileReader.py b/tools/CrossStackProfiler/NetFileReader.py index 29c2ae85e60..fe900fab2ad 100755 --- a/tools/CrossStackProfiler/NetFileReader.py +++ b/tools/CrossStackProfiler/NetFileReader.py @@ -17,6 +17,7 @@ import json import glob import logging import pandas as pd +import multiprocessing from multiprocessing import Process -- GitLab