Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c1838da6
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c1838da6
编写于
3月 28, 2023
作者:
K
Kim
提交者:
GitHub
3月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CodeStyle][PLR1701] unify multiple isinstance expressions as one (#52150)
上级
c05feb90
变更
33
隐藏空白更改
内联
并排
Showing
33 changed file
with
123 addition
and
171 deletion
+123
-171
python/paddle/audio/functional/functional.py
python/paddle/audio/functional/functional.py
+1
-1
python/paddle/distributed/auto_parallel/dist_op.py
python/paddle/distributed/auto_parallel/dist_op.py
+1
-1
python/paddle/distributed/auto_parallel/reshard.py
python/paddle/distributed/auto_parallel/reshard.py
+1
-3
python/paddle/distributed/fleet/base/util_factory.py
python/paddle/distributed/fleet/base/util_factory.py
+1
-1
python/paddle/distributed/fleet/meta_optimizers/localsgd_optimizer.py
...e/distributed/fleet/meta_optimizers/localsgd_optimizer.py
+16
-10
python/paddle/fluid/tests/unittests/ir/inference/auto_scan_test.py
...ddle/fluid/tests/unittests/ir/inference/auto_scan_test.py
+1
-3
python/paddle/fluid/tests/unittests/mkldnn/test_bilinear_interp_v2_mkldnn_op.py
...sts/unittests/mkldnn/test_bilinear_interp_v2_mkldnn_op.py
+1
-1
python/paddle/fluid/tests/unittests/mkldnn/test_nearest_interp_v2_mkldnn_op.py
...ests/unittests/mkldnn/test_nearest_interp_v2_mkldnn_op.py
+1
-1
python/paddle/fluid/tests/unittests/test_bicubic_interp_v2_op.py
...paddle/fluid/tests/unittests/test_bicubic_interp_v2_op.py
+5
-7
python/paddle/fluid/tests/unittests/test_bilinear_interp_v2_op.py
...addle/fluid/tests/unittests/test_bilinear_interp_v2_op.py
+8
-8
python/paddle/fluid/tests/unittests/test_desc_clone.py
python/paddle/fluid/tests/unittests/test_desc_clone.py
+3
-8
python/paddle/fluid/tests/unittests/test_linear_interp_v2_op.py
.../paddle/fluid/tests/unittests/test_linear_interp_v2_op.py
+8
-8
python/paddle/fluid/tests/unittests/test_nearest_interp_v2_op.py
...paddle/fluid/tests/unittests/test_nearest_interp_v2_op.py
+8
-8
python/paddle/fluid/tests/unittests/test_trilinear_interp_v2_op.py
...ddle/fluid/tests/unittests/test_trilinear_interp_v2_op.py
+8
-8
python/paddle/fluid/tests/unittests/testsuite.py
python/paddle/fluid/tests/unittests/testsuite.py
+1
-1
python/paddle/fluid/tests/unittests/xpu/test_bilinear_interp_v2_op_xpu.py
...uid/tests/unittests/xpu/test_bilinear_interp_v2_op_xpu.py
+4
-4
python/paddle/fluid/tests/unittests/xpu/test_nearest_interp_v2_op_xpu.py
...luid/tests/unittests/xpu/test_nearest_interp_v2_op_xpu.py
+3
-3
python/paddle/hapi/progressbar.py
python/paddle/hapi/progressbar.py
+1
-5
python/paddle/incubate/distributed/fleet/utils.py
python/paddle/incubate/distributed/fleet/utils.py
+1
-1
python/paddle/jit/api.py
python/paddle/jit/api.py
+1
-3
python/paddle/jit/dy2static/static_analysis.py
python/paddle/jit/dy2static/static_analysis.py
+1
-3
python/paddle/nn/functional/common.py
python/paddle/nn/functional/common.py
+6
-16
python/paddle/nn/initializer/constant.py
python/paddle/nn/initializer/constant.py
+1
-3
python/paddle/nn/layer/layers.py
python/paddle/nn/layer/layers.py
+1
-1
python/paddle/nn/layer/rnn.py
python/paddle/nn/layer/rnn.py
+1
-1
python/paddle/nn/quant/quant_layers.py
python/paddle/nn/quant/quant_layers.py
+2
-6
python/paddle/optimizer/lr.py
python/paddle/optimizer/lr.py
+1
-5
python/paddle/static/nn/common.py
python/paddle/static/nn/common.py
+30
-30
python/paddle/static/quantization/quantization_pass.py
python/paddle/static/quantization/quantization_pass.py
+1
-6
python/paddle/static/quantization/tests/test_imperative_ptq.py
...n/paddle/static/quantization/tests/test_imperative_ptq.py
+2
-8
python/paddle/tensor/layer_function_generator.py
python/paddle/tensor/layer_function_generator.py
+1
-5
python/paddle/tensor/math.py
python/paddle/tensor/math.py
+1
-1
python/paddle/vision/ops.py
python/paddle/vision/ops.py
+1
-1
未找到文件。
python/paddle/audio/functional/functional.py
浏览文件 @
c1838da6
...
...
@@ -250,7 +250,7 @@ def compute_fbank_matrix(
if
norm
==
'slaney'
:
enorm
=
2.0
/
(
mel_f
[
2
:
n_mels
+
2
]
-
mel_f
[:
n_mels
])
weights
*=
enorm
.
unsqueeze
(
1
)
elif
isinstance
(
norm
,
int
)
or
isinstance
(
norm
,
float
):
elif
isinstance
(
norm
,
(
int
,
float
)
):
weights
=
paddle
.
nn
.
functional
.
normalize
(
weights
,
p
=
norm
,
axis
=-
1
)
return
weights
...
...
python/paddle/distributed/auto_parallel/dist_op.py
浏览文件 @
c1838da6
...
...
@@ -323,7 +323,7 @@ class DistributedOperatorHelper:
output
=
self
.
_serial_op
(
*
args
,
**
kwargs
)
new_op_size
=
len
(
cur_block
.
ops
)
if
isinstance
(
output
,
tuple
)
or
isinstance
(
output
,
list
):
if
isinstance
(
output
,
(
tuple
,
list
)
):
new_output
=
list
(
output
)
elif
isinstance
(
output
,
Variable
):
new_output
=
[
output
]
...
...
python/paddle/distributed/auto_parallel/reshard.py
浏览文件 @
c1838da6
...
...
@@ -1948,9 +1948,7 @@ class Resharder:
)
idx
=
idx_list
[
0
]
elif
isinstance
(
op_desc
,
SliceOpDesc
)
or
isinstance
(
op_desc
,
AllGatherConcatOpDesc
):
elif
isinstance
(
op_desc
,
(
SliceOpDesc
,
AllGatherConcatOpDesc
)):
target_tensor
=
None
if
isinstance
(
op_desc
,
SliceOpDesc
):
assert
(
...
...
python/paddle/distributed/fleet/base/util_factory.py
浏览文件 @
c1838da6
...
...
@@ -425,7 +425,7 @@ class UtilBase:
def
feed_gen
(
batch_size
,
feeded_vars_dims
,
feeded_vars_filelist
):
def
reader
(
batch_size
,
fn
,
dim
):
data
=
[]
if
isinstance
(
dim
,
list
)
or
isinstance
(
dim
,
tuple
):
if
isinstance
(
dim
,
(
list
,
tuple
)
):
shape
=
list
(
dim
)
_temp
=
1
for
x
in
dim
:
...
...
python/paddle/distributed/fleet/meta_optimizers/localsgd_optimizer.py
浏览文件 @
c1838da6
...
...
@@ -45,11 +45,14 @@ class LocalSGDOptimizer(MetaOptimizerBase):
if
self
.
role_maker
.
_worker_num
()
<=
1
:
return
False
return
(
isinstance
(
self
.
inner_opt
,
paddle
.
optimizer
.
momentum
.
Momentum
)
or
isinstance
(
self
.
inner_opt
,
paddle
.
fluid
.
optimizer
.
Momentum
)
or
isinstance
(
self
.
inner_opt
,
paddle
.
optimizer
.
sgd
.
SGD
)
or
isinstance
(
self
.
inner_opt
,
paddle
.
fluid
.
optimizer
.
SGD
)
return
isinstance
(
self
.
inner_opt
,
(
paddle
.
optimizer
.
momentum
.
Momentum
,
paddle
.
fluid
.
optimizer
.
Momentum
,
paddle
.
optimizer
.
sgd
.
SGD
,
paddle
.
fluid
.
optimizer
.
SGD
,
),
)
def
_disable_strategy
(
self
,
dist_strategy
):
...
...
@@ -228,11 +231,14 @@ class AdaptiveLocalSGDOptimizer(MetaOptimizerBase):
if
self
.
role_maker
.
_worker_num
()
<=
1
:
return
False
return
(
isinstance
(
self
.
inner_opt
,
paddle
.
optimizer
.
Momentum
)
or
isinstance
(
self
.
inner_opt
,
paddle
.
fluid
.
optimizer
.
Momentum
)
or
isinstance
(
self
.
inner_opt
,
paddle
.
optimizer
.
sgd
.
SGD
)
or
isinstance
(
self
.
inner_opt
,
paddle
.
fluid
.
optimizer
.
SGD
)
return
isinstance
(
self
.
inner_opt
,
(
paddle
.
optimizer
.
Momentum
,
paddle
.
fluid
.
optimizer
.
Momentum
,
paddle
.
optimizer
.
sgd
.
SGD
,
paddle
.
fluid
.
optimizer
.
SGD
,
),
)
def
_disable_strategy
(
self
,
dist_strategy
):
...
...
python/paddle/fluid/tests/unittests/ir/inference/auto_scan_test.py
浏览文件 @
c1838da6
...
...
@@ -795,9 +795,7 @@ class TrtLayerAutoScanTest(AutoScanTest):
if
isinstance
(
threshold
,
float
):
atol
=
threshold
rtol
=
1e-8
elif
isinstance
(
threshold
,
list
)
or
isinstance
(
threshold
,
tuple
):
elif
isinstance
(
threshold
,
(
list
,
tuple
)):
atol
=
threshold
[
0
]
rtol
=
threshold
[
1
]
else
:
...
...
python/paddle/fluid/tests/unittests/mkldnn/test_bilinear_interp_v2_mkldnn_op.py
浏览文件 @
c1838da6
...
...
@@ -110,7 +110,7 @@ class TestBilinearInterpOneDNNOp(OpTest):
scale_w
=
0
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
scale_h
=
float
(
self
.
scale
)
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
python/paddle/fluid/tests/unittests/mkldnn/test_nearest_interp_v2_mkldnn_op.py
浏览文件 @
c1838da6
...
...
@@ -104,7 +104,7 @@ class TestNearestInterpV2MKLDNNOp(OpTest):
scale_w
=
0
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
scale_h
=
float
(
self
.
scale
)
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
python/paddle/fluid/tests/unittests/test_bicubic_interp_v2_op.py
浏览文件 @
c1838da6
...
...
@@ -37,17 +37,15 @@ def bicubic_interp_test(
align_corners
=
True
,
align_mode
=
0
,
):
if
isinstance
(
scale
,
float
)
or
isinstance
(
scale
,
int
):
if
isinstance
(
scale
,
(
float
,
int
)
):
scale_list
=
[]
for
_
in
range
(
len
(
x
.
shape
)
-
2
):
scale_list
.
append
(
scale
)
scale
=
list
(
map
(
float
,
scale_list
))
elif
isinstance
(
scale
,
list
)
or
isinstance
(
scale
,
tuple
):
elif
isinstance
(
scale
,
(
list
,
tuple
)
):
scale
=
list
(
map
(
float
,
scale
))
if
SizeTensor
is
not
None
:
if
not
isinstance
(
SizeTensor
,
list
)
and
not
isinstance
(
SizeTensor
,
tuple
):
if
not
isinstance
(
SizeTensor
,
(
list
,
tuple
)):
SizeTensor
=
[
SizeTensor
]
return
paddle
.
_C_ops
.
bicubic_interp
(
x
,
...
...
@@ -197,7 +195,7 @@ class TestBicubicInterpOp(OpTest):
in_w
=
self
.
input_shape
[
2
]
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0.0
:
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -236,7 +234,7 @@ class TestBicubicInterpOp(OpTest):
'data_layout'
:
self
.
data_layout
,
}
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0.0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
python/paddle/fluid/tests/unittests/test_bilinear_interp_v2_op.py
浏览文件 @
c1838da6
...
...
@@ -37,12 +37,12 @@ def bilinear_interp_test(
align_corners
=
True
,
align_mode
=
0
,
):
if
isinstance
(
scale
,
float
)
or
isinstance
(
scale
,
int
):
if
isinstance
(
scale
,
(
float
,
int
)
):
scale_list
=
[]
for
_
in
range
(
len
(
x
.
shape
)
-
2
):
scale_list
.
append
(
scale
)
scale
=
list
(
map
(
float
,
scale_list
))
elif
isinstance
(
scale
,
list
)
or
isinstance
(
scale
,
tuple
):
elif
isinstance
(
scale
,
(
list
,
tuple
)
):
scale
=
list
(
map
(
float
,
scale
))
if
SizeTensor
is
not
None
:
if
not
isinstance
(
SizeTensor
,
list
)
and
not
isinstance
(
...
...
@@ -169,7 +169,7 @@ class TestBilinearInterpOp(OpTest):
scale_h
=
0
scale_w
=
0
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0.0
:
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -210,7 +210,7 @@ class TestBilinearInterpOp(OpTest):
'data_layout'
:
self
.
data_layout
,
}
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0.0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -363,7 +363,7 @@ class TestBilinearInterpOpUint8(OpTest):
).
astype
(
"uint8"
)
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -400,7 +400,7 @@ class TestBilinearInterpOpUint8(OpTest):
'align_mode'
:
self
.
align_mode
,
}
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -537,7 +537,7 @@ class TestBilinearInterpOp_attr_tensor(OpTest):
if
self
.
scale_by_1Dtensor
:
self
.
inputs
[
'Scale'
]
=
np
.
array
([
self
.
scale
]).
astype
(
"float32"
)
elif
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -564,7 +564,7 @@ class TestBilinearInterpOp_attr_tensor(OpTest):
self
.
attrs
[
'out_h'
]
=
self
.
out_h
self
.
attrs
[
'out_w'
]
=
self
.
out_w
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
python/paddle/fluid/tests/unittests/test_desc_clone.py
浏览文件 @
c1838da6
...
...
@@ -114,9 +114,7 @@ def operator_equal(a, b):
raise
ValueError
(
"In operator_equal not equal
\n
"
)
for
k
,
v
in
a
.
__dict__
.
items
():
if
isinstance
(
v
,
fluid
.
framework
.
Program
)
or
isinstance
(
v
,
fluid
.
framework
.
Block
):
if
isinstance
(
v
,
(
fluid
.
framework
.
Program
,
fluid
.
framework
.
Block
)):
continue
elif
isinstance
(
v
,
core
.
OpDesc
):
...
...
@@ -137,13 +135,10 @@ def operator_equal(a, b):
def
block_equal
(
a
,
b
):
for
k
,
v
in
a
.
__dict__
.
items
():
if
(
isinstance
(
v
,
core
.
ProgramDesc
)
or
isinstance
(
v
,
fluid
.
framework
.
Program
)
or
isinstance
(
v
,
core
.
BlockDesc
)
if
isinstance
(
v
,
(
core
.
ProgramDesc
,
fluid
.
framework
.
Program
,
core
.
BlockDesc
)
):
continue
elif
k
==
"ops"
:
assert
len
(
a
.
ops
)
==
len
(
b
.
ops
)
for
i
in
range
(
0
,
len
(
a
.
ops
)):
...
...
python/paddle/fluid/tests/unittests/test_linear_interp_v2_op.py
浏览文件 @
c1838da6
...
...
@@ -38,12 +38,12 @@ def linear_interp_test(
align_corners
=
True
,
align_mode
=
0
,
):
if
isinstance
(
scale
,
float
)
or
isinstance
(
scale
,
int
):
if
isinstance
(
scale
,
(
float
,
int
)
):
scale_list
=
[]
for
_
in
range
(
len
(
x
.
shape
)
-
2
):
scale_list
.
append
(
scale
)
scale
=
list
(
map
(
float
,
scale_list
))
elif
isinstance
(
scale
,
list
)
or
isinstance
(
scale
,
tuple
):
elif
isinstance
(
scale
,
(
list
,
tuple
)
):
scale
=
list
(
map
(
float
,
scale
))
if
SizeTensor
is
not
None
:
if
not
isinstance
(
SizeTensor
,
list
)
and
not
isinstance
(
...
...
@@ -138,7 +138,7 @@ class TestLinearInterpOp(OpTest):
in_w
=
self
.
input_shape
[
1
]
if
self
.
scale
>
0
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
self
.
scale
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
):
self
.
scale
=
float
(
self
.
scale
[
0
])
...
...
@@ -170,7 +170,7 @@ class TestLinearInterpOp(OpTest):
'data_layout'
:
self
.
data_layout
,
}
if
self
.
scale
>
0
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
self
.
scale
=
[
float
(
self
.
scale
)]
self
.
attrs
[
'scale'
]
=
self
.
scale
self
.
outputs
=
{
'Out'
:
output_np
}
...
...
@@ -262,7 +262,7 @@ class TestLinearInterpOpSizeTensor(TestLinearInterpOp):
in_w
=
self
.
input_shape
[
1
]
if
self
.
scale
>
0
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
self
.
scale
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
):
self
.
scale
=
float
(
self
.
scale
[
0
])
...
...
@@ -302,7 +302,7 @@ class TestLinearInterpOpSizeTensor(TestLinearInterpOp):
'data_layout'
:
self
.
data_layout
,
}
if
self
.
scale
>
0
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
self
.
scale
=
[
self
.
scale
[
0
],
self
.
scale
[
0
]]
...
...
@@ -343,7 +343,7 @@ class TestResizeLinearOpUint8(OpTest):
input_np
=
np
.
random
.
random
(
self
.
input_shape
).
astype
(
"uint8"
)
if
self
.
scale
>
0
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
self
.
scale
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
):
self
.
scale
=
float
(
self
.
scale
[
0
])
...
...
@@ -371,7 +371,7 @@ class TestResizeLinearOpUint8(OpTest):
'align_mode'
:
self
.
align_mode
,
}
if
self
.
scale
>
0
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
self
.
scale
=
[
self
.
scale
[
0
],
self
.
scale
[
0
]]
...
...
python/paddle/fluid/tests/unittests/test_nearest_interp_v2_op.py
浏览文件 @
c1838da6
...
...
@@ -39,12 +39,12 @@ def nearest_interp_test(
align_corners
=
True
,
align_mode
=
0
,
):
if
isinstance
(
scale
,
float
)
or
isinstance
(
scale
,
int
):
if
isinstance
(
scale
,
(
float
,
int
)
):
scale_list
=
[]
for
_
in
range
(
len
(
x
.
shape
)
-
2
):
scale_list
.
append
(
scale
)
scale
=
list
(
map
(
float
,
scale_list
))
elif
isinstance
(
scale
,
list
)
or
isinstance
(
scale
,
tuple
):
elif
isinstance
(
scale
,
(
list
,
tuple
)
):
scale
=
list
(
map
(
float
,
scale
))
if
SizeTensor
is
not
None
:
if
not
isinstance
(
SizeTensor
,
list
)
and
not
isinstance
(
...
...
@@ -233,7 +233,7 @@ class TestNearestInterpOp(OpTest):
scale_h
=
0
scale_w
=
0
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_d
=
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -305,7 +305,7 @@ class TestNearestInterpOp(OpTest):
'data_layout'
:
self
.
data_layout
,
}
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -438,7 +438,7 @@ class TestNearestInterpOpUint8(OpTest):
).
astype
(
"uint8"
)
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -472,7 +472,7 @@ class TestNearestInterpOpUint8(OpTest):
'align_corners'
:
self
.
align_corners
,
}
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -583,7 +583,7 @@ class TestNearestInterpOp_attr_tensor(OpTest):
if
self
.
scale_by_1Dtensor
:
self
.
inputs
[
'Scale'
]
=
np
.
array
([
self
.
scale
]).
astype
(
"float64"
)
elif
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -610,7 +610,7 @@ class TestNearestInterpOp_attr_tensor(OpTest):
self
.
attrs
[
'out_h'
]
=
self
.
out_h
self
.
attrs
[
'out_w'
]
=
self
.
out_w
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
python/paddle/fluid/tests/unittests/test_trilinear_interp_v2_op.py
浏览文件 @
c1838da6
...
...
@@ -39,12 +39,12 @@ def trilinear_interp_test(
align_corners
=
True
,
align_mode
=
0
,
):
if
isinstance
(
scale
,
float
)
or
isinstance
(
scale
,
int
):
if
isinstance
(
scale
,
(
float
,
int
)
):
scale_list
=
[]
for
_
in
range
(
len
(
x
.
shape
)
-
2
):
scale_list
.
append
(
scale
)
scale
=
list
(
map
(
float
,
scale_list
))
elif
isinstance
(
scale
,
list
)
or
isinstance
(
scale
,
tuple
):
elif
isinstance
(
scale
,
(
list
,
tuple
)
):
scale
=
list
(
map
(
float
,
scale
))
if
SizeTensor
is
not
None
:
if
not
isinstance
(
SizeTensor
,
list
)
and
not
isinstance
(
...
...
@@ -219,7 +219,7 @@ class TestTrilinearInterpOp(OpTest):
in_w
=
self
.
input_shape
[
3
]
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_d
=
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -270,7 +270,7 @@ class TestTrilinearInterpOp(OpTest):
'data_layout'
:
data_layout
,
}
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -434,7 +434,7 @@ class TestTrilinearInterpOpUint8(OpTest):
).
astype
(
"uint8"
)
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_d
=
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -477,7 +477,7 @@ class TestTrilinearInterpOpUint8(OpTest):
'align_mode'
:
self
.
align_mode
,
}
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -611,7 +611,7 @@ class TestTrilinearInterpOp_attr_tensor(OpTest):
if
self
.
scale_by_1Dtensor
:
self
.
inputs
[
'Scale'
]
=
np
.
array
([
self
.
scale
]).
astype
(
"float32"
)
elif
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_d
=
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -642,7 +642,7 @@ class TestTrilinearInterpOp_attr_tensor(OpTest):
self
.
attrs
[
'out_h'
]
=
self
.
out_h
self
.
attrs
[
'out_w'
]
=
self
.
out_w
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
python/paddle/fluid/tests/unittests/testsuite.py
浏览文件 @
c1838da6
...
...
@@ -71,7 +71,7 @@ def create_op(scope, op_type, inputs, outputs, attrs, cache_list=None):
def
set_input
(
scope
,
op
,
inputs
,
place
):
def
__set_input__
(
var_name
,
var
):
if
isinstance
(
var
,
tuple
)
or
isinstance
(
var
,
np
.
ndarray
):
if
isinstance
(
var
,
(
tuple
,
np
.
ndarray
)
):
tensor
=
scope
.
find_var
(
var_name
).
get_tensor
()
if
isinstance
(
var
,
tuple
):
tensor
.
set_recursive_sequence_lengths
(
var
[
1
])
...
...
python/paddle/fluid/tests/unittests/xpu/test_bilinear_interp_v2_op_xpu.py
浏览文件 @
c1838da6
...
...
@@ -141,7 +141,7 @@ class XPUTestBilinearInterpV2Op(XPUOpTestWrapper):
scale_h
=
0
scale_w
=
0
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0.0
:
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -182,7 +182,7 @@ class XPUTestBilinearInterpV2Op(XPUOpTestWrapper):
'data_layout'
:
self
.
data_layout
,
}
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0.0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -389,7 +389,7 @@ class XPUTestBilinearInterpV2Op(XPUOpTestWrapper):
if
self
.
scale_by_1Dtensor
:
self
.
inputs
[
'Scale'
]
=
np
.
array
([
self
.
scale
]).
astype
(
"float32"
)
elif
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -416,7 +416,7 @@ class XPUTestBilinearInterpV2Op(XPUOpTestWrapper):
self
.
attrs
[
'out_h'
]
=
self
.
out_h
self
.
attrs
[
'out_w'
]
=
self
.
out_w
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
python/paddle/fluid/tests/unittests/xpu/test_nearest_interp_v2_op_xpu.py
浏览文件 @
c1838da6
...
...
@@ -212,7 +212,7 @@ class XPUNearestInterpOpWrapper(XPUOpTestWrapper):
scale_h
=
0
scale_w
=
0
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_d
=
scale_h
=
scale_w
=
float
(
self
.
scale
)
self
.
scale
=
[
self
.
scale
]
...
...
@@ -450,7 +450,7 @@ class XPUNearestInterpOpWrapper(XPUOpTestWrapper):
if
self
.
scale_by_1Dtensor
:
self
.
inputs
[
'Scale'
]
=
np
.
array
([
self
.
scale
]).
astype
(
"float32"
)
elif
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
scale_h
=
scale_w
=
float
(
self
.
scale
)
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
@@ -477,7 +477,7 @@ class XPUNearestInterpOpWrapper(XPUOpTestWrapper):
self
.
attrs
[
'out_h'
]
=
self
.
out_h
self
.
attrs
[
'out_w'
]
=
self
.
out_w
if
self
.
scale
:
if
isinstance
(
self
.
scale
,
float
)
or
isinstance
(
self
.
scale
,
int
):
if
isinstance
(
self
.
scale
,
(
float
,
int
)
):
if
self
.
scale
>
0
:
self
.
scale
=
[
self
.
scale
]
if
isinstance
(
self
.
scale
,
list
)
and
len
(
self
.
scale
)
==
1
:
...
...
python/paddle/hapi/progressbar.py
浏览文件 @
c1838da6
...
...
@@ -81,11 +81,7 @@ class ProgressBar:
for
i
,
(
k
,
val
)
in
enumerate
(
values
):
if
k
==
"loss"
:
val
=
(
val
if
isinstance
(
val
,
list
)
or
isinstance
(
val
,
np
.
ndarray
)
else
[
val
]
)
val
=
val
if
isinstance
(
val
,
(
list
,
np
.
ndarray
))
else
[
val
]
if
isinstance
(
val
[
0
],
np
.
uint16
):
values
[
i
]
=
(
"loss"
,
list
(
convert_uint16_to_float
(
val
)))
...
...
python/paddle/incubate/distributed/fleet/utils.py
浏览文件 @
c1838da6
...
...
@@ -192,7 +192,7 @@ def load_var(var_name, shape_list, dtype, save_path):
def
reader
(
batch_size
,
fn
,
dim
):
data
=
[]
if
isinstance
(
dim
,
list
)
or
isinstance
(
dim
,
tuple
):
if
isinstance
(
dim
,
(
list
,
tuple
)
):
shape
=
list
(
dim
)
_temp
=
1
for
x
in
dim
:
...
...
python/paddle/jit/api.py
浏览文件 @
c1838da6
...
...
@@ -915,9 +915,7 @@ def save(layer, path, input_spec=None, **configs):
)
if
not
(
isinstance
(
layer
,
Layer
)
or
inspect
.
isfunction
(
layer
)
or
isinstance
(
layer
,
StaticFunction
)
isinstance
(
layer
,
(
Layer
,
StaticFunction
))
or
inspect
.
isfunction
(
layer
)
):
raise
TypeError
(
"The input of paddle.jit.save should be 'Layer' or 'Function', but received input type is %s."
...
...
python/paddle/jit/dy2static/static_analysis.py
浏览文件 @
c1838da6
...
...
@@ -179,9 +179,7 @@ class StaticAnalysisVisitor:
self
.
ancestor_wrappers
.
append
(
cur_wrapper
)
for
child
in
gast
.
iter_child_nodes
(
node
):
if
isinstance
(
child
,
gast
.
FunctionDef
)
or
isinstance
(
child
,
gast
.
AsyncFunctionDef
):
if
isinstance
(
child
,
(
gast
.
FunctionDef
,
gast
.
AsyncFunctionDef
)):
# TODO: current version is function name mapping to its type
# consider complex case involving parameters
self
.
var_env
.
enter_scope
(
...
...
python/paddle/nn/functional/common.py
浏览文件 @
c1838da6
...
...
@@ -399,9 +399,7 @@ def interpolate(
if
size
is
None
and
scale_factor
is
None
:
raise
ValueError
(
"One of size and scale_factor must not be None."
)
if
(
isinstance
(
size
,
list
)
or
isinstance
(
size
,
tuple
))
and
len
(
size
)
!=
x
.
ndim
-
2
:
if
isinstance
(
size
,
(
tuple
,
list
))
and
(
len
(
size
)
!=
x
.
ndim
-
2
):
raise
ValueError
(
'The x and size should satisfy rank(x) - 2 == len(size).'
)
...
...
@@ -427,11 +425,7 @@ def interpolate(
)
if
resample
==
'AREA'
:
if
(
isinstance
(
size
,
list
)
or
isinstance
(
size
,
tuple
)
or
isinstance
(
size
,
Variable
)
):
if
isinstance
(
size
,
(
list
,
tuple
,
Variable
)):
if
len
(
size
)
==
0
:
raise
ValueError
(
"output size can not be empty"
)
if
size
is
None
:
...
...
@@ -464,7 +458,7 @@ def interpolate(
)
def
_is_list_or_turple_
(
data
):
return
isinstance
(
data
,
list
)
or
isinstance
(
data
,
tuple
)
return
isinstance
(
data
,
(
list
,
tuple
)
)
if
data_format
==
'NCHW'
or
data_format
==
'NCDHW'
or
data_format
==
'NCW'
:
data_layout
=
'NCHW'
...
...
@@ -581,18 +575,14 @@ def interpolate(
if
isinstance
(
scale
,
Variable
):
scale
.
stop_gradient
=
True
inputs
[
"Scale"
]
=
scale
elif
(
isinstance
(
scale
,
float
)
or
isinstance
(
scale
,
int
)
or
isinstance
(
scale
,
numpy
.
ndarray
)
):
elif
isinstance
(
scale
,
(
float
,
int
,
numpy
.
ndarray
)):
if
scale
<=
0
:
raise
ValueError
(
"Attr(scale) should be greater than zero."
)
scale_list
=
[]
for
i
in
range
(
len
(
x
.
shape
)
-
2
):
scale_list
.
append
(
scale
)
attrs
[
'scale'
]
=
list
(
map
(
float
,
scale_list
))
elif
isinstance
(
scale
,
list
)
or
isinstance
(
scale
,
tuple
):
elif
isinstance
(
scale
,
(
list
,
tuple
)
):
if
len
(
scale
)
!=
len
(
x
.
shape
)
-
2
:
raise
ValueError
(
"scale_shape length should be {} for "
...
...
@@ -2275,7 +2265,7 @@ def fold(
assert
len
(
x
.
shape
)
==
3
,
"input should be the format of [N, C, L]"
def
_is_list_or_turple_
(
data
):
return
isinstance
(
data
,
list
)
or
isinstance
(
data
,
tuple
)
return
isinstance
(
data
,
(
list
,
tuple
)
)
if
isinstance
(
output_sizes
,
int
):
output_sizes
=
[
output_sizes
,
output_sizes
]
...
...
python/paddle/nn/initializer/constant.py
浏览文件 @
c1838da6
...
...
@@ -50,9 +50,7 @@ class ConstantInitializer(Initializer):
"""
block
=
self
.
_check_block
(
block
)
assert
isinstance
(
var
,
framework
.
Variable
)
or
isinstance
(
var
,
framework
.
EagerParamBase
)
assert
isinstance
(
var
,
(
framework
.
Variable
,
framework
.
EagerParamBase
))
assert
isinstance
(
block
,
framework
.
Block
)
if
in_dygraph_mode
():
...
...
python/paddle/nn/layer/layers.py
浏览文件 @
c1838da6
...
...
@@ -1860,7 +1860,7 @@ class Layer:
raise
ValueError
(
"{} is not found in the provided dict."
.
format
(
key
)
)
if
isinstance
(
state
,
dict
)
or
isinstance
(
state
,
list
):
if
isinstance
(
state
,
(
dict
,
list
)
):
if
len
(
state
)
!=
len
(
param
):
missing_keys
.
append
(
key
)
raise
ValueError
(
...
...
python/paddle/nn/layer/rnn.py
浏览文件 @
c1838da6
...
...
@@ -593,7 +593,7 @@ class RNNCellBase(Layer):
def
_is_shape_sequence
(
seq
):
"""For shape, list/tuple of integer is the finest-grained objection"""
if
isinstance
(
seq
,
list
)
or
isinstance
(
seq
,
tuple
):
if
isinstance
(
seq
,
(
list
,
tuple
)
):
if
reduce
(
lambda
flag
,
x
:
isinstance
(
x
,
int
)
and
flag
,
seq
,
True
):
...
...
python/paddle/nn/quant/quant_layers.py
浏览文件 @
c1838da6
...
...
@@ -1087,11 +1087,7 @@ class MAOutputScaleLayer(Layer):
def
forward
(
self
,
*
inputs
,
**
kwargs
):
out
=
self
.
_layer
(
*
inputs
,
**
kwargs
)
# TODO (jc): support the ops of several outputs
if
(
isinstance
(
out
,
list
)
or
isinstance
(
out
,
tuple
)
or
isinstance
(
out
,
dict
)
):
if
isinstance
(
out
,
(
list
,
tuple
,
dict
)):
return
out
else
:
return
self
.
_ma_output_scale
(
out
)
...
...
@@ -1129,7 +1125,7 @@ class FakeQuantMAOutputScaleLayer(Layer):
def
forward
(
self
,
*
inputs
,
**
kwargs
):
out
=
self
.
_layer
(
*
inputs
,
**
kwargs
)
# TODO (jc): support the ops of several outputs
if
(
isinstance
(
out
,
list
)
or
isinstance
(
out
,
tuple
))
and
len
(
out
)
>
1
:
if
(
isinstance
(
out
,
(
list
,
tuple
)
))
and
len
(
out
)
>
1
:
return
out
else
:
return
self
.
_fake_quant_output
(
out
)
...
...
python/paddle/optimizer/lr.py
浏览文件 @
c1838da6
...
...
@@ -791,11 +791,7 @@ class LinearWarmup(LRScheduler):
last_epoch
=-
1
,
verbose
=
False
,
):
type_check
=
(
isinstance
(
learning_rate
,
float
)
or
isinstance
(
learning_rate
,
int
)
or
isinstance
(
learning_rate
,
LRScheduler
)
)
type_check
=
isinstance
(
learning_rate
,
(
float
,
int
,
LRScheduler
))
if
not
type_check
:
raise
TypeError
(
"the type of learning_rate should be [int, float or LRScheduler], the current type is {}"
.
format
(
...
...
python/paddle/static/nn/common.py
浏览文件 @
c1838da6
...
...
@@ -961,13 +961,11 @@ def conv2d(
# padding
def
_update_padding
(
padding
,
data_format
):
def
is_list_or_tuple
(
ele
):
if
isinstance
(
ele
,
list
)
or
isinstance
(
ele
,
tuple
):
return
True
return
False
if
is_list_or_tuple
(
padding
)
and
len
(
padding
)
==
4
:
if
is_list_or_tuple
(
padding
[
0
])
and
(
data_format
==
"NCHW"
):
if
isinstance
(
padding
,
(
list
,
tuple
))
and
len
(
padding
)
==
4
:
if
isinstance
(
padding
[
0
],
(
list
,
tuple
))
and
(
data_format
==
"NCHW"
):
if
not
(
padding
[
0
]
==
[
0
,
0
]
and
padding
[
1
]
==
[
0
,
0
]):
raise
ValueError
(
"Non-zero padding(%s) in the batch or channel dimensions "
...
...
@@ -975,7 +973,9 @@ def conv2d(
)
padding
=
padding
[
2
:
4
]
padding
=
[
ele
for
a_list
in
padding
for
ele
in
a_list
]
elif
is_list_or_tuple
(
padding
[
0
])
and
(
data_format
==
"NHWC"
):
elif
isinstance
(
padding
[
0
],
(
list
,
tuple
))
and
(
data_format
==
"NHWC"
):
if
not
(
padding
[
0
]
==
[
0
,
0
]
and
padding
[
3
]
==
[
0
,
0
]):
raise
ValueError
(
"Non-zero padding(%s) in the batch or channel dimensions "
...
...
@@ -1257,13 +1257,11 @@ def conv3d(
dilation
=
paddle
.
utils
.
convert_to_list
(
dilation
,
3
,
'dilation'
)
def
_update_padding
(
padding
,
data_format
):
def
is_list_or_tuple
(
ele
):
if
isinstance
(
ele
,
list
)
or
isinstance
(
ele
,
tuple
):
return
True
return
False
if
is_list_or_tuple
(
padding
)
and
len
(
padding
)
==
5
:
if
is_list_or_tuple
(
padding
[
0
])
and
(
data_format
==
"NCDHW"
):
if
isinstance
(
padding
,
(
list
,
tuple
))
and
len
(
padding
)
==
5
:
if
isinstance
(
padding
[
0
],
(
list
,
tuple
))
and
(
data_format
==
"NCDHW"
):
if
not
(
padding
[
0
]
==
[
0
,
0
]
and
padding
[
1
]
==
[
0
,
0
]):
raise
ValueError
(
"Non-zero padding(%s) in the batch or channel dimensions "
...
...
@@ -1271,7 +1269,9 @@ def conv3d(
)
padding
=
padding
[
2
:
5
]
padding
=
[
ele
for
a_list
in
padding
for
ele
in
a_list
]
elif
is_list_or_tuple
(
padding
[
0
])
and
(
data_format
==
"NDHWC"
):
elif
isinstance
(
padding
[
0
],
(
list
,
tuple
))
and
(
data_format
==
"NDHWC"
):
if
not
(
padding
[
0
]
==
[
0
,
0
]
and
padding
[
4
]
==
[
0
,
0
]):
raise
ValueError
(
"Non-zero padding(%s) in the batch or channel dimensions "
...
...
@@ -1282,7 +1282,7 @@ def conv3d(
padding
=
paddle
.
utils
.
convert_to_list
(
padding
,
6
,
'padding'
)
if
paddle
.
utils
.
_is_symmetric_padding
(
padding
,
3
):
padding
=
[
padding
[
0
],
padding
[
2
],
padding
[
4
]]
elif
is
_list_or_tuple
(
padding
)
and
len
(
padding
)
==
6
:
elif
is
instance
(
padding
,
(
list
,
tuple
)
)
and
len
(
padding
)
==
6
:
padding
=
paddle
.
utils
.
convert_to_list
(
padding
,
6
,
'padding'
)
if
paddle
.
utils
.
_is_symmetric_padding
(
padding
,
3
):
padding
=
[
padding
[
0
],
padding
[
2
],
padding
[
4
]]
...
...
@@ -1580,13 +1580,11 @@ def conv2d_transpose(
raise
ValueError
(
"use_cudnn should be True or False"
)
def
_update_padding
(
padding
,
data_format
):
def
is_list_or_tuple
(
ele
):
if
isinstance
(
ele
,
list
)
or
isinstance
(
ele
,
tuple
):
return
True
return
False
if
is_list_or_tuple
(
padding
)
and
len
(
padding
)
==
4
:
if
is_list_or_tuple
(
padding
[
0
])
and
(
data_format
==
"NCHW"
):
if
isinstance
(
padding
,
(
list
,
tuple
))
and
len
(
padding
)
==
4
:
if
isinstance
(
padding
[
0
],
(
list
,
tuple
))
and
(
data_format
==
"NCHW"
):
if
not
(
padding
[
0
]
==
[
0
,
0
]
and
padding
[
1
]
==
[
0
,
0
]):
raise
ValueError
(
"Non-zero padding(%s) in the batch or channel dimensions "
...
...
@@ -1594,7 +1592,9 @@ def conv2d_transpose(
)
padding
=
padding
[
2
:
4
]
padding
=
[
ele
for
a_list
in
padding
for
ele
in
a_list
]
elif
is_list_or_tuple
(
padding
[
0
])
and
(
data_format
==
"NHWC"
):
elif
isinstance
(
padding
[
0
],
(
list
,
tuple
))
and
(
data_format
==
"NHWC"
):
if
not
(
padding
[
0
]
==
[
0
,
0
]
and
padding
[
3
]
==
[
0
,
0
]):
raise
ValueError
(
"Non-zero padding(%s) in the batch or channel dimensions "
...
...
@@ -1951,13 +1951,11 @@ def conv3d_transpose(
raise
ValueError
(
"use_cudnn should be True or False"
)
def
_update_padding
(
padding
,
data_format
):
def
is_list_or_tuple
(
ele
):
if
isinstance
(
ele
,
list
)
or
isinstance
(
ele
,
tuple
):
return
True
return
False
if
is_list_or_tuple
(
padding
)
and
len
(
padding
)
==
5
:
if
is_list_or_tuple
(
padding
[
0
])
and
(
data_format
==
"NCDHW"
):
if
isinstance
(
padding
,
(
list
,
tuple
))
and
len
(
padding
)
==
5
:
if
isinstance
(
padding
[
0
],
(
list
,
tuple
))
and
(
data_format
==
"NCDHW"
):
if
not
(
padding
[
0
]
==
[
0
,
0
]
and
padding
[
1
]
==
[
0
,
0
]):
raise
ValueError
(
"Non-zero padding(%s) in the batch or channel dimensions "
...
...
@@ -1965,7 +1963,9 @@ def conv3d_transpose(
)
padding
=
padding
[
2
:
5
]
padding
=
[
ele
for
a_list
in
padding
for
ele
in
a_list
]
elif
is_list_or_tuple
(
padding
[
0
])
and
(
data_format
==
"NDHWC"
):
elif
isinstance
(
padding
[
0
],
(
list
,
tuple
))
and
(
data_format
==
"NDHWC"
):
if
not
(
padding
[
0
]
==
[
0
,
0
]
and
padding
[
4
]
==
[
0
,
0
]):
raise
ValueError
(
"Non-zero padding(%s) in the batch or channel dimensions "
...
...
@@ -1975,7 +1975,7 @@ def conv3d_transpose(
padding
=
[
ele
for
a_list
in
padding
for
ele
in
a_list
]
padding
=
paddle
.
utils
.
convert_to_list
(
padding
,
6
,
'padding'
)
elif
is
_list_or_tuple
(
padding
)
and
len
(
padding
)
==
6
:
elif
is
instance
(
padding
,
(
list
,
tuple
)
)
and
len
(
padding
)
==
6
:
padding
=
paddle
.
utils
.
convert_to_list
(
padding
,
6
,
'padding'
)
else
:
...
...
python/paddle/static/quantization/quantization_pass.py
浏览文件 @
c1838da6
...
...
@@ -1438,12 +1438,7 @@ class QuantizationFreezePass:
return
"%s.dequantized"
%
(
var_name
)
def
_is_float
(
self
,
v
):
return
(
isinstance
(
v
,
float
)
or
isinstance
(
v
,
np
.
float16
)
or
isinstance
(
v
,
np
.
float32
)
or
isinstance
(
v
,
np
.
float64
)
)
return
isinstance
(
v
,
(
float
,
np
.
float16
,
np
.
float32
,
np
.
float64
))
class
ConvertToInt8Pass
:
...
...
python/paddle/static/quantization/tests/test_imperative_ptq.py
浏览文件 @
c1838da6
...
...
@@ -60,10 +60,7 @@ class TestFuseLinearBn(unittest.TestCase):
quant_h
=
ptq
.
quantize
(
model_h
,
fuse
=
True
,
fuse_list
=
f_l
)
for
name
,
layer
in
quant_model
.
named_sublayers
():
if
name
in
f_l
:
assert
not
(
isinstance
(
layer
,
nn
.
BatchNorm1D
)
or
isinstance
(
layer
,
nn
.
BatchNorm2D
)
)
assert
not
(
isinstance
(
layer
,
(
nn
.
BatchNorm1D
,
nn
.
BatchNorm2D
)))
out
=
model
(
inputs
)
out_h
=
model_h
(
inputs
)
out_quant
=
quant_model
(
inputs
)
...
...
@@ -294,10 +291,7 @@ class TestImperativePTQfuse(TestImperativePTQ):
quant_model
=
self
.
ptq
.
quantize
(
model
,
fuse
=
True
,
fuse_list
=
f_l
)
for
name
,
layer
in
quant_model
.
named_sublayers
():
if
name
in
f_l
:
assert
not
(
isinstance
(
layer
,
nn
.
BatchNorm1D
)
or
isinstance
(
layer
,
nn
.
BatchNorm2D
)
)
assert
not
(
isinstance
(
layer
,
(
nn
.
BatchNorm1D
,
nn
.
BatchNorm2D
)))
before_acc_top1
=
self
.
model_test
(
quant_model
,
self
.
batch_num
,
self
.
batch_size
)
...
...
python/paddle/tensor/layer_function_generator.py
浏览文件 @
c1838da6
...
...
@@ -238,11 +238,7 @@ def generate_layer_fn(op_type):
outputs
=
{}
out
=
kwargs
.
pop
(
_convert_
(
o_name
),
[])
if
out
:
out_var
=
(
out
[
0
]
if
(
isinstance
(
out
,
list
)
or
isinstance
(
out
,
tuple
))
else
out
)
out_var
=
out
[
0
]
if
isinstance
(
out
,
(
list
,
tuple
))
else
out
else
:
out_var
=
helper
.
create_variable_for_type_inference
(
dtype
=
dtype
)
outputs
[
o_name
]
=
[
out_var
]
...
...
python/paddle/tensor/math.py
浏览文件 @
c1838da6
...
...
@@ -1651,7 +1651,7 @@ def add_n(inputs, name=None):
else
:
helper
=
LayerHelper
(
'add_n'
,
**
locals
())
check_type
(
inputs
,
'inputs'
,
(
Variable
,
tuple
,
list
),
'add_n'
)
if
isinstance
(
inputs
,
list
)
or
isinstance
(
inputs
,
tuple
):
if
isinstance
(
inputs
,
(
list
,
tuple
)
):
if
len
(
inputs
)
>
0
:
for
input
in
inputs
:
check_variable_and_dtype
(
...
...
python/paddle/vision/ops.py
浏览文件 @
c1838da6
...
...
@@ -495,7 +495,7 @@ def prior_box(
"""
def
_is_list_or_tuple_
(
data
):
return
isinstance
(
data
,
list
)
or
isinstance
(
data
,
tuple
)
return
isinstance
(
data
,
(
list
,
tuple
)
)
if
not
_is_list_or_tuple_
(
min_sizes
):
min_sizes
=
[
min_sizes
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录