Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
cb34ee0f
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,发现更多精彩内容 >>
未验证
提交
cb34ee0f
编写于
12月 23, 2022
作者:
姜
姜永久
提交者:
GitHub
12月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rm eager guard test (#49245)
* rm eager guard test * retain grad for xpu test
上级
ca4155c8
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
40 addition
and
226 deletion
+40
-226
python/paddle/fluid/contrib/slim/tests/test_imperative_qat_matmul.py
...le/fluid/contrib/slim/tests/test_imperative_qat_matmul.py
+0
-1
python/paddle/fluid/tests/custom_op/test_custom_relu_op_xpu_setup.py
...le/fluid/tests/custom_op/test_custom_relu_op_xpu_setup.py
+5
-7
python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage3_eager.py
...ts/collective/fleet/dygraph_group_sharded_stage3_eager.py
+1
-3
python/paddle/fluid/tests/unittests/spawn_runner_base.py
python/paddle/fluid/tests/unittests/spawn_runner_base.py
+0
-5
python/paddle/fluid/tests/unittests/test_math_op_patch_var_base.py
...ddle/fluid/tests/unittests/test_math_op_patch_var_base.py
+32
-193
python/paddle/fluid/tests/unittests/xpu/test_diag_v2_op_xpu.py
...n/paddle/fluid/tests/unittests/xpu/test_diag_v2_op_xpu.py
+0
-3
python/paddle/fluid/tests/unittests/xpu/test_set_value_op_xpu.py
...paddle/fluid/tests/unittests/xpu/test_set_value_op_xpu.py
+1
-7
python/paddle/tests/test_callback_wandb.py
python/paddle/tests/test_callback_wandb.py
+1
-7
未找到文件。
python/paddle/fluid/contrib/slim/tests/test_imperative_qat_matmul.py
浏览文件 @
cb34ee0f
...
...
@@ -38,7 +38,6 @@ from paddle.nn.quant.quant_layers import (
QuantizedConv2D
,
QuantizedMatmul
,
)
from
paddle.fluid.framework
import
_test_eager_guard
from
imperative_test_utils
import
fix_model_dict
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/custom_op/test_custom_relu_op_xpu_setup.py
浏览文件 @
cb34ee0f
...
...
@@ -21,7 +21,6 @@ import numpy as np
import
paddle
import
paddle.static
as
static
from
paddle.fluid.framework
import
_test_eager_guard
from
paddle.utils.cpp_extension.extension_utils
import
run_cmd
from
paddle.vision.transforms
import
Compose
,
Normalize
...
...
@@ -143,6 +142,9 @@ def custom_relu_static_inference(func, device, np_data, np_label, path_prefix):
def
custom_relu_double_grad_dynamic
(
func
,
device
,
dtype
,
np_x
,
use_func
=
True
):
import
paddle.fluid
as
fluid
fluid
.
set_flags
({
"FLAGS_retain_grad_for_all_tensor"
:
True
})
paddle
.
set_device
(
device
)
t
=
paddle
.
to_tensor
(
np_x
,
dtype
=
dtype
,
stop_gradient
=
False
)
...
...
@@ -158,6 +160,7 @@ def custom_relu_double_grad_dynamic(func, device, dtype, np_x, use_func=True):
assert
dx
[
0
].
grad
is
not
None
return
dx
[
0
].
numpy
(),
dx
[
0
].
grad
.
numpy
()
fluid
.
set_flags
({
"FLAGS_retain_grad_for_all_tensor"
:
False
})
class
TestNewCustomOpSetUpInstall
(
unittest
.
TestCase
):
...
...
@@ -228,7 +231,7 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase):
),
)
def
func
_dynamic
(
self
):
def
test
_dynamic
(
self
):
for
device
in
self
.
devices
:
for
dtype
in
self
.
dtypes
:
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
4
,
8
]).
astype
(
dtype
)
...
...
@@ -253,11 +256,6 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase):
),
)
def
test_dynamic
(
self
):
with
_test_eager_guard
():
self
.
func_dynamic
()
self
.
func_dynamic
()
def
test_static_save_and_load_inference_model
(
self
):
paddle
.
enable_static
()
np_data
=
np
.
random
.
random
((
1
,
1
,
28
,
28
)).
astype
(
"float32"
)
...
...
python/paddle/fluid/tests/unittests/collective/fleet/dygraph_group_sharded_stage3_eager.py
浏览文件 @
cb34ee0f
...
...
@@ -18,7 +18,6 @@ import numpy as np
import
paddle
from
paddle
import
nn
from
paddle.distributed.sharding
import
group_sharded_parallel
from
paddle.fluid.framework
import
_test_eager_guard
paddle
.
seed
(
2022
)
np
.
random
.
seed
(
2022
)
...
...
@@ -174,5 +173,4 @@ def test_sharding_api():
if
__name__
==
'__main__'
:
with
_test_eager_guard
():
test_sharding_api
()
python/paddle/fluid/tests/unittests/spawn_runner_base.py
浏览文件 @
cb34ee0f
...
...
@@ -20,7 +20,6 @@ import numpy as np
from
test_dist_base
import
RUN_STEP
import
paddle
from
paddle.fluid.framework
import
_test_eager_guard
# NOTE: compatible TestParallelDyGraphRunnerBase args
...
...
@@ -54,10 +53,6 @@ class TestDistSpawnRunner(unittest.TestCase):
return
result_list
def
check_dist_result_with_spawn
(
self
,
test_class
,
delta
=
1e-3
):
with
_test_eager_guard
():
self
.
check_dist_result_with_spawn_func
(
test_class
=
test_class
,
delta
=
delta
)
self
.
check_dist_result_with_spawn_func
(
test_class
=
test_class
,
delta
=
delta
)
...
...
python/paddle/fluid/tests/unittests/test_math_op_patch_var_base.py
浏览文件 @
cb34ee0f
...
...
@@ -19,7 +19,6 @@ import numpy as np
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.framework
import
_test_eager_guard
class
TestMathOpPatchesVarBase
(
unittest
.
TestCase
):
...
...
@@ -27,7 +26,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
self
.
shape
=
[
10
,
1024
]
self
.
dtype
=
np
.
float32
def
func_
test_add
(
self
):
def
test_add
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
b_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -36,12 +35,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
+
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
+
b_np
)
def
test_add
(
self
):
with
_test_eager_guard
():
self
.
func_test_add
()
self
.
func_test_add
()
def
func_test_sub
(
self
):
def
test_sub
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
b_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -50,12 +44,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
-
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
-
b_np
)
def
test_sub
(
self
):
with
_test_eager_guard
():
self
.
func_test_sub
()
self
.
func_test_sub
()
def
func_test_mul
(
self
):
def
test_mul
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
b_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -64,12 +53,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
*
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
*
b_np
)
def
test_mul
(
self
):
with
_test_eager_guard
():
self
.
func_test_mul
()
self
.
func_test_mul
()
def
func_test_div
(
self
):
def
test_div
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
b_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -79,12 +63,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
# NOTE: Not sure why array_equal fails on windows, allclose is acceptable
np
.
testing
.
assert_allclose
(
res
.
numpy
(),
a_np
/
b_np
,
rtol
=
1e-05
)
def
test_div
(
self
):
with
_test_eager_guard
():
self
.
func_test_div
()
self
.
func_test_div
()
def
func_test_add_scalar
(
self
):
def
test_add_scalar
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
...
...
@@ -92,12 +71,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
+
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
+
b
)
def
test_add_scalar
(
self
):
with
_test_eager_guard
():
self
.
func_test_add_scalar
()
self
.
func_test_add_scalar
()
def
func_test_add_scalar_reverse
(
self
):
def
test_add_scalar_reverse
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
...
...
@@ -105,12 +79,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
b
+
a
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
b
+
a_np
)
def
test_add_scalar_reverse
(
self
):
with
_test_eager_guard
():
self
.
func_test_add_scalar_reverse
()
self
.
func_test_add_scalar_reverse
()
def
func_test_sub_scalar
(
self
):
def
test_sub_scalar
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
...
...
@@ -118,12 +87,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
-
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
-
b
)
def
test_sub_scalar
(
self
):
with
_test_eager_guard
():
self
.
func_test_sub_scalar
()
self
.
func_test_sub_scalar
()
def
func_test_sub_scalar_reverse
(
self
):
def
test_sub_scalar_reverse
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
...
...
@@ -131,12 +95,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
b
-
a
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
b
-
a_np
)
def
test_sub_scalar_reverse
(
self
):
with
_test_eager_guard
():
self
.
func_test_sub_scalar_reverse
()
self
.
func_test_sub_scalar_reverse
()
def
func_test_mul_scalar
(
self
):
def
test_mul_scalar
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
...
...
@@ -144,13 +103,8 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
*
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
*
b
)
def
test_mul_scalar
(
self
):
with
_test_eager_guard
():
self
.
func_test_mul_scalar
()
self
.
func_test_mul_scalar
()
# div_scalar, not equal
def
func_
test_div_scalar
(
self
):
def
test_div_scalar
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
...
...
@@ -158,13 +112,8 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
/
b
np
.
testing
.
assert_allclose
(
res
.
numpy
(),
a_np
/
b
,
rtol
=
1e-05
)
def
test_div_scalar
(
self
):
with
_test_eager_guard
():
self
.
func_test_div_scalar
()
self
.
func_test_div_scalar
()
# pow of float type, not equal
def
func_
test_pow
(
self
):
def
test_pow
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
b_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -173,12 +122,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
**
b
np
.
testing
.
assert_allclose
(
res
.
numpy
(),
a_np
**
b_np
,
rtol
=
1e-05
)
def
test_pow
(
self
):
with
_test_eager_guard
():
self
.
func_test_pow
()
self
.
func_test_pow
()
def
func_test_floor_div
(
self
):
def
test_floor_div
(
self
):
a_np
=
np
.
random
.
randint
(
1
,
100
,
size
=
self
.
shape
)
b_np
=
np
.
random
.
randint
(
1
,
100
,
size
=
self
.
shape
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -187,12 +131,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
//
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
//
b_np
)
def
test_floor_div
(
self
):
with
_test_eager_guard
():
self
.
func_test_floor_div
()
self
.
func_test_floor_div
()
def
func_test_mod
(
self
):
def
test_mod
(
self
):
a_np
=
np
.
random
.
randint
(
1
,
100
,
size
=
self
.
shape
)
b_np
=
np
.
random
.
randint
(
1
,
100
,
size
=
self
.
shape
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -201,13 +140,8 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
%
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
%
b_np
)
def
test_mod
(
self
):
with
_test_eager_guard
():
self
.
func_test_mod
()
self
.
func_test_mod
()
# for bitwise and/or/xor/not
def
func_
test_bitwise
(
self
):
def
test_bitwise
(
self
):
paddle
.
disable_static
()
x_np
=
np
.
random
.
randint
(
-
100
,
100
,
[
2
,
3
,
5
])
...
...
@@ -231,13 +165,8 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
out
=
~
x
np
.
testing
.
assert_array_equal
(
out
.
numpy
(),
out_np
)
def
test_bitwise
(
self
):
with
_test_eager_guard
():
self
.
func_test_bitwise
()
self
.
func_test_bitwise
()
# for logical compare
def
func_
test_equal
(
self
):
def
test_equal
(
self
):
a_np
=
np
.
asarray
([
1
,
2
,
3
,
4
,
5
])
b_np
=
np
.
asarray
([
1
,
2
,
3
,
4
,
5
])
c_np
=
np
.
asarray
([
1
,
2
,
2
,
4
,
5
])
...
...
@@ -250,12 +179,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
np
.
testing
.
assert_array_equal
(
res1
.
numpy
(),
a_np
==
b_np
)
np
.
testing
.
assert_array_equal
(
res2
.
numpy
(),
a_np
==
c_np
)
def
test_equal
(
self
):
with
_test_eager_guard
():
self
.
func_test_equal
()
self
.
func_test_equal
()
def
func_test_not_equal
(
self
):
def
test_not_equal
(
self
):
a_np
=
np
.
asarray
([
1
,
2
,
3
,
4
,
5
])
b_np
=
np
.
asarray
([
1
,
2
,
3
,
4
,
5
])
c_np
=
np
.
asarray
([
1
,
2
,
2
,
4
,
5
])
...
...
@@ -268,12 +192,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
np
.
testing
.
assert_array_equal
(
res1
.
numpy
(),
a_np
!=
b_np
)
np
.
testing
.
assert_array_equal
(
res2
.
numpy
(),
a_np
!=
c_np
)
def
test_not_equal
(
self
):
with
_test_eager_guard
():
self
.
func_test_not_equal
()
self
.
func_test_not_equal
()
def
func_test_less_than
(
self
):
def
test_less_than
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
b_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -282,12 +201,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
<
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
<
b_np
)
def
test_less_than
(
self
):
with
_test_eager_guard
():
self
.
func_test_less_than
()
self
.
func_test_less_than
()
def
func_test_less_equal
(
self
):
def
test_less_equal
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
b_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -296,12 +210,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
<=
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
<=
b_np
)
def
test_less_equal
(
self
):
with
_test_eager_guard
():
self
.
func_test_less_equal
()
self
.
func_test_less_equal
()
def
func_test_greater_than
(
self
):
def
test_greater_than
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
b_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -310,12 +219,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
>
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
>
b_np
)
def
test_greater_than
(
self
):
with
_test_eager_guard
():
self
.
func_test_greater_than
()
self
.
func_test_greater_than
()
def
func_test_greater_equal
(
self
):
def
test_greater_equal
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
b_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -324,47 +228,27 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
>=
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
>=
b_np
)
def
test_greater_equal
(
self
):
with
_test_eager_guard
():
self
.
func_test_greater_equal
()
self
.
func_test_greater_equal
()
def
func_test_neg
(
self
):
def
test_neg
(
self
):
a_np
=
np
.
random
.
uniform
(
-
1
,
1
,
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
res
=
-
a
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
-
a_np
)
def
test_neg
(
self
):
with
_test_eager_guard
():
self
.
func_test_neg
()
self
.
func_test_neg
()
def
func_test_float_int_long
(
self
):
def
test_float_int_long
(
self
):
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
np
.
array
([
100.1
]))
self
.
assertTrue
(
float
(
a
)
==
100.1
)
self
.
assertTrue
(
int
(
a
)
==
100
)
self
.
assertTrue
(
int
(
a
)
==
100
)
def
test_float_int_long
(
self
):
with
_test_eager_guard
():
self
.
func_test_float_int_long
()
self
.
func_test_float_int_long
()
def
func_test_len
(
self
):
def
test_len
(
self
):
a_np
=
np
.
random
.
uniform
(
-
1
,
1
,
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
self
.
assertTrue
(
len
(
a
)
==
10
)
def
test_len
(
self
):
with
_test_eager_guard
():
self
.
func_test_len
()
self
.
func_test_len
()
def
func_test_index
(
self
):
def
test_index
(
self
):
with
fluid
.
dygraph
.
guard
():
var1
=
fluid
.
dygraph
.
to_variable
(
np
.
array
([
2
]))
i_tmp
=
0
...
...
@@ -376,12 +260,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
str1
=
"just test"
self
.
assertTrue
(
str1
[
var1
]
==
's'
)
def
test_index
(
self
):
with
_test_eager_guard
():
self
.
func_test_index
()
self
.
func_test_index
()
def
func_test_np_left_mul
(
self
):
def
test_np_left_mul
(
self
):
with
fluid
.
dygraph
.
guard
():
t
=
np
.
sqrt
(
2.0
*
np
.
pi
)
x
=
paddle
.
ones
((
2
,
2
),
dtype
=
"float32"
)
...
...
@@ -394,12 +273,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
atol
=
0.0
,
)
def
test_np_left_mul
(
self
):
with
_test_eager_guard
():
self
.
func_test_np_left_mul
()
self
.
func_test_np_left_mul
()
def
func_test_add_different_dtype
(
self
):
def
test_add_different_dtype
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
np
.
float32
)
b_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
np
.
float16
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -408,12 +282,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
+
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
+
b_np
)
def
test_add_different_dtype
(
self
):
with
_test_eager_guard
():
self
.
func_test_add_different_dtype
()
self
.
func_test_add_different_dtype
()
def
func_test_floordiv_different_dtype
(
self
):
def
test_floordiv_different_dtype
(
self
):
a_np
=
np
.
full
(
self
.
shape
,
10
,
np
.
int64
)
b_np
=
np
.
full
(
self
.
shape
,
2
,
np
.
int32
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -422,12 +291,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
res
=
a
//
b
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
a_np
//
b_np
)
def
test_floordiv_different_dtype
(
self
):
with
_test_eager_guard
():
self
.
func_test_floordiv_different_dtype
()
self
.
func_test_floordiv_different_dtype
()
def
func_test_astype
(
self
):
def
test_astype
(
self
):
a_np
=
np
.
random
.
uniform
(
-
1
,
1
,
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
...
...
@@ -441,12 +305,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
np
.
testing
.
assert_array_equal
(
res1
.
numpy
(),
res2
.
numpy
())
np
.
testing
.
assert_array_equal
(
res1
.
numpy
(),
res3
.
numpy
())
def
test_astype
(
self
):
with
_test_eager_guard
():
self
.
func_test_astype
()
self
.
func_test_astype
()
def
func_test_conpare_op_broadcast
(
self
):
def
test_conpare_op_broadcast
(
self
):
a_np
=
np
.
random
.
uniform
(
-
1
,
1
,
[
10
,
1
,
10
]).
astype
(
self
.
dtype
)
b_np
=
np
.
random
.
uniform
(
-
1
,
1
,
[
1
,
1
,
10
]).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
...
...
@@ -456,12 +315,7 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
self
.
assertEqual
((
a
!=
b
).
dtype
,
fluid
.
core
.
VarDesc
.
VarType
.
BOOL
)
np
.
testing
.
assert_array_equal
((
a
!=
b
).
numpy
(),
a_np
!=
b_np
)
def
test_conpare_op_broadcast
(
self
):
with
_test_eager_guard
():
self
.
func_test_conpare_op_broadcast
()
self
.
func_test_conpare_op_broadcast
()
def
func_test_tensor_patch_method
(
self
):
def
test_tensor_patch_method
(
self
):
paddle
.
disable_static
()
x_np
=
np
.
random
.
uniform
(
-
1
,
1
,
[
2
,
3
]).
astype
(
self
.
dtype
)
y_np
=
np
.
random
.
uniform
(
-
1
,
1
,
[
2
,
3
]).
astype
(
self
.
dtype
)
...
...
@@ -740,24 +594,14 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
self
.
assertTrue
(
inspect
.
ismethod
(
a
.
std
))
self
.
assertTrue
(
inspect
.
ismethod
(
a
.
numel
))
def
test_tensor_patch_method
(
self
):
with
_test_eager_guard
():
self
.
func_test_tensor_patch_method
()
self
.
func_test_tensor_patch_method
()
def
func_test_complex_scalar
(
self
):
def
test_complex_scalar
(
self
):
a_np
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
with
fluid
.
dygraph
.
guard
():
a
=
fluid
.
dygraph
.
to_variable
(
a_np
)
res
=
1j
*
a
np
.
testing
.
assert_array_equal
(
res
.
numpy
(),
1j
*
a_np
)
def
test_complex_scalar
(
self
):
with
_test_eager_guard
():
self
.
func_test_complex_scalar
()
self
.
func_test_complex_scalar
()
def
func_test_matmul
(
self
):
def
test_matmul
(
self
):
x_np
=
np
.
random
.
uniform
(
-
1
,
1
,
[
2
,
3
]).
astype
(
self
.
dtype
)
y_np
=
np
.
random
.
uniform
(
-
1
,
1
,
[
3
,
2
]).
astype
(
self
.
dtype
)
except_out
=
x_np
@
y_np
...
...
@@ -768,11 +612,6 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
out
=
x
@
y
np
.
testing
.
assert_allclose
(
out
.
numpy
(),
except_out
,
atol
=
1e-03
)
def
test_matmul
(
self
):
with
_test_eager_guard
():
self
.
func_test_matmul
()
self
.
func_test_matmul
()
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/xpu/test_diag_v2_op_xpu.py
浏览文件 @
cb34ee0f
...
...
@@ -28,7 +28,6 @@ from xpu.get_test_cover_info import (
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid
import
Program
,
program_guard
from
paddle.fluid.framework
import
_test_eager_guard
paddle
.
enable_static
()
...
...
@@ -305,8 +304,6 @@ class XPUTestDiagV2Op(XPUOpTestWrapper):
def
test_xpu
(
self
):
paddle
.
disable_static
(
place
=
paddle
.
fluid
.
XPUPlace
(
0
))
self
.
run_imperative
()
with
_test_eager_guard
():
self
.
run_imperative
()
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/unittests/xpu/test_set_value_op_xpu.py
浏览文件 @
cb34ee0f
...
...
@@ -28,7 +28,6 @@ from xpu.get_test_cover_info import (
)
import
paddle
from
paddle.fluid.framework
import
_test_eager_guard
class
XPUTestSetValueOp
(
XPUOpTestWrapper
):
...
...
@@ -66,7 +65,7 @@ class XPUTestSetValueOp(XPUOpTestWrapper):
paddle
.
disable_static
()
return
out
def
func_
test_api
(
self
):
def
test_api
(
self
):
static_out
=
self
.
_run_static
()
self
.
_get_answer
()
...
...
@@ -78,11 +77,6 @@ class XPUTestSetValueOp(XPUOpTestWrapper):
msg
=
error_msg
.
format
(
"static"
,
self
.
data
,
static_out
),
)
def
test_api
(
self
):
with
_test_eager_guard
():
self
.
func_test_api
()
self
.
func_test_api
()
support_types
=
get_xpu_op_support_types
(
'set_value'
)
for
stype
in
support_types
:
...
...
python/paddle/tests/test_callback_wandb.py
浏览文件 @
cb34ee0f
...
...
@@ -17,7 +17,6 @@ import unittest
import
paddle
import
paddle.vision.transforms
as
T
from
paddle.fluid.framework
import
_test_eager_guard
from
paddle.static
import
InputSpec
from
paddle.vision.datasets
import
MNIST
...
...
@@ -31,7 +30,7 @@ class TestWandbCallbacks(unittest.TestCase):
def
setUp
(
self
):
self
.
save_dir
=
tempfile
.
mkdtemp
()
def
func
_wandb_callback
(
self
):
def
test
_wandb_callback
(
self
):
inputs
=
[
InputSpec
([
-
1
,
1
,
28
,
28
],
'float32'
,
'image'
)]
labels
=
[
InputSpec
([
None
,
1
],
'int64'
,
'label'
)]
...
...
@@ -59,11 +58,6 @@ class TestWandbCallbacks(unittest.TestCase):
train_dataset
,
eval_dataset
,
batch_size
=
64
,
callbacks
=
callback
)
def
test_wandb_callback
(
self
):
with
_test_eager_guard
():
self
.
func_wandb_callback
()
self
.
func_wandb_callback
()
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录