Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
29c211ee
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
29c211ee
编写于
1月 11, 2022
作者:
W
Weilong Wu
提交者:
GitHub
1月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support test_numpy_bridge and thread_local_has_grad (#38835)
上级
d3ba1895
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
3 deletion
+19
-3
python/paddle/fluid/tests/unittests/test_imperative_numpy_bridge.py
...dle/fluid/tests/unittests/test_imperative_numpy_bridge.py
+12
-2
python/paddle/fluid/tests/unittests/test_imperative_thread_local_has_grad.py
.../tests/unittests/test_imperative_thread_local_has_grad.py
+7
-1
未找到文件。
python/paddle/fluid/tests/unittests/test_imperative_numpy_bridge.py
浏览文件 @
29c211ee
...
...
@@ -16,10 +16,11 @@ import unittest
import
numpy
as
np
import
paddle.fluid
as
fluid
import
warnings
from
paddle.fluid.framework
import
_test_eager_guard
,
_in_eager_mode
class
TestImperativeNumpyBridge
(
unittest
.
TestCase
):
def
test
_tensor_from_numpy
(
self
):
def
func
_tensor_from_numpy
(
self
):
data_np
=
np
.
array
([[
2
,
3
,
1
]]).
astype
(
'float32'
)
with
fluid
.
dygraph
.
guard
(
fluid
.
CPUPlace
()):
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
...
...
@@ -39,9 +40,18 @@ class TestImperativeNumpyBridge(unittest.TestCase):
self
.
assertTrue
(
np
.
array_equal
(
var2
.
numpy
(),
data_np
))
data_np
[
0
][
0
]
=
-
1
self
.
assertEqual
(
data_np
[
0
][
0
],
-
1
)
self
.
assertNotEqual
(
var2
[
0
][
0
].
numpy
()[
0
],
-
1
)
if
_in_eager_mode
():
# eager_mode, var2 is EagerTensor, is not subscriptable
self
.
assertNotEqual
(
var2
.
numpy
()[
0
][
0
],
-
1
)
else
:
self
.
assertNotEqual
(
var2
[
0
][
0
].
numpy
()[
0
],
-
1
)
self
.
assertFalse
(
np
.
array_equal
(
var2
.
numpy
(),
data_np
))
def
test_func_tensor_from_numpy
(
self
):
with
_test_eager_guard
():
self
.
func_tensor_from_numpy
()
self
.
func_tensor_from_numpy
()
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_imperative_thread_local_has_grad.py
浏览文件 @
29c211ee
...
...
@@ -18,6 +18,7 @@ import time
import
paddle.nn
as
nn
import
numpy
as
np
import
threading
from
paddle.fluid.framework
import
_test_eager_guard
,
_in_eager_mode
class
SimpleNet
(
nn
.
Layer
):
...
...
@@ -44,7 +45,7 @@ class TestCases(unittest.TestCase):
x
=
net
(
x
)
self
.
assertFalse
(
x
.
stop_gradient
)
def
test
_main
(
self
):
def
func
_main
(
self
):
threads
=
[]
for
_
in
range
(
10
):
threads
.
append
(
threading
.
Thread
(
target
=
self
.
thread_1_main
))
...
...
@@ -54,6 +55,11 @@ class TestCases(unittest.TestCase):
for
t
in
threads
:
t
.
join
()
def
test_main
(
self
):
with
_test_eager_guard
():
self
.
func_main
()
self
.
func_main
()
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录