未验证 提交 05a47f39 编写于 作者: N Nyakku Shigure 提交者: GitHub

[CodeStyle][F821] fix undefined variables due to missing imports, misspelled...

[CodeStyle][F821] fix undefined variables due to missing imports, misspelled variable names (#47899)

* `hann` -> `_hann`

* `false` -> `False`

* a missing passed argument `reduce_all`

* some missing imports

* `device_type` -> `heter_device_type`

* `PKVClient` -> `KVClient`

* fix some typos and missing imports
上级 8347354d
...@@ -210,7 +210,7 @@ def _tukey( ...@@ -210,7 +210,7 @@ def _tukey(
if alpha <= 0: if alpha <= 0:
return paddle.ones((M,), dtype=dtype) return paddle.ones((M,), dtype=dtype)
elif alpha >= 1.0: elif alpha >= 1.0:
return hann(M, sym=sym) return _hann(M, sym=sym)
M, needs_trunc = _extend(M, sym) M, needs_trunc = _extend(M, sym)
......
...@@ -833,7 +833,7 @@ class CommOpCost(OpCost): ...@@ -833,7 +833,7 @@ class CommOpCost(OpCost):
if self.op_desc is not None: if self.op_desc is not None:
self._group_ranks = self.op_desc["group_ranks"] self._group_ranks = self.op_desc["group_ranks"]
elif self.op is not None: elif self.op is not None:
ring_id = op.attrs("ring_id") ring_id = self.op.attrs("ring_id")
process_group = get_process_group(ring_id) process_group = get_process_group(ring_id)
if process_group is None: if process_group is None:
raise ValueError( raise ValueError(
......
...@@ -23,6 +23,7 @@ from .dist_default import DistributedDefaultImpl0 ...@@ -23,6 +23,7 @@ from .dist_default import DistributedDefaultImpl0
from ..cost import build_comp_desc_from_dist_op, build_comp_costs_from_descs from ..cost import build_comp_desc_from_dist_op, build_comp_costs_from_descs
from ..cost import Reshape2OpCost from ..cost import Reshape2OpCost
from ..cost import Reshape2GradOpCost from ..cost import Reshape2GradOpCost
from ..cost import build_dp_costs
from paddle.distributed.fleet.meta_optimizers.common import OpRole from paddle.distributed.fleet.meta_optimizers.common import OpRole
......
...@@ -437,7 +437,7 @@ class SearchAlgorithm: ...@@ -437,7 +437,7 @@ class SearchAlgorithm:
@property @property
def name(self): def name(self):
self.name = name self.name = self._name
def search(self): def search(self):
raise NotImplementedError("Please Implement this method in subclass.") raise NotImplementedError("Please Implement this method in subclass.")
......
...@@ -129,7 +129,9 @@ class OrthogonalStrategy: ...@@ -129,7 +129,9 @@ class OrthogonalStrategy:
def _check_valid_strategy(self): def _check_valid_strategy(self):
assert len(self._list_of_strategy_name) == len( assert len(self._list_of_strategy_name) == len(
set(self._list_of_strategy_name) set(self._list_of_strategy_name)
), "Defined duplicated strategies: {}".format(list_of_strategy) ), "Defined duplicated strategies: {}".format(
self._list_of_strategy_name
)
num_of_ranks = functools.reduce( num_of_ranks = functools.reduce(
lambda x, y: x * y, self._list_of_degree lambda x, y: x * y, self._list_of_degree
) )
......
...@@ -342,9 +342,7 @@ class MultiSlotDataGenerator(DataGenerator): ...@@ -342,9 +342,7 @@ class MultiSlotDataGenerator(DataGenerator):
for elem in elements: for elem in elements:
if isinstance(elem, float): if isinstance(elem, float):
self._proto_info[-1] = (name, "float") self._proto_info[-1] = (name, "float")
elif not isinstance(elem, int) and not isinstance( elif not isinstance(elem, int):
elem, long
):
raise ValueError( raise ValueError(
"the type of element%s must be in int or float" "the type of element%s must be in int or float"
% type(elem) % type(elem)
...@@ -379,9 +377,7 @@ class MultiSlotDataGenerator(DataGenerator): ...@@ -379,9 +377,7 @@ class MultiSlotDataGenerator(DataGenerator):
if self._proto_info[index][1] != "float": if self._proto_info[index][1] != "float":
if isinstance(elem, float): if isinstance(elem, float):
self._proto_info[index] = (name, "float") self._proto_info[index] = (name, "float")
elif not isinstance(elem, int) and not isinstance( elif not isinstance(elem, int):
elem, long
):
raise ValueError( raise ValueError(
"the type of element%s must be in int or float" "the type of element%s must be in int or float"
% type(elem) % type(elem)
......
...@@ -18,6 +18,7 @@ from paddle.fluid import core ...@@ -18,6 +18,7 @@ from paddle.fluid import core
from paddle.fluid.framework import _non_static_mode from paddle.fluid.framework import _non_static_mode
from paddle.fluid.framework import _in_legacy_dygraph from paddle.fluid.framework import _in_legacy_dygraph
from paddle.fluid.framework import in_dygraph_mode from paddle.fluid.framework import in_dygraph_mode
from paddle.fluid.framework import _varbase_creator
from paddle.fluid.layer_helper import LayerHelper from paddle.fluid.layer_helper import LayerHelper
from paddle.fluid.data_feeder import check_variable_and_dtype from paddle.fluid.data_feeder import check_variable_and_dtype
from paddle.fluid.dygraph import layers from paddle.fluid.dygraph import layers
......
...@@ -902,7 +902,9 @@ class TheOnePSRuntime(RuntimeBase): ...@@ -902,7 +902,9 @@ class TheOnePSRuntime(RuntimeBase):
heter_device_type = self.role_maker._heter_device_type().upper() heter_device_type = self.role_maker._heter_device_type().upper()
if heter_device_type not in ["GPU", "XPU", "CPU"]: if heter_device_type not in ["GPU", "XPU", "CPU"]:
raise ValueError( raise ValueError(
"Heter Worker Not Support Device {}".format(device_type) "Heter Worker Not Support Device {}".format(
heter_device_type
)
) )
if heter_device_type == "GPU": if heter_device_type == "GPU":
executor = Executor( executor = Executor(
......
...@@ -19,6 +19,7 @@ import re ...@@ -19,6 +19,7 @@ import re
import time import time
import abc import abc
from paddle.fluid import core from paddle.fluid import core
from .log_util import logger
import functools import functools
import shutil import shutil
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import annotations
from .container import Container from .container import Container
from .status import Status from .status import Status
...@@ -27,8 +29,8 @@ class PodSepc: ...@@ -27,8 +29,8 @@ class PodSepc:
) )
# by controller # by controller
self._init_containers: List[Container] = [] self._init_containers: list[Container] = []
self._containers: List[Container] = [] self._containers: list[Container] = []
# self.resource: Resource = None # self.resource: Resource = None
# self.status: Status = None # self.status: Status = None
......
...@@ -79,7 +79,7 @@ class KVClient: ...@@ -79,7 +79,7 @@ class KVClient:
if __name__ == '__main__': if __name__ == '__main__':
cli = PKVClient("http://localhost:8090") cli = KVClient("http://localhost:8090")
data = {"/workers/1": "rank1", "/workers/2": "rank2"} data = {"/workers/1": "rank1", "/workers/2": "rank2"}
for k, v in data.items(): for k, v in data.items():
cli.put(k, v) cli.put(k, v)
......
...@@ -494,7 +494,9 @@ class DataParallelOptimizationPass(PassBase): ...@@ -494,7 +494,9 @@ class DataParallelOptimizationPass(PassBase):
for idx in sorted(remove_op_indices, reverse=True): for idx in sorted(remove_op_indices, reverse=True):
assert ( assert (
block.ops[idx].type in remove_op_types block.ops[idx].type in remove_op_types
), "Unexception: try to remove op {}".format(str(op)) ), "Unexception: try to remove op {}".format(
str(block.ops[idx])
)
block._remove_op(idx) block._remove_op(idx)
# insert coalecse op # insert coalecse op
......
...@@ -482,7 +482,7 @@ def get_geo_trainer_send_context(attrs): ...@@ -482,7 +482,7 @@ def get_geo_trainer_send_context(attrs):
if attrs['ps_mode'] != DistributedMode.GEO: if attrs['ps_mode'] != DistributedMode.GEO:
raise ValueError( raise ValueError(
"ps mode: {} not matched {}", "ps mode: {} not matched {}",
format(ps_mode, "get_geo_trainer_send_context"), format(attrs['ps_mode'], "get_geo_trainer_send_context"),
) )
send_ctx = {} send_ctx = {}
trainer_id = get_role_id(attrs['role_maker']) trainer_id = get_role_id(attrs['role_maker'])
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
from paddle.distribution import constraint from paddle.distribution import constraint
import paddle
class Variable: class Variable:
"""Random variable of probability distribution. """Random variable of probability distribution.
......
...@@ -27,7 +27,7 @@ class TrtConvertElementwiseTest_one_input_corner_case(TrtLayerAutoScanTest): ...@@ -27,7 +27,7 @@ class TrtConvertElementwiseTest_one_input_corner_case(TrtLayerAutoScanTest):
program_config.ops[i].attrs for i in range(len(program_config.ops)) program_config.ops[i].attrs for i in range(len(program_config.ops))
] ]
if attrs[0]['axis'] == 0: if attrs[0]['axis'] == 0:
return false return False
ver = paddle_infer.get_trt_compile_version() ver = paddle_infer.get_trt_compile_version()
if ver[0] * 1000 + ver[1] * 100 + ver[2] * 10 < 8415: if ver[0] * 1000 + ver[1] * 100 + ver[2] * 10 < 8415:
return False return False
......
...@@ -22,6 +22,7 @@ from paddle.fluid.layer_helper import LayerHelper ...@@ -22,6 +22,7 @@ from paddle.fluid.layer_helper import LayerHelper
from paddle.fluid.framework import _non_static_mode from paddle.fluid.framework import _non_static_mode
from paddle import _legacy_C_ops from paddle import _legacy_C_ops
from paddle.static import default_main_program from paddle.static import default_main_program
from paddle.fluid.data_feeder import check_variable_and_dtype
def dropout_nd( def dropout_nd(
......
...@@ -140,7 +140,7 @@ def ref_reduce_mean(x, axis=None, keepdim=False, reduce_all=False): ...@@ -140,7 +140,7 @@ def ref_reduce_mean(x, axis=None, keepdim=False, reduce_all=False):
return np.mean(x, axis=axis, keepdims=keepdim) return np.mean(x, axis=axis, keepdims=keepdim)
def ref_reduce_mean_grad(x, axis, dtype): def ref_reduce_mean_grad(x, axis, dtype, reduce_all):
if reduce_all: if reduce_all:
axis = list(range(x.ndim)) axis = list(range(x.ndim))
...@@ -191,7 +191,6 @@ class TestReduceMeanOp(OpTest): ...@@ -191,7 +191,6 @@ class TestReduceMeanOp(OpTest):
if self.dtype != 'float16': if self.dtype != 'float16':
self.check_grad(['X'], ['Out'], check_eager=True) self.check_grad(['X'], ['Out'], check_eager=True)
else: else:
return
if not core.is_compiled_with_cuda(): if not core.is_compiled_with_cuda():
return return
place = paddle.CUDAPlace(0) place = paddle.CUDAPlace(0)
...@@ -204,7 +203,10 @@ class TestReduceMeanOp(OpTest): ...@@ -204,7 +203,10 @@ class TestReduceMeanOp(OpTest):
) )
dx = paddle.grad(y, x)[0].numpy() dx = paddle.grad(y, x)[0].numpy()
dx_expected = ref_reduce_mean_grad( dx_expected = ref_reduce_mean_grad(
self.inputs['X'], self.attrs['dim'], self.dtype self.inputs['X'],
self.attrs['dim'],
self.dtype,
self.attrs['reduce_all'],
) )
np.testing.assert_array_equal(dx, dx_expected) np.testing.assert_array_equal(dx, dx_expected)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册