Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a7014f09
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,发现更多精彩内容 >>
未验证
提交
a7014f09
编写于
12月 12, 2022
作者:
姜
姜永久
提交者:
GitHub
12月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rm unittests eager guard tests part6 eager_run2expand_v2 (#48817)
上级
08524758
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
165 addition
and
241 deletion
+165
-241
python/paddle/fluid/tests/unittests/test_eager_run_program.py
...on/paddle/fluid/tests/unittests/test_eager_run_program.py
+48
-63
python/paddle/fluid/tests/unittests/test_eager_trace_op.py
python/paddle/fluid/tests/unittests/test_eager_trace_op.py
+17
-19
python/paddle/fluid/tests/unittests/test_egr_code_generate_api.py
...addle/fluid/tests/unittests/test_egr_code_generate_api.py
+33
-38
python/paddle/fluid/tests/unittests/test_egr_string_tensor_api.py
...addle/fluid/tests/unittests/test_egr_string_tensor_api.py
+61
-70
python/paddle/fluid/tests/unittests/test_elementwise_add_op.py
...n/paddle/fluid/tests/unittests/test_elementwise_add_op.py
+2
-12
python/paddle/fluid/tests/unittests/test_elementwise_div_op.py
...n/paddle/fluid/tests/unittests/test_elementwise_div_op.py
+1
-6
python/paddle/fluid/tests/unittests/test_elementwise_mul_op.py
...n/paddle/fluid/tests/unittests/test_elementwise_mul_op.py
+1
-6
python/paddle/fluid/tests/unittests/test_elementwise_sub_op.py
...n/paddle/fluid/tests/unittests/test_elementwise_sub_op.py
+2
-12
python/paddle/fluid/tests/unittests/test_expand_v2_op.py
python/paddle/fluid/tests/unittests/test_expand_v2_op.py
+0
-15
未找到文件。
python/paddle/fluid/tests/unittests/test_eager_run_program.py
浏览文件 @
a7014f09
...
...
@@ -24,11 +24,7 @@ from paddle.fluid.executor import (
_is_dy2st_enable_standalone_executor
,
_is_enable_standalone_executor
,
)
from
paddle.fluid.framework
import
(
Variable
,
_in_legacy_dygraph
,
_test_eager_guard
,
)
from
paddle.fluid.framework
import
Variable
,
_in_legacy_dygraph
from
paddle.fluid.layers.utils
import
_hash_with_id
...
...
@@ -124,7 +120,6 @@ class TestRunProgram(unittest.TestCase):
paddle
.
disable_static
(
'cpu'
)
# step 2: call run_program in eager mode
with
_test_eager_guard
():
x_t
=
paddle
.
ones
([
2
,
4
])
x_t
.
name
=
"x"
x_t
.
stop_gradient
=
False
...
...
@@ -167,25 +162,15 @@ class TestRunProgram(unittest.TestCase):
)
_legacy_C_ops
.
run_program
(
[
x_t
,
y_t
],
[
fake_var
],
[
out_t
],
[
scope
],
[
fake_var
],
None
,
*
attrs
[
x_t
,
y_t
],
[
fake_var
],
[
out_t
],
[
scope
],
[
fake_var
],
None
,
*
attrs
)
loss
=
paddle
.
mean
(
out_t
)
loss
.
backward
()
np
.
testing
.
assert_array_equal
(
np
.
ones
([
2
,
2
])
*
4
,
out_t
.
numpy
())
np
.
testing
.
assert_array_equal
(
np
.
ones
([
2
,
4
])
*
0.5
,
x_t
.
grad
.
numpy
()
)
np
.
testing
.
assert_array_equal
(
np
.
ones
([
4
,
2
])
*
0.5
,
y_t
.
grad
.
numpy
()
)
np
.
testing
.
assert_array_equal
(
np
.
ones
([
2
,
4
])
*
0.5
,
x_t
.
grad
.
numpy
())
np
.
testing
.
assert_array_equal
(
np
.
ones
([
4
,
2
])
*
0.5
,
y_t
.
grad
.
numpy
())
if
__name__
==
'__main__'
:
...
...
python/paddle/fluid/tests/unittests/test_eager_trace_op.py
浏览文件 @
a7014f09
...
...
@@ -17,12 +17,10 @@ import unittest
import
numpy
as
np
import
paddle
from
paddle.fluid.framework
import
_test_eager_guard
class
TestEagerTraceOp
(
unittest
.
TestCase
):
def
test_branches
(
self
):
with
_test_eager_guard
():
data
=
np
.
random
.
random
([
1
,
1
]).
astype
(
np
.
float32
)
x
=
paddle
.
to_tensor
(
data
)
...
...
python/paddle/fluid/tests/unittests/test_egr_code_generate_api.py
浏览文件 @
a7014f09
...
...
@@ -17,12 +17,10 @@ import unittest
import
numpy
as
np
import
paddle
from
paddle.fluid.framework
import
_test_eager_guard
class
EagerOpAPIGenerateTestCase
(
unittest
.
TestCase
):
def
test_elementwise_add
(
self
):
with
_test_eager_guard
():
paddle
.
set_device
(
"cpu"
)
np_x
=
np
.
ones
([
4
,
16
,
16
,
32
]).
astype
(
'float32'
)
np_y
=
np
.
ones
([
4
,
16
,
16
,
32
]).
astype
(
'float32'
)
...
...
@@ -35,10 +33,9 @@ class EagerOpAPIGenerateTestCase(unittest.TestCase):
np
.
testing
.
assert_array_equal
(
out_arr
,
out_arr_expected
)
def
test_sum
(
self
):
with
_test_eager_guard
():
x_data
=
np
.
array
(
[[
0.2
,
0.3
,
0.5
,
0.9
],
[
0.1
,
0.2
,
0.6
,
0.7
]]
).
astype
(
'float32'
)
x_data
=
np
.
array
([[
0.2
,
0.3
,
0.5
,
0.9
],
[
0.1
,
0.2
,
0.6
,
0.7
]]).
astype
(
'float32'
)
x
=
paddle
.
to_tensor
(
x_data
,
'float32'
)
out
=
paddle
.
sum
(
x
,
axis
=
0
)
out_arr
=
out
.
numpy
()
...
...
@@ -46,7 +43,6 @@ class EagerOpAPIGenerateTestCase(unittest.TestCase):
np
.
testing
.
assert_array_equal
(
out_arr
,
out_arr_expected
)
def
test_mm
(
self
):
with
_test_eager_guard
():
np_input
=
np
.
random
.
random
([
16
,
32
]).
astype
(
'float32'
)
np_mat2
=
np
.
random
.
random
([
32
,
32
]).
astype
(
'float32'
)
input
=
paddle
.
to_tensor
(
np_input
)
...
...
@@ -57,7 +53,6 @@ class EagerOpAPIGenerateTestCase(unittest.TestCase):
np
.
testing
.
assert_allclose
(
out_arr
,
out_arr_expected
,
rtol
=
1e-05
)
def
test_sigmoid
(
self
):
with
_test_eager_guard
():
np_x
=
np
.
array
([
-
0.4
,
-
0.2
,
0.1
,
0.3
]).
astype
(
'float32'
)
x
=
paddle
.
to_tensor
(
np_x
)
out
=
paddle
.
nn
.
functional
.
sigmoid
(
x
)
...
...
python/paddle/fluid/tests/unittests/test_egr_string_tensor_api.py
浏览文件 @
a7014f09
...
...
@@ -17,7 +17,6 @@ import unittest
import
numpy
as
np
import
paddle.fluid.core
as
core
from
paddle.fluid.framework
import
_test_eager_guard
class
EagerStringTensorTestCase
(
unittest
.
TestCase
):
...
...
@@ -32,7 +31,6 @@ class EagerStringTensorTestCase(unittest.TestCase):
)
# From IMDB
def
test_constructor_with_args
(
self
):
with
_test_eager_guard
():
ST1
=
core
.
eager
.
StringTensor
()
# constructor 1
self
.
assertEqual
(
ST1
.
name
,
"generated_string_tensor_0"
)
self
.
assertEqual
(
ST1
.
shape
,
[])
...
...
@@ -71,20 +69,15 @@ class EagerStringTensorTestCase(unittest.TestCase):
self
.
assertTrue
(
st
.
place
.
_equals
(
core
.
CPUPlace
()))
def
test_constructor_with_kwargs
(
self
):
with
_test_eager_guard
():
shape
=
[
2
,
3
]
ST1
=
core
.
eager
.
StringTensor
(
dims
=
shape
,
name
=
"ST1"
)
# constructor 2
ST1
=
core
.
eager
.
StringTensor
(
dims
=
shape
,
name
=
"ST1"
)
# constructor 2
self
.
assertEqual
(
ST1
.
name
,
"ST1"
)
self
.
assertEqual
(
ST1
.
shape
,
shape
)
np
.
testing
.
assert_array_equal
(
ST1
.
numpy
(),
np
.
empty
(
shape
,
dtype
=
np
.
unicode_
)
)
ST2
=
core
.
eager
.
StringTensor
(
self
.
str_arr
,
name
=
"ST2"
)
# constructor 3
ST2
=
core
.
eager
.
StringTensor
(
self
.
str_arr
,
name
=
"ST2"
)
# constructor 3
self
.
assertEqual
(
ST2
.
name
,
"ST2"
)
self
.
assertEqual
(
ST2
.
shape
,
list
(
self
.
str_arr
.
shape
))
np
.
testing
.
assert_array_equal
(
ST2
.
numpy
(),
self
.
str_arr
)
...
...
@@ -94,9 +87,7 @@ class EagerStringTensorTestCase(unittest.TestCase):
self
.
assertEqual
(
ST3
.
shape
,
list
(
self
.
str_arr
.
shape
))
np
.
testing
.
assert_array_equal
(
ST3
.
numpy
(),
self
.
str_arr
)
ST4
=
core
.
eager
.
StringTensor
(
value
=
ST2
,
name
=
"ST4"
)
# constructor 6
ST4
=
core
.
eager
.
StringTensor
(
value
=
ST2
,
name
=
"ST4"
)
# constructor 6
self
.
assertEqual
(
ST4
.
name
,
"ST4"
)
self
.
assertEqual
(
ST4
.
shape
,
list
(
self
.
str_arr
.
shape
))
np
.
testing
.
assert_array_equal
(
ST4
.
numpy
(),
self
.
str_arr
)
...
...
python/paddle/fluid/tests/unittests/test_elementwise_add_op.py
浏览文件 @
a7014f09
...
...
@@ -19,7 +19,6 @@ import numpy as np
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
from
paddle.fluid.framework
import
_test_eager_guard
from
paddle.fluid.tests.unittests.op_test
import
(
OpTest
,
convert_float_to_uint16
,
...
...
@@ -684,7 +683,7 @@ class TestBoolAddFloatElementwiseAddop(unittest.TestCase):
self
.
assertTrue
(
c
.
dtype
==
core
.
VarDesc
.
VarType
.
FP32
)
paddle
.
enable_static
()
def
func
_dygraph_add
(
self
):
def
test
_dygraph_add
(
self
):
paddle
.
disable_static
()
a
=
1.5
b
=
paddle
.
full
([
2
],
True
,
dtype
=
'bool'
)
...
...
@@ -715,14 +714,9 @@ class TestBoolAddFloatElementwiseAddop(unittest.TestCase):
paddle
.
enable_static
()
def
test_dygraph_add
(
self
):
with
_test_eager_guard
():
self
.
func_dygraph_add
()
self
.
func_dygraph_add
()
class
TestElementwiseAddop1
(
unittest
.
TestCase
):
def
func
_dygraph_add
(
self
):
def
test
_dygraph_add
(
self
):
paddle
.
disable_static
()
np_a
=
np
.
random
.
random
((
2
,
3
,
4
)).
astype
(
np
.
float32
)
...
...
@@ -742,10 +736,6 @@ class TestElementwiseAddop1(unittest.TestCase):
paddle
.
enable_static
()
def
test_dygraph_add
(
self
):
with
_test_eager_guard
():
self
.
func_dygraph_add
()
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/unittests/test_elementwise_div_op.py
浏览文件 @
a7014f09
...
...
@@ -20,7 +20,6 @@ from op_test import OpTest, convert_float_to_uint16, skip_check_grad_ci
import
paddle
from
paddle
import
fluid
from
paddle.fluid
import
core
from
paddle.fluid.framework
import
_test_eager_guard
class
ElementwiseDivOp
(
OpTest
):
...
...
@@ -440,7 +439,7 @@ class TestRealComplexElementwiseDivOp(TestComplexElementwiseDivOp):
class
TestElementwiseDivop
(
unittest
.
TestCase
):
def
func
_dygraph_div
(
self
):
def
test
_dygraph_div
(
self
):
paddle
.
disable_static
()
np_a
=
np
.
random
.
random
((
2
,
3
,
4
)).
astype
(
np
.
float32
)
...
...
@@ -462,10 +461,6 @@ class TestElementwiseDivop(unittest.TestCase):
paddle
.
enable_static
()
def
test_dygraph_div
(
self
):
with
_test_eager_guard
():
self
.
func_dygraph_div
()
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/unittests/test_elementwise_mul_op.py
浏览文件 @
a7014f09
...
...
@@ -18,7 +18,6 @@ import numpy as np
import
paddle
import
paddle.fluid.core
as
core
from
paddle.fluid.framework
import
_test_eager_guard
from
paddle.fluid.tests.unittests.op_test
import
(
OpTest
,
convert_float_to_uint16
,
...
...
@@ -367,7 +366,7 @@ class TestRealComplexElementwiseMulOp(TestComplexElementwiseMulOp):
class
TestElementwiseMulop
(
unittest
.
TestCase
):
def
func
_dygraph_mul
(
self
):
def
test
_dygraph_mul
(
self
):
paddle
.
disable_static
()
np_a
=
np
.
random
.
random
((
2
,
3
,
4
)).
astype
(
np
.
float32
)
...
...
@@ -387,10 +386,6 @@ class TestElementwiseMulop(unittest.TestCase):
paddle
.
enable_static
()
def
test_dygraph_mul
(
self
):
with
_test_eager_guard
():
self
.
func_dygraph_mul
()
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/unittests/test_elementwise_sub_op.py
浏览文件 @
a7014f09
...
...
@@ -19,7 +19,6 @@ from op_test import OpTest, convert_float_to_uint16, skip_check_grad_ci
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.framework
import
_test_eager_guard
class
TestElementwiseOp
(
OpTest
):
...
...
@@ -414,7 +413,7 @@ class TestSubtractInplaceBroadcastError3(TestSubtractInplaceBroadcastError):
class
TestFloatElementwiseSubop
(
unittest
.
TestCase
):
def
func
_dygraph_sub
(
self
):
def
test
_dygraph_sub
(
self
):
paddle
.
disable_static
()
np_a
=
np
.
random
.
random
((
2
,
3
,
4
)).
astype
(
np
.
float64
)
...
...
@@ -446,14 +445,9 @@ class TestFloatElementwiseSubop(unittest.TestCase):
paddle
.
enable_static
()
def
test_dygraph_sub
(
self
):
with
_test_eager_guard
():
self
.
func_dygraph_sub
()
self
.
func_dygraph_sub
()
class
TestFloatElementwiseSubop1
(
unittest
.
TestCase
):
def
func
_dygraph_sub
(
self
):
def
test
_dygraph_sub
(
self
):
paddle
.
disable_static
()
np_a
=
np
.
random
.
random
((
2
,
3
,
4
)).
astype
(
np
.
float32
)
...
...
@@ -477,10 +471,6 @@ class TestFloatElementwiseSubop1(unittest.TestCase):
paddle
.
enable_static
()
def
test_dygraph_sub
(
self
):
with
_test_eager_guard
():
self
.
func_dygraph_sub
()
if
__name__
==
'__main__'
:
paddle
.
enable_static
()
...
...
python/paddle/fluid/tests/unittests/test_expand_v2_op.py
浏览文件 @
a7014f09
...
...
@@ -23,7 +23,6 @@ import paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.layers
as
layers
from
paddle.fluid
import
Program
,
core
,
program_guard
from
paddle.fluid.framework
import
_test_eager_guard
# Situation 1: shape is a list(without tensor)
...
...
@@ -256,26 +255,12 @@ class TestExpandInferShape(unittest.TestCase):
class
TestExpandV2DygraphAPI
(
unittest
.
TestCase
):
def
test_expand_times_is_tensor
(
self
):
with
paddle
.
fluid
.
dygraph
.
guard
():
with
_test_eager_guard
():
paddle
.
seed
(
1
)
a
=
paddle
.
rand
([
2
,
5
])
egr_expand_1
=
paddle
.
expand
(
a
,
shape
=
[
2
,
5
])
np_array
=
np
.
array
([
2
,
5
])
egr_expand_2
=
paddle
.
expand
(
a
,
shape
=
np_array
)
paddle
.
seed
(
1
)
a
=
paddle
.
rand
([
2
,
5
])
expand_1
=
paddle
.
expand
(
a
,
shape
=
[
2
,
5
])
np_array
=
np
.
array
([
2
,
5
])
expand_2
=
paddle
.
expand
(
a
,
shape
=
np_array
)
np
.
testing
.
assert_array_equal
(
egr_expand_1
.
numpy
(),
egr_expand_2
.
numpy
()
)
np
.
testing
.
assert_array_equal
(
expand_1
.
numpy
(),
expand_2
.
numpy
())
np
.
testing
.
assert_array_equal
(
expand_1
.
numpy
(),
egr_expand_1
.
numpy
()
)
class
TestExpandDoubleGradCheck
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录