Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
3be7e971
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
提交
3be7e971
编写于
3月 15, 2019
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polish
test=develop
上级
50ff8983
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
6 deletion
+60
-6
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+1
-1
python/paddle/fluid/tests/unittests/test_imperative_gnn.py
python/paddle/fluid/tests/unittests/test_imperative_gnn.py
+58
-3
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+1
-2
未找到文件。
python/paddle/fluid/framework.py
浏览文件 @
3be7e971
...
@@ -431,7 +431,7 @@ class Variable(object):
...
@@ -431,7 +431,7 @@ class Variable(object):
str: The debug string.
str: The debug string.
"""
"""
if
_in_imperative_mode
():
if
_in_imperative_mode
():
# TODO(panyx0718): add imperative debug info.
# TODO(panyx0718): add
more
imperative debug info.
return
'name %s, dtype: %s shape: %s'
%
(
self
.
name
,
self
.
dtype
,
return
'name %s, dtype: %s shape: %s'
%
(
self
.
name
,
self
.
dtype
,
self
.
shape
)
self
.
shape
)
...
...
python/paddle/fluid/tests/unittests/test_imperative_gnn.py
浏览文件 @
3be7e971
...
@@ -21,7 +21,7 @@ import sys
...
@@ -21,7 +21,7 @@ import sys
import
paddle
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
import
paddle.fluid.core
as
core
from
paddle.fluid.optimizer
import
SGD
Optimizer
from
paddle.fluid.optimizer
import
Adam
Optimizer
from
paddle.fluid.imperative.nn
import
Conv2D
,
Pool2D
,
FC
from
paddle.fluid.imperative.nn
import
Conv2D
,
Pool2D
,
FC
from
test_imperative_base
import
new_program_scope
from
test_imperative_base
import
new_program_scope
from
paddle.fluid.imperative.base
import
to_variable
from
paddle.fluid.imperative.base
import
to_variable
...
@@ -65,24 +65,79 @@ class TestImperativeGNN(unittest.TestCase):
...
@@ -65,24 +65,79 @@ class TestImperativeGNN(unittest.TestCase):
def
test_gnn_float32
(
self
):
def
test_gnn_float32
(
self
):
seed
=
90
seed
=
90
startup
=
fluid
.
Program
()
startup
.
random_seed
=
seed
main
=
fluid
.
Program
()
main
.
random_seed
=
seed
scope
=
fluid
.
core
.
Scope
()
with
new_program_scope
(
main
=
main
,
startup
=
startup
,
scope
=
scope
):
features
=
fluid
.
layers
.
data
(
name
=
'features'
,
shape
=
[
1
,
100
,
50
],
dtype
=
'float32'
,
append_batch_size
=
False
)
# Use selected rows when it's supported.
adj
=
fluid
.
layers
.
data
(
name
=
'adj'
,
shape
=
[
1
,
100
,
100
],
dtype
=
'float32'
,
append_batch_size
=
False
)
labels
=
fluid
.
layers
.
data
(
name
=
'labels'
,
shape
=
[
100
,
1
],
dtype
=
'int64'
,
append_batch_size
=
False
)
model
=
GCN
(
'test_gcn'
,
50
)
logits
=
model
(
features
,
adj
)
logits
=
fluid
.
layers
.
reshape
(
logits
,
logits
.
shape
[
1
:])
# In other example, it's nll with log_softmax. However, paddle's
# log_loss only supports binary classification now.
loss
=
fluid
.
layers
.
softmax_with_cross_entropy
(
logits
,
labels
)
loss
=
fluid
.
layers
.
reduce_sum
(
loss
)
adam
=
AdamOptimizer
(
learning_rate
=
1e-3
)
adam
.
minimize
(
loss
)
exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
(
)
if
not
core
.
is_compiled_with_cuda
()
else
fluid
.
CUDAPlace
(
0
))
exe
.
run
(
startup
)
static_loss
=
exe
.
run
(
feed
=
{
'features'
:
np
.
zeros
(
[
1
,
100
,
50
],
dtype
=
np
.
float32
),
'adj'
:
np
.
zeros
(
[
1
,
100
,
100
],
dtype
=
np
.
float32
),
'labels'
:
np
.
zeros
(
[
100
,
1
],
dtype
=
np
.
int64
)
},
fetch_list
=
[
loss
])[
0
]
static_weight
=
np
.
array
(
scope
.
find_var
(
model
.
gc
.
weight
.
name
).
get_tensor
())
with
fluid
.
imperative
.
guard
():
with
fluid
.
imperative
.
guard
():
fluid
.
default_startup_program
().
random_seed
=
seed
fluid
.
default_startup_program
().
random_seed
=
seed
fluid
.
default_main_program
().
random_seed
=
seed
fluid
.
default_main_program
().
random_seed
=
seed
features
=
np
.
zeros
([
1
,
100
,
50
],
dtype
=
np
.
float32
)
features
=
np
.
zeros
([
1
,
100
,
50
],
dtype
=
np
.
float32
)
# Use selected rows when it's supported.
adj
=
np
.
zeros
([
1
,
100
,
100
],
dtype
=
np
.
float32
)
adj
=
np
.
zeros
([
1
,
100
,
100
],
dtype
=
np
.
float32
)
labels
=
np
.
zeros
([
100
,
1
],
dtype
=
np
.
int64
)
labels
=
np
.
zeros
([
100
,
1
],
dtype
=
np
.
int64
)
model
=
GCN
(
'test_gcn'
,
50
)
model
=
GCN
(
'test_gcn'
,
50
)
logits
=
model
(
to_variable
(
features
),
to_variable
(
adj
))
logits
=
model
(
to_variable
(
features
),
to_variable
(
adj
))
sys
.
stderr
.
write
(
'%s
\n
'
%
logits
)
logits
=
fluid
.
layers
.
reshape
(
logits
,
logits
.
shape
[
1
:])
logits
=
fluid
.
layers
.
reshape
(
logits
,
logits
.
shape
[
1
:])
# In other example, it's nll with log_softmax. However, paddle's
# In other example, it's nll with log_softmax. However, paddle's
# log_loss only supports binary classification now.
# log_loss only supports binary classification now.
loss
=
fluid
.
layers
.
softmax_with_cross_entropy
(
logits
,
loss
=
fluid
.
layers
.
softmax_with_cross_entropy
(
logits
,
to_variable
(
labels
))
to_variable
(
labels
))
loss
=
fluid
.
layers
.
reduce_sum
(
loss
)
loss
=
fluid
.
layers
.
reduce_sum
(
loss
)
sys
.
stderr
.
write
(
'%s
\n
'
%
loss
.
_numpy
())
adam
=
AdamOptimizer
(
learning_rate
=
1e-3
)
adam
.
minimize
(
loss
)
self
.
assertEqual
(
static_loss
,
loss
.
_numpy
())
self
.
assertTrue
(
np
.
allclose
(
static_weight
,
model
.
gc
.
weight
.
_numpy
()))
sys
.
stderr
.
write
(
'%s %s
\n
'
%
(
static_loss
,
loss
.
_numpy
()))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
3be7e971
...
@@ -101,8 +101,7 @@ class TestLayer(LayerTest):
...
@@ -101,8 +101,7 @@ class TestLayer(LayerTest):
with
self
.
dynamic_graph
():
with
self
.
dynamic_graph
():
t
=
np
.
ones
([
3
,
3
],
dtype
=
'float32'
)
t
=
np
.
ones
([
3
,
3
],
dtype
=
'float32'
)
t2
=
np
.
ones
([
3
,
3
],
dtype
=
'float32'
)
t2
=
np
.
ones
([
3
,
3
],
dtype
=
'float32'
)
ret
=
layers
.
matmul
(
t
,
t2
)
dy_ret
=
layers
.
matmul
(
base
.
to_variable
(
t
),
base
.
to_variable
(
t2
))
dy_ret
=
layers
.
relu
(
base
.
to_variable
(
ret
))
self
.
assertTrue
(
np
.
allclose
(
static_ret
,
dy_ret
.
_numpy
()))
self
.
assertTrue
(
np
.
allclose
(
static_ret
,
dy_ret
.
_numpy
()))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录