Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76559479
Paddle
提交
2a3ddce0
P
Paddle
项目概览
2301_76559479
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2a3ddce0
编写于
12月 05, 2022
作者:
W
Weilong Wu
提交者:
GitHub
12月 05, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rm _enable_legacy_dygraph (#48677)
* rm _enable_legacy * recover original code
上级
aee2db01
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
24 addition
and
146 deletion
+24
-146
python/paddle/fluid/tests/unittests/test_linalg_lstsq_op.py
python/paddle/fluid/tests/unittests/test_linalg_lstsq_op.py
+0
-21
python/paddle/fluid/tests/unittests/test_pairwise_distance.py
...on/paddle/fluid/tests/unittests/test_pairwise_distance.py
+1
-85
python/paddle/fluid/tests/unittests/test_slice_op.py
python/paddle/fluid/tests/unittests/test_slice_op.py
+23
-26
python/paddle/fluid/tests/unittests/test_tensor_fill_diagonal_tensor.py
...fluid/tests/unittests/test_tensor_fill_diagonal_tensor.py
+0
-5
python/paddle/fluid/tests/unittests/test_uniform_random_inplace_op.py
...e/fluid/tests/unittests/test_uniform_random_inplace_op.py
+0
-9
未找到文件。
python/paddle/fluid/tests/unittests/test_linalg_lstsq_op.py
浏览文件 @
2a3ddce0
...
...
@@ -92,27 +92,6 @@ class LinalgLstsqTestCase(unittest.TestCase):
self
.
_result_sg_values
=
results
[
3
].
numpy
()
self
.
assert_np_close
()
def
test_legacy_dygraph
(
self
):
paddle
.
disable_static
()
paddle
.
fluid
.
framework
.
_enable_legacy_dygraph
()
for
dev
in
self
.
devices
:
paddle
.
set_device
(
dev
)
place
=
paddle
.
CPUPlace
()
if
dev
==
"cpu"
else
paddle
.
CUDAPlace
(
0
)
x
=
paddle
.
to_tensor
(
self
.
_input_data_1
,
place
=
place
,
dtype
=
self
.
dtype
)
y
=
paddle
.
to_tensor
(
self
.
_input_data_2
,
place
=
place
,
dtype
=
self
.
dtype
)
results
=
paddle
.
linalg
.
lstsq
(
x
,
y
,
rcond
=
self
.
rcond
,
driver
=
self
.
driver
)
self
.
_result_solution
=
results
[
0
].
numpy
()
self
.
_result_residuals
=
results
[
1
].
numpy
()
self
.
_result_rank
=
results
[
2
].
numpy
()
self
.
_result_sg_values
=
results
[
3
].
numpy
()
self
.
assert_np_close
()
def
test_static
(
self
):
paddle
.
enable_static
()
for
dev
in
self
.
devices
:
...
...
python/paddle/fluid/tests/unittests/test_pairwise_distance.py
浏览文件 @
2a3ddce0
...
...
@@ -95,25 +95,6 @@ def test_dygraph(
return
dygraph_ret
def
test_legacy_dygraph
(
place
,
x_np
,
y_np
,
p
=
2.0
,
epsilon
=
1e-6
,
keepdim
=
False
,
functional
=
False
):
paddle
.
fluid
.
framework
.
_enable_legacy_dygraph
()
x
=
paddle
.
to_tensor
(
x_np
)
y
=
paddle
.
to_tensor
(
y_np
)
if
functional
:
legacy_distance
=
call_pairwise_distance_functional
(
x
=
x
,
y
=
y
,
p
=
p
,
epsilon
=
epsilon
,
keepdim
=
keepdim
)
else
:
legacy_distance
=
call_pairwise_distance_layer
(
x
=
x
,
y
=
y
,
p
=
p
,
epsilon
=
epsilon
,
keepdim
=
keepdim
)
legacy_ret
=
legacy_distance
.
numpy
()
paddle
.
fluid
.
framework
.
_disable_legacy_dygraph
()
return
legacy_ret
class
TestPairwiseDistance
(
unittest
.
TestCase
):
def
test_pairwise_distance
(
self
):
epsilon
=
1e-6
...
...
@@ -148,14 +129,6 @@ class TestPairwiseDistance(unittest.TestCase):
epsilon
=
epsilon
,
keepdim
=
keepdim
,
)
legacy_ret
=
test_legacy_dygraph
(
place
,
x_np
,
y_np
,
p
,
epsilon
=
epsilon
,
keepdim
=
keepdim
,
)
excepted_value
=
np_pairwise_distance
(
x_np
,
y_np
,
p
,
epsilon
=
epsilon
,
keepdim
=
keepdim
)
...
...
@@ -166,9 +139,6 @@ class TestPairwiseDistance(unittest.TestCase):
self
.
assertEqual
(
dygraph_ret
.
shape
,
excepted_value
.
shape
)
self
.
assertEqual
(
legacy_ret
.
shape
,
excepted_value
.
shape
)
np
.
testing
.
assert_allclose
(
static_ret
,
excepted_value
,
rtol
=
1e-05
...
...
@@ -176,10 +146,6 @@ class TestPairwiseDistance(unittest.TestCase):
np
.
testing
.
assert_allclose
(
dygraph_ret
,
excepted_value
,
rtol
=
1e-05
)
np
.
testing
.
assert_allclose
(
legacy_ret
,
excepted_value
,
rtol
=
1e-05
)
static_functional_ret
=
test_static
(
place
,
x_np
,
...
...
@@ -196,14 +162,6 @@ class TestPairwiseDistance(unittest.TestCase):
epsilon
=
epsilon
,
keepdim
=
keepdim
,
)
legacy_functional_ret
=
test_legacy_dygraph
(
place
,
x_np
,
y_np
,
p
,
epsilon
=
epsilon
,
keepdim
=
keepdim
,
)
self
.
assertEqual
(
static_functional_ret
.
shape
,
...
...
@@ -213,10 +171,6 @@ class TestPairwiseDistance(unittest.TestCase):
dygraph_functional_ret
.
shape
,
excepted_value
.
shape
,
)
self
.
assertEqual
(
legacy_functional_ret
.
shape
,
excepted_value
.
shape
,
)
np
.
testing
.
assert_allclose
(
static_functional_ret
,
...
...
@@ -228,11 +182,6 @@ class TestPairwiseDistance(unittest.TestCase):
excepted_value
,
rtol
=
1e-05
,
)
np
.
testing
.
assert_allclose
(
legacy_functional_ret
,
excepted_value
,
rtol
=
1e-05
,
)
def
test_pairwise_distance_broadcast_1
(
self
):
shape_x
=
[
100
,
100
]
...
...
@@ -248,20 +197,15 @@ class TestPairwiseDistance(unittest.TestCase):
dygraph_ret
=
test_dygraph
(
place
=
place
,
x_np
=
x_np
,
y_np
=
y_np
,
epsilon
=
epsilon
,
keepdim
=
keepdim
)
legacy_ret
=
test_legacy_dygraph
(
place
=
place
,
x_np
=
x_np
,
y_np
=
y_np
,
epsilon
=
epsilon
,
keepdim
=
keepdim
)
excepted_value
=
np_pairwise_distance
(
x_np
,
y_np
,
epsilon
=
epsilon
,
keepdim
=
keepdim
)
self
.
assertEqual
(
static_ret
.
shape
,
excepted_value
.
shape
)
self
.
assertEqual
(
dygraph_ret
.
shape
,
excepted_value
.
shape
)
self
.
assertEqual
(
legacy_ret
.
shape
,
excepted_value
.
shape
)
np
.
testing
.
assert_allclose
(
static_ret
,
excepted_value
,
rtol
=
1e-05
)
np
.
testing
.
assert_allclose
(
dygraph_ret
,
excepted_value
,
rtol
=
1e-05
)
np
.
testing
.
assert_allclose
(
legacy_ret
,
excepted_value
,
rtol
=
1e-05
)
static_functional_ret
=
test_static
(
place
=
place
,
...
...
@@ -279,18 +223,9 @@ class TestPairwiseDistance(unittest.TestCase):
keepdim
=
keepdim
,
functional
=
True
,
)
legacy_functional_ret
=
test_legacy_dygraph
(
place
=
place
,
x_np
=
x_np
,
y_np
=
y_np
,
epsilon
=
epsilon
,
keepdim
=
keepdim
,
functional
=
True
,
)
self
.
assertEqual
(
static_functional_ret
.
shape
,
excepted_value
.
shape
)
self
.
assertEqual
(
dygraph_functional_ret
.
shape
,
excepted_value
.
shape
)
self
.
assertEqual
(
legacy_functional_ret
.
shape
,
excepted_value
.
shape
)
np
.
testing
.
assert_allclose
(
static_functional_ret
,
excepted_value
,
rtol
=
1e-05
...
...
@@ -298,9 +233,6 @@ class TestPairwiseDistance(unittest.TestCase):
np
.
testing
.
assert_allclose
(
dygraph_functional_ret
,
excepted_value
,
rtol
=
1e-05
)
np
.
testing
.
assert_allclose
(
legacy_functional_ret
,
excepted_value
,
rtol
=
1e-05
)
def
test_pairwise_distance_broadcast_2
(
self
):
shape_x
=
[
100
,
100
]
...
...
@@ -316,20 +248,16 @@ class TestPairwiseDistance(unittest.TestCase):
dygraph_ret
=
test_dygraph
(
place
=
place
,
x_np
=
x_np
,
y_np
=
y_np
,
epsilon
=
epsilon
,
keepdim
=
keepdim
)
legacy_ret
=
test_legacy_dygraph
(
place
=
place
,
x_np
=
x_np
,
y_np
=
y_np
,
epsilon
=
epsilon
,
keepdim
=
keepdim
)
excepted_value
=
np_pairwise_distance
(
x_np
,
y_np
,
epsilon
=
epsilon
,
keepdim
=
keepdim
)
self
.
assertEqual
(
static_ret
.
shape
,
excepted_value
.
shape
)
self
.
assertEqual
(
dygraph_ret
.
shape
,
excepted_value
.
shape
)
self
.
assertEqual
(
legacy_ret
.
shape
,
excepted_value
.
shape
)
np
.
testing
.
assert_allclose
(
static_ret
,
excepted_value
,
rtol
=
1e-05
)
np
.
testing
.
assert_allclose
(
dygraph_ret
,
excepted_value
,
rtol
=
1e-05
)
np
.
testing
.
assert_allclose
(
legacy_ret
,
excepted_value
,
rtol
=
1e-05
)
static_functional_ret
=
test_static
(
place
=
place
,
...
...
@@ -347,18 +275,9 @@ class TestPairwiseDistance(unittest.TestCase):
keepdim
=
keepdim
,
functional
=
True
,
)
legacy_functional_ret
=
test_legacy_dygraph
(
place
=
place
,
x_np
=
x_np
,
y_np
=
y_np
,
epsilon
=
epsilon
,
keepdim
=
keepdim
,
functional
=
True
,
)
self
.
assertEqual
(
static_functional_ret
.
shape
,
excepted_value
.
shape
)
self
.
assertEqual
(
dygraph_functional_ret
.
shape
,
excepted_value
.
shape
)
self
.
assertEqual
(
legacy_functional_ret
.
shape
,
excepted_value
.
shape
)
np
.
testing
.
assert_allclose
(
static_functional_ret
,
excepted_value
,
rtol
=
1e-05
...
...
@@ -366,9 +285,6 @@ class TestPairwiseDistance(unittest.TestCase):
np
.
testing
.
assert_allclose
(
dygraph_functional_ret
,
excepted_value
,
rtol
=
1e-05
)
np
.
testing
.
assert_allclose
(
legacy_functional_ret
,
excepted_value
,
rtol
=
1e-05
)
if
__name__
==
"__main__"
:
...
...
python/paddle/fluid/tests/unittests/test_slice_op.py
浏览文件 @
2a3ddce0
...
...
@@ -23,7 +23,6 @@ import paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
import
paddle.fluid.layers
as
layers
from
paddle.fluid.framework
import
_enable_legacy_dygraph
,
_test_eager_guard
paddle
.
enable_static
()
...
...
@@ -640,29 +639,28 @@ class TestSliceApiWithTensor(unittest.TestCase):
class
TestSliceApiEager
(
unittest
.
TestCase
):
def
test_slice_api
(
self
):
with
paddle
.
fluid
.
dygraph
.
guard
():
with
_test_eager_guard
():
a
=
paddle
.
rand
(
shape
=
[
4
,
5
,
6
],
dtype
=
'float32'
)
a
.
stop_gradient
=
False
axes
=
[
0
,
1
,
2
]
starts
=
[
-
3
,
0
,
2
]
ends
=
[
3
,
2
,
4
]
a_1
=
paddle
.
slice
(
a
,
axes
=
axes
,
starts
=
starts
,
ends
=
ends
)
a_2
=
paddle
.
slice
(
a
,
axes
=
axes
,
starts
=
paddle
.
to_tensor
(
starts
),
ends
=
paddle
.
to_tensor
(
ends
),
)
np
.
testing
.
assert_array_equal
(
a_1
.
numpy
(),
a_2
.
numpy
())
a_1
.
backward
()
grad_truth
=
paddle
.
zeros_like
(
a
)
grad_truth
[
-
3
:
3
,
0
:
2
,
2
:
4
]
=
1
np
.
testing
.
assert_array_equal
(
grad_truth
,
a
.
gradient
())
np
.
testing
.
assert_allclose
(
a_1
.
numpy
(),
a
[
-
3
:
3
,
0
:
2
,
2
:
4
],
rtol
=
1e-05
)
a
=
paddle
.
rand
(
shape
=
[
4
,
5
,
6
],
dtype
=
'float32'
)
a
.
stop_gradient
=
False
axes
=
[
0
,
1
,
2
]
starts
=
[
-
3
,
0
,
2
]
ends
=
[
3
,
2
,
4
]
a_1
=
paddle
.
slice
(
a
,
axes
=
axes
,
starts
=
starts
,
ends
=
ends
)
a_2
=
paddle
.
slice
(
a
,
axes
=
axes
,
starts
=
paddle
.
to_tensor
(
starts
),
ends
=
paddle
.
to_tensor
(
ends
),
)
np
.
testing
.
assert_array_equal
(
a_1
.
numpy
(),
a_2
.
numpy
())
a_1
.
backward
()
grad_truth
=
paddle
.
zeros_like
(
a
)
grad_truth
[
-
3
:
3
,
0
:
2
,
2
:
4
]
=
1
np
.
testing
.
assert_array_equal
(
grad_truth
,
a
.
gradient
())
np
.
testing
.
assert_allclose
(
a_1
.
numpy
(),
a
[
-
3
:
3
,
0
:
2
,
2
:
4
],
rtol
=
1e-05
)
class
TestSliceApiWithLoDTensorArray
(
unittest
.
TestCase
):
...
...
@@ -861,10 +859,9 @@ class TestInferShape(unittest.TestCase):
)
class
TestImperativeCUDAPinnedInput
(
unittest
.
TestCase
):
def
test_input_cuda_pinned_var
(
self
):
_enable_legacy_dygraph
()
with
fluid
.
dygraph
.
guard
():
data
=
np
.
random
.
random
((
2
,
80
,
16128
)).
astype
(
'float32'
)
var
=
core
.
VarBase
(
var
=
core
.
eager
.
Tensor
(
value
=
data
,
name
=
''
,
persistable
=
False
,
...
...
python/paddle/fluid/tests/unittests/test_tensor_fill_diagonal_tensor.py
浏览文件 @
2a3ddce0
...
...
@@ -19,7 +19,6 @@ import numpy as np
import
paddle
import
paddle.fluid
as
fluid
import
paddle.nn.functional
as
F
from
paddle.fluid.framework
import
_enable_legacy_dygraph
class
TensorFillDiagTensor_Test
(
unittest
.
TestCase
):
...
...
@@ -216,9 +215,5 @@ class TensorFillDiagTensor_Test(unittest.TestCase):
fluid
.
set_flags
({
"FLAGS_retain_grad_for_all_tensor"
:
False
})
class
TensorFillDiagTensor_Test_legacy
(
TensorFillDiagTensor_Test
):
_enable_legacy_dygraph
()
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_uniform_random_inplace_op.py
浏览文件 @
2a3ddce0
...
...
@@ -18,10 +18,6 @@ import numpy as np
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.framework
import
(
_disable_legacy_dygraph
,
_enable_legacy_dygraph
,
)
class
TestUniformRandomInplaceOpDtype
(
unittest
.
TestCase
):
...
...
@@ -188,11 +184,6 @@ class TestUniformRandomInplaceGrad(unittest.TestCase):
def
test_uniform_random_inplace_grad
(
self
):
self
.
run_
()
def
test_uniform_random_inplace_grad_old_dygraph
(
self
):
_enable_legacy_dygraph
()
self
.
run_
()
_disable_legacy_dygraph
()
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录