Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2922aa67
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
2922aa67
编写于
3月 22, 2023
作者:
A
Ainavo
提交者:
GitHub
3月 22, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CodeStyple][B011] replace assert false with raise AssertionError (#51935)
* replace assert false with AssertionError * 修改配置文件多余的部分
上级
40115c7e
变更
25
隐藏空白更改
内联
并排
Showing
25 changed file
with
84 addition
and
67 deletion
+84
-67
paddle/fluid/eager/auto_code_generator/generator/eager_gen.py
...le/fluid/eager/auto_code_generator/generator/eager_gen.py
+3
-3
paddle/fluid/eager/auto_code_generator/generator/python_c_gen.py
...fluid/eager/auto_code_generator/generator/python_c_gen.py
+3
-1
pyproject.toml
pyproject.toml
+6
-0
python/paddle/dataset/imikolov.py
python/paddle/dataset/imikolov.py
+1
-1
python/paddle/distributed/auto_parallel/cost/base_cost.py
python/paddle/distributed/auto_parallel/cost/base_cost.py
+4
-2
python/paddle/distributed/auto_parallel/dist_context.py
python/paddle/distributed/auto_parallel/dist_context.py
+17
-17
python/paddle/distributed/auto_parallel/operators/common.py
python/paddle/distributed/auto_parallel/operators/common.py
+3
-1
python/paddle/distributed/auto_parallel/process_group.py
python/paddle/distributed/auto_parallel/process_group.py
+3
-3
python/paddle/distributed/auto_parallel/utils.py
python/paddle/distributed/auto_parallel/utils.py
+3
-1
python/paddle/distributed/collective.py
python/paddle/distributed/collective.py
+1
-1
python/paddle/distributed/fleet/fleet.py
python/paddle/distributed/fleet/fleet.py
+3
-1
python/paddle/distributed/fleet/launch_utils.py
python/paddle/distributed/fleet/launch_utils.py
+4
-4
python/paddle/distributed/fleet/meta_optimizers/ascend/ascend_optimizer.py
...tributed/fleet/meta_optimizers/ascend/ascend_optimizer.py
+3
-4
python/paddle/distributed/fleet/meta_optimizers/ascend/ascend_parser.py
...distributed/fleet/meta_optimizers/ascend/ascend_parser.py
+4
-4
python/paddle/distributed/fleet/meta_optimizers/dgc_optimizer.py
...paddle/distributed/fleet/meta_optimizers/dgc_optimizer.py
+3
-1
python/paddle/fluid/tests/unittests/check_nan_inf_base.py
python/paddle/fluid/tests/unittests/check_nan_inf_base.py
+2
-2
python/paddle/fluid/tests/unittests/check_nan_inf_base_dygraph.py
...addle/fluid/tests/unittests/check_nan_inf_base_dygraph.py
+2
-2
python/paddle/fluid/tests/unittests/ir/inference/auto_scan_test.py
...ddle/fluid/tests/unittests/ir/inference/auto_scan_test.py
+2
-2
python/paddle/fluid/tests/unittests/test_matmul_op_with_head.py
.../paddle/fluid/tests/unittests/test_matmul_op_with_head.py
+1
-1
python/paddle/fluid/tests/unittests/test_nan_inf.py
python/paddle/fluid/tests/unittests/test_nan_inf.py
+1
-1
python/paddle/incubate/distributed/fleet/collective.py
python/paddle/incubate/distributed/fleet/collective.py
+3
-1
python/paddle/incubate/distributed/models/moe/moe_layer.py
python/paddle/incubate/distributed/models/moe/moe_layer.py
+4
-6
python/paddle/jit/dy2static/convert_operators.py
python/paddle/jit/dy2static/convert_operators.py
+1
-1
python/paddle/nn/layer/transformer.py
python/paddle/nn/layer/transformer.py
+6
-6
python/paddle/text/datasets/imikolov.py
python/paddle/text/datasets/imikolov.py
+1
-1
未找到文件。
paddle/fluid/eager/auto_code_generator/generator/eager_gen.py
浏览文件 @
2922aa67
...
...
@@ -829,9 +829,9 @@ class DygraphFunctionGeneratorBase(FunctionGeneratorBase):
backward_input_pos
,
]
else
:
assert
(
False
)
,
f
"Cannot find
{
backward_input_name
}
in forward position map"
raise
AssertionError
(
f
"Cannot find
{
backward_input_name
}
in forward position map"
)
for
backward_output
in
backward_returns_list
:
backward_output_name
=
backward_output
[
0
]
...
...
paddle/fluid/eager/auto_code_generator/generator/python_c_gen.py
浏览文件 @
2922aa67
...
...
@@ -58,7 +58,9 @@ atype_to_parsing_function = {
def
FindParsingFunctionFromAttributeType
(
atype
):
if
atype
not
in
atype_to_parsing_function
.
keys
():
assert
False
,
f
"Unable to find
{
atype
}
in atype_to_parsing_function."
raise
AssertionError
(
f
"Unable to find
{
atype
}
in atype_to_parsing_function."
)
return
atype_to_parsing_function
[
atype
]
...
...
pyproject.toml
浏览文件 @
2922aa67
...
...
@@ -32,6 +32,11 @@ select = [
# Pyflakes
"F401"
,
# Comprehensions
"C400"
,
"C401"
,
"C402"
,
# Pyupgrade
"UP001"
,
"UP003"
,
...
...
@@ -62,6 +67,7 @@ select = [
# Bugbear
"B009"
,
"B010"
,
"B011"
,
]
unfixable
=
[
"NPY001"
...
...
python/paddle/dataset/imikolov.py
浏览文件 @
2922aa67
...
...
@@ -108,7 +108,7 @@ def reader_creator(filename, word_idx, n, data_type):
continue
yield
src_seq
,
trg_seq
else
:
assert
False
,
'Unknown data type'
raise
AssertionError
(
'Unknown data type'
)
return
reader
...
...
python/paddle/distributed/auto_parallel/cost/base_cost.py
浏览文件 @
2922aa67
...
...
@@ -436,8 +436,10 @@ def build_dp_costs(
elif
var_name
in
dist_attr
.
outputs_dist_attrs
:
dims_mapping
=
dist_attr
.
get_output_dims_mapping
(
var_name
)
else
:
assert
False
,
"cannot find dims_mapping for {} in {}"
.
format
(
var_name
,
dist_attr
raise
AssertionError
(
"cannot find dims_mapping for {} in {}"
.
format
(
var_name
,
dist_attr
)
)
# dims_mapping = (
...
...
python/paddle/distributed/auto_parallel/dist_context.py
浏览文件 @
2922aa67
...
...
@@ -974,9 +974,9 @@ class DistributedContext:
def
validate_dist_attr_for_program
(
self
):
if
not
self
.
_is_initialized
:
assert
(
False
)
,
"Program must be initialized before validating its distributed attributes"
raise
AssertionError
(
"Program must be initialized before validating its distributed attributes"
)
for
block
in
self
.
serial_main_program
.
blocks
:
for
tensor
in
block
.
vars
.
values
():
dist_tensor
=
self
.
get_dist_tensor_for_program
(
tensor
)
...
...
@@ -988,13 +988,13 @@ class DistributedContext:
if
(
dist_tensor
is
not
None
)
and
(
not
dist_tensor
.
validate_dist_attr
()
):
assert
(
False
),
"Tensor {} (id: {}, original_id: {}) has a wrong distributed attributes {}."
.
format
(
dist_tensor
.
serial_tensor
.
name
,
dist_tensor
.
serial_tensor
.
desc
.
id
(),
dist_tensor
.
serial_tensor
.
desc
.
original_id
()
,
dist_tensor
.
dist_attr
,
raise
AssertionError
(
"Tensor {} (id: {}, original_id: {}) has a wrong distributed attributes {}."
.
format
(
dist_tensor
.
serial_tensor
.
name
,
dist_tensor
.
serial_tensor
.
desc
.
id
()
,
dist_tensor
.
serial_tensor
.
desc
.
original_
id
(),
dist_tensor
.
dist_attr
,
)
)
for
op
in
block
.
ops
:
dist_op
=
self
.
get_dist_op_for_program
(
op
)
...
...
@@ -1004,13 +1004,13 @@ class DistributedContext:
dist_op
.
serial_op
.
type
)
if
(
dist_op
is
not
None
)
and
(
not
dist_op
.
validate_dist_attr
()):
assert
(
False
),
"Operator {} (id: {}, original_id: {}) has a wrong distributed attributes {} ."
.
format
(
dist_op
.
serial_op
.
type
,
dist_op
.
serial_op
.
desc
.
id
(),
dist_op
.
serial_op
.
desc
.
original_id
()
,
dist_op
.
dist_attr
,
raise
AssertionError
(
"Operator {} (id: {}, original_id: {}) has a wrong distributed attributes {} ."
.
format
(
dist_op
.
serial_op
.
type
,
dist_op
.
serial_op
.
desc
.
id
()
,
dist_op
.
serial_op
.
desc
.
original_
id
(),
dist_op
.
dist_attr
,
)
)
return
True
...
...
python/paddle/distributed/auto_parallel/operators/common.py
浏览文件 @
2922aa67
...
...
@@ -186,7 +186,9 @@ def register_distributed_operator_impl(op_type, dist_impl):
dist_impl
.
type
=
op_type
dist_op_impl_container
.
register_impl
(
dist_impl
)
else
:
assert
False
,
"Must register distributed operator registry first."
raise
AssertionError
(
"Must register distributed operator registry first."
)
def
find_compatible_distributed_operator_impls
(
dist_op
,
fwd
=
True
,
partial
=
True
):
...
...
python/paddle/distributed/auto_parallel/process_group.py
浏览文件 @
2922aa67
...
...
@@ -115,8 +115,8 @@ class ProcessGroup:
if
global_rank
in
self
.
ranks
:
return
self
.
ranks
.
index
(
global_rank
)
else
:
assert
False
,
"Rank {} doesn't belong to this group"
.
format
(
global_rank
raise
AssertionError
(
"Rank {} doesn't belong to this group"
.
format
(
global_rank
)
)
def
is_instantiate
(
self
):
...
...
@@ -149,7 +149,7 @@ class ProcessGroup:
ring_id
)
else
:
assert
False
,
"No CUDA device found"
raise
AssertionError
(
'No CUDA device found'
)
# TODO(shenliang03): This is a temporary solution to solve the problem of
# hang caused by cross-creation of new_group
...
...
python/paddle/distributed/auto_parallel/utils.py
浏览文件 @
2922aa67
...
...
@@ -1790,7 +1790,9 @@ def set_dist_op_desc_original_id(dist_op_desc, op_desc, dist_context):
return
# Third, print error infomation if we cannot find the original id
else
:
assert
False
,
"Cannot find the original id in the distributed context"
raise
AssertionError
(
"Cannot find the original id in the distributed context"
)
def
to_list
(
value
):
...
...
python/paddle/distributed/collective.py
浏览文件 @
2922aa67
...
...
@@ -304,7 +304,7 @@ def new_group(ranks=None, backend=None, timeout=_default_timeout):
ring_id
)
else
:
assert
False
,
"no cuda device found"
raise
AssertionError
(
"no cuda device found"
)
else
:
return
gp
...
...
python/paddle/distributed/fleet/fleet.py
浏览文件 @
2922aa67
...
...
@@ -416,7 +416,9 @@ class Fleet:
if
not
order
:
order
=
[
'dp'
,
'pp'
,
'sharding'
,
'mp'
]
if
order
[:].
sort
()
!=
list
(
d_hybrid_degree
.
keys
())[:].
sort
():
assert
False
,
"The order of hybrid_config setting is incorrect."
raise
AssertionError
(
'The order of hybrid_config setting is incorrect.'
)
hybrid_group_names
=
[]
dims
=
[]
...
...
python/paddle/distributed/fleet/launch_utils.py
浏览文件 @
2922aa67
...
...
@@ -953,10 +953,10 @@ def get_device_proc_info(args):
else
:
devices_per_proc
=
[
x
for
x
in
range
(
0
,
args
.
nproc_per_node
)]
else
:
assert
(
False
),
"Can't support device_mode:{}, support only cpu|gpu|xpu now."
.
format
(
device_mode
raise
AssertionError
(
"Can't support device_mode:{}, support only cpu|gpu|xpu now."
.
format
(
device_mode
)
)
return
(
device_mode
,
devices_per_proc
)
...
...
python/paddle/distributed/fleet/meta_optimizers/ascend/ascend_optimizer.py
浏览文件 @
2922aa67
...
...
@@ -116,10 +116,9 @@ class AscendIRParser:
)
op_parser
.
apply
(
op
)
else
:
assert
(
False
),
"Op[%s] has not been registered, so we have to skip it"
%
(
op
.
type
raise
AssertionError
(
'Op[%s] has not been registered, so we have to skip it'
%
op
.
type
)
def
_parse_program
(
...
...
python/paddle/distributed/fleet/meta_optimizers/ascend/ascend_parser.py
浏览文件 @
2922aa67
...
...
@@ -515,7 +515,7 @@ class SumParser(AscendParserBase):
def
_apply
(
self
):
len_list
=
len
(
self
.
op
.
input_arg_names
)
if
len_list
<
2
:
assert
False
,
"the size of input list must large or equal 2"
raise
AssertionError
(
"the size of input list must large or equal 2"
)
x
=
self
.
_get_ge_input
(
self
.
op
.
input_arg_names
[
0
])
y
=
self
.
_get_ge_input
(
self
.
op
.
input_arg_names
[
1
])
sum
=
(
...
...
@@ -643,7 +643,7 @@ class MatMulParser(AscendParserBase):
.
set_attr_bool
(
"transpose_x2"
,
transpose_y
)
)
else
:
assert
False
,
"not support"
raise
AssertionError
(
"not support"
)
return
[
matmul
],
[[
0
]]
...
...
@@ -681,7 +681,7 @@ class MulParser(AscendParserBase):
.
set_input
(
"x2"
,
y
,
0
)
)
else
:
assert
False
,
"not support"
raise
AssertionError
(
"not support"
)
else
:
if
len
(
shape_x1
)
==
3
and
len
(
shape_x2
)
==
2
:
assert
x_num_col_dims
==
2
,
"only support 2"
...
...
@@ -729,7 +729,7 @@ class MulParser(AscendParserBase):
.
set_attr_vec_int32
(
"perm"
,
[
1
,
2
,
0
])
)
else
:
assert
False
,
"not support"
raise
AssertionError
(
"not support"
)
return
[
matmul
],
[[
0
]]
...
...
python/paddle/distributed/fleet/meta_optimizers/dgc_optimizer.py
浏览文件 @
2922aa67
...
...
@@ -107,7 +107,9 @@ class DGCMomentumOptimizer(Optimizer):
elif
isinstance
(
regularization
,
L2Decay
):
regular_type
=
2
else
:
assert
False
,
'regularization must be None|L1Decay|L2Deacy'
raise
AssertionError
(
"regularization must be None|L1Decay|L2Deacy"
)
return
regular_type
,
regular_coeff
def
_is_use_dgc
(
self
,
param_var
,
grad_var
):
...
...
python/paddle/fluid/tests/unittests/check_nan_inf_base.py
浏览文件 @
2922aa67
...
...
@@ -105,7 +105,7 @@ def check(use_cuda):
if
__name__
==
'__main__'
:
try
:
check
(
use_cuda
=
False
)
assert
False
raise
AssertionError
()
except
Exception
as
e
:
print
(
e
)
print
(
type
(
e
))
...
...
@@ -114,7 +114,7 @@ if __name__ == '__main__':
if
core
.
is_compiled_with_cuda
():
try
:
check
(
use_cuda
=
True
)
assert
False
raise
AssertionError
()
except
Exception
as
e
:
print
(
e
)
print
(
type
(
e
))
...
...
python/paddle/fluid/tests/unittests/check_nan_inf_base_dygraph.py
浏览文件 @
2922aa67
...
...
@@ -96,7 +96,7 @@ def run_check():
if
paddle
.
is_compiled_with_cuda
():
try
:
check
(
use_cuda
=
True
)
assert
False
raise
AssertionError
()
except
Exception
as
e
:
print
(
e
)
print
(
type
(
e
))
...
...
@@ -105,7 +105,7 @@ def run_check():
assert
type
(
e
)
==
OSError
or
type
(
e
)
==
RuntimeError
try
:
check
(
use_cuda
=
False
)
assert
False
raise
AssertionError
()
except
Exception
as
e
:
print
(
e
)
print
(
type
(
e
))
...
...
python/paddle/fluid/tests/unittests/ir/inference/auto_scan_test.py
浏览文件 @
2922aa67
...
...
@@ -462,7 +462,7 @@ class PassAutoScanTest(AutoScanTest):
min_success_num
,
successful_ran_programs
)
)
assert
False
raise
AssertionError
()
used_time
=
time
.
time
()
-
start_time
if
max_duration
>
0
and
used_time
>
max_duration
:
logging
.
error
(
...
...
@@ -470,7 +470,7 @@ class PassAutoScanTest(AutoScanTest):
max_duration
)
)
assert
False
raise
AssertionError
()
def
run_test
(
self
,
quant
=
False
,
prog_configs
=
None
):
status
=
True
...
...
python/paddle/fluid/tests/unittests/test_matmul_op_with_head.py
浏览文件 @
2922aa67
...
...
@@ -180,7 +180,7 @@ def matmul_head2(X, Y, head_number=1):
z
.
append
(
np
.
matmul
(
x
[
i
],
y
[
i
]))
Z
=
np
.
concatenate
((
z
),
axis
=
2
)
else
:
assert
False
,
"ERROR: Not supported dimension!"
raise
AssertionError
(
"ERROR: Not supported dimension!"
)
return
Z
...
...
python/paddle/fluid/tests/unittests/test_nan_inf.py
浏览文件 @
2922aa67
...
...
@@ -99,7 +99,7 @@ class TestNanInfCheckResult(unittest.TestCase):
out
=
paddle
.
log
(
x
)
sys
.
stdout
.
flush
()
if
add_assert
:
assert
False
raise
AssertionError
()
except
Exception
as
e
:
# Cannot catch the log in CUDA kernel.
err_str_list
=
(
...
...
python/paddle/incubate/distributed/fleet/collective.py
浏览文件 @
2922aa67
...
...
@@ -301,7 +301,9 @@ class CollectiveOptimizer(DistributedOptimizer):
def
_check_condition
(
self
,
name
,
**
kwargs
):
for
k
,
v
in
kwargs
.
items
():
if
v
is
True
:
assert
False
,
"you can't use %s and %s together"
%
(
name
,
k
)
raise
AssertionError
(
"you can't use %s and %s together"
%
(
name
,
k
)
)
def
_check_collective_mode
(
self
,
main_program
,
optimizer
,
strategy
):
"""
...
...
python/paddle/incubate/distributed/models/moe/moe_layer.py
浏览文件 @
2922aa67
...
...
@@ -384,12 +384,10 @@ class MoELayer(nn.Layer):
group
=
self
.
group
,
)
else
:
assert
(
False
),
"We only support naive gate,
\
gshard gate and switch gate,
\
but you choose {} gate."
.
format
(
str
(
gate
)
raise
AssertionError
(
"We only support naive gate, gshard gate and switch gate, but you choose {} gate."
.
format
(
str
(
gate
)
)
)
elif
isinstance
(
gate
,
NaiveGate
):
self
.
top_k
=
gate
.
top_k
...
...
python/paddle/jit/dy2static/convert_operators.py
浏览文件 @
2922aa67
...
...
@@ -87,7 +87,7 @@ def _unpack_by_structure_paddle(target, structure):
if
isinstance
(
ele
,
list
):
ret
.
append
(
unpack_by_structure
(
target
[
idx
],
ele
))
continue
assert
False
,
"structure element must be 1 or list"
raise
AssertionError
(
"structure element must be 1 or list"
)
return
ret
...
...
python/paddle/nn/layer/transformer.py
浏览文件 @
2922aa67
...
...
@@ -1317,9 +1317,9 @@ class Transformer(Layer):
encoder_bias_attr
=
[
bias_attr
[
0
],
bias_attr
[
-
1
]]
decoder_bias_attr
=
bias_attr
else
:
assert
(
False
)
,
"length of bias_attr should be 1 or 2 or 3 when it is a list/tuple"
raise
AssertionError
(
"length of bias_attr should be 1 or 2 or 3 when it is a list/tuple"
)
else
:
encoder_bias_attr
=
bias_attr
decoder_bias_attr
=
bias_attr
...
...
@@ -1339,9 +1339,9 @@ class Transformer(Layer):
encoder_weight_attr
=
[
weight_attr
[
0
],
weight_attr
[
-
1
]]
decoder_weight_attr
=
weight_attr
else
:
assert
(
False
)
,
"length of weight_attr should be 1 or 2 or 3 when it is a list/tuple"
raise
AssertionError
(
"length of weight_attr should be 1 or 2 or 3 when it is a list/tuple"
)
else
:
encoder_weight_attr
=
weight_attr
decoder_weight_attr
=
weight_attr
...
...
python/paddle/text/datasets/imikolov.py
浏览文件 @
2922aa67
...
...
@@ -168,7 +168,7 @@ class Imikolov(Dataset):
continue
self
.
data
.
append
((
src_seq
,
trg_seq
))
else
:
assert
False
,
'Unknow data type'
raise
AssertionError
(
'Unknow data type'
)
def
__getitem__
(
self
,
idx
):
return
tuple
([
np
.
array
(
d
)
for
d
in
self
.
data
[
idx
]])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录