Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
934d9986
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看板
未验证
提交
934d9986
编写于
12月 22, 2019
作者:
T
tangwei12
提交者:
GitHub
12月 22, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add selected rows supported in framework (#21808)
* add selected rows supported in framework
上级
855ed5fb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
48 addition
and
13 deletion
+48
-13
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+21
-7
python/paddle/fluid/layer_helper_base.py
python/paddle/fluid/layer_helper_base.py
+5
-2
python/paddle/fluid/optimizer.py
python/paddle/fluid/optimizer.py
+7
-4
python/paddle/fluid/tests/unittests/test_variable.py
python/paddle/fluid/tests/unittests/test_variable.py
+15
-0
未找到文件。
python/paddle/fluid/framework.py
浏览文件 @
934d9986
...
@@ -568,7 +568,6 @@ def _varbase_creator(type=core.VarDesc.VarType.LOD_TENSOR,
...
@@ -568,7 +568,6 @@ def _varbase_creator(type=core.VarDesc.VarType.LOD_TENSOR,
dtype
=
None
,
dtype
=
None
,
persistable
=
None
,
persistable
=
None
,
**
kwargs
):
**
kwargs
):
if
dtype
is
not
None
:
if
dtype
is
not
None
:
if
not
isinstance
(
dtype
,
core
.
VarDesc
.
VarType
):
if
not
isinstance
(
dtype
,
core
.
VarDesc
.
VarType
):
dtype
=
convert_np_dtype_to_dtype_
(
dtype
)
dtype
=
convert_np_dtype_to_dtype_
(
dtype
)
...
@@ -1398,6 +1397,10 @@ class Variable(object):
...
@@ -1398,6 +1397,10 @@ class Variable(object):
# TODO(minqiyang): Support lod_level in dygraph mode
# TODO(minqiyang): Support lod_level in dygraph mode
if
in_dygraph_mode
():
if
in_dygraph_mode
():
raise
Exception
(
"Dygraph model DO NOT supprt lod"
)
raise
Exception
(
"Dygraph model DO NOT supprt lod"
)
if
self
.
type
==
core
.
VarDesc
.
VarType
.
SELECTED_ROWS
:
raise
Exception
(
"SelectedRows DO NOT supprt lod"
)
return
self
.
desc
.
lod_level
()
return
self
.
desc
.
lod_level
()
@
property
@
property
...
@@ -2445,7 +2448,7 @@ class Block(object):
...
@@ -2445,7 +2448,7 @@ class Block(object):
" is inited by multiple init ops "
+
str
(
" is inited by multiple init ops "
+
str
(
init_ops
))
init_ops
))
elif
init_ops_len
==
1
:
elif
init_ops_len
==
1
:
#TODO already inited, do nothing, should log a warning
#
TODO already inited, do nothing, should log a warning
pass
pass
else
:
else
:
initializer
(
param
,
self
)
initializer
(
param
,
self
)
...
@@ -3351,8 +3354,8 @@ class IrGraph(object):
...
@@ -3351,8 +3354,8 @@ class IrGraph(object):
op_node(IrOpNode): the operator node that is needed to update input's link.
op_node(IrOpNode): the operator node that is needed to update input's link.
"""
"""
assert
old_output_node
.
node
in
self
.
graph
.
nodes
()
and
new_output_node
.
node
in
\
assert
old_output_node
.
node
in
self
.
graph
.
nodes
()
and
new_output_node
.
node
in
\
self
.
graph
.
nodes
()
and
op_node
.
node
in
self
.
graph
.
nodes
(),
\
self
.
graph
.
nodes
()
and
op_node
.
node
in
self
.
graph
.
nodes
(),
\
'The three arguments(old_output_node &new_output_node &op_node) must be in the graph nodes.'
'The three arguments(old_output_node &new_output_node &op_node) must be in the graph nodes.'
old_output_node
.
remove_input
(
op_node
)
old_output_node
.
remove_input
(
op_node
)
op_node
.
remove_output
(
old_output_node
)
op_node
.
remove_output
(
old_output_node
)
new_output_node
.
append_input
(
op_node
)
new_output_node
.
append_input
(
op_node
)
...
@@ -4525,7 +4528,12 @@ class Parameter(Variable):
...
@@ -4525,7 +4528,12 @@ class Parameter(Variable):
be applied on this parameter.
be applied on this parameter.
"""
"""
def
__init__
(
self
,
block
,
shape
,
dtype
,
**
kwargs
):
def
__init__
(
self
,
block
,
shape
,
dtype
,
type
=
core
.
VarDesc
.
VarType
.
LOD_TENSOR
,
**
kwargs
):
if
shape
is
None
:
if
shape
is
None
:
raise
ValueError
(
"The shape of Parameter should not be None"
)
raise
ValueError
(
"The shape of Parameter should not be None"
)
if
dtype
is
None
:
if
dtype
is
None
:
...
@@ -4542,7 +4550,13 @@ class Parameter(Variable):
...
@@ -4542,7 +4550,13 @@ class Parameter(Variable):
%
list
(
shape
))
%
list
(
shape
))
Variable
.
__init__
(
Variable
.
__init__
(
self
,
block
,
persistable
=
True
,
shape
=
shape
,
dtype
=
dtype
,
**
kwargs
)
self
,
block
,
persistable
=
True
,
shape
=
shape
,
dtype
=
dtype
,
type
=
type
,
**
kwargs
)
self
.
trainable
=
kwargs
.
get
(
'trainable'
,
True
)
self
.
trainable
=
kwargs
.
get
(
'trainable'
,
True
)
self
.
optimize_attr
=
kwargs
.
get
(
'optimize_attr'
,
{
'learning_rate'
:
1.0
})
self
.
optimize_attr
=
kwargs
.
get
(
'optimize_attr'
,
{
'learning_rate'
:
1.0
})
...
@@ -4660,7 +4674,7 @@ class ParamBase(core.VarBase):
...
@@ -4660,7 +4674,7 @@ class ParamBase(core.VarBase):
self
.
is_distributed
=
False
self
.
is_distributed
=
False
#self.block = default_main_program().global_block()
#
self.block = default_main_program().global_block()
_dygraph_tracer
().
trace_var
(
name
,
self
)
_dygraph_tracer
().
trace_var
(
name
,
self
)
...
...
python/paddle/fluid/layer_helper_base.py
浏览文件 @
934d9986
...
@@ -280,7 +280,8 @@ class LayerHelperBase(object):
...
@@ -280,7 +280,8 @@ class LayerHelperBase(object):
dtype
,
dtype
,
is_bias
=
False
,
is_bias
=
False
,
default_initializer
=
None
,
default_initializer
=
None
,
stop_gradient
=
False
):
stop_gradient
=
False
,
type
=
core
.
VarDesc
.
VarType
.
LOD_TENSOR
):
"""Create parameters for this layers.
"""Create parameters for this layers.
Args:
Args:
...
@@ -334,15 +335,17 @@ class LayerHelperBase(object):
...
@@ -334,15 +335,17 @@ class LayerHelperBase(object):
return
self
.
main_program
.
global_block
().
create_parameter
(
return
self
.
main_program
.
global_block
().
create_parameter
(
dtype
=
dtype
,
dtype
=
dtype
,
shape
=
shape
,
shape
=
shape
,
type
=
type
,
stop_gradient
=
stop_gradient
,
stop_gradient
=
stop_gradient
,
**
attr
.
_to_kwargs
(
with_initializer
=
True
))
**
attr
.
_to_kwargs
(
with_initializer
=
True
))
else
:
else
:
self
.
startup_program
.
global_block
().
create_parameter
(
self
.
startup_program
.
global_block
().
create_parameter
(
dtype
=
dtype
,
dtype
=
dtype
,
shape
=
shape
,
shape
=
shape
,
type
=
type
,
**
attr
.
_to_kwargs
(
with_initializer
=
True
))
**
attr
.
_to_kwargs
(
with_initializer
=
True
))
return
self
.
main_program
.
global_block
().
create_parameter
(
return
self
.
main_program
.
global_block
().
create_parameter
(
dtype
=
dtype
,
shape
=
shape
,
**
attr
.
_to_kwargs
())
dtype
=
dtype
,
shape
=
shape
,
type
=
type
,
**
attr
.
_to_kwargs
())
def
create_variable_for_type_inference
(
self
,
dtype
,
stop_gradient
=
False
):
def
create_variable_for_type_inference
(
self
,
dtype
,
stop_gradient
=
False
):
"""Create a temporary variable that should be type inferred layer.
"""Create a temporary variable that should be type inferred layer.
...
...
python/paddle/fluid/optimizer.py
浏览文件 @
934d9986
...
@@ -324,7 +324,8 @@ class Optimizer(object):
...
@@ -324,7 +324,8 @@ class Optimizer(object):
param
,
param
,
dtype
=
None
,
dtype
=
None
,
fill_value
=
0.0
,
fill_value
=
0.0
,
shape
=
None
):
shape
=
None
,
type
=
None
):
"""Utility function to add an accumulator for a parameter
"""Utility function to add an accumulator for a parameter
Args:
Args:
...
@@ -354,7 +355,7 @@ class Optimizer(object):
...
@@ -354,7 +355,7 @@ class Optimizer(object):
name
=
var_name
,
name
=
var_name
,
persistable
=
True
,
persistable
=
True
,
dtype
=
dtype
or
param
.
dtype
,
dtype
=
dtype
or
param
.
dtype
,
type
=
param
.
type
,
type
=
param
.
type
if
type
is
None
else
type
,
shape
=
shape
,
shape
=
shape
,
belong_to_optimizer
=
True
)
belong_to_optimizer
=
True
)
self
.
helper
.
set_variable_initializer
(
self
.
helper
.
set_variable_initializer
(
...
@@ -1635,13 +1636,15 @@ class AdamOptimizer(Optimizer):
...
@@ -1635,13 +1636,15 @@ class AdamOptimizer(Optimizer):
param
=
p
,
param
=
p
,
fill_value
=
0.9
if
isinstance
(
self
.
_beta1
,
Variable
)
\
fill_value
=
0.9
if
isinstance
(
self
.
_beta1
,
Variable
)
\
else
self
.
_beta1
,
else
self
.
_beta1
,
shape
=
[
1
])
shape
=
[
1
],
type
=
core
.
VarDesc
.
VarType
.
LOD_TENSOR
)
self
.
_add_accumulator
(
self
.
_add_accumulator
(
name
=
self
.
_beta2_pow_acc_str
,
name
=
self
.
_beta2_pow_acc_str
,
param
=
p
,
param
=
p
,
fill_value
=
0.999
if
isinstance
(
self
.
_beta2
,
Variable
)
\
fill_value
=
0.999
if
isinstance
(
self
.
_beta2
,
Variable
)
\
else
self
.
_beta2
,
else
self
.
_beta2
,
shape
=
[
1
])
shape
=
[
1
],
type
=
core
.
VarDesc
.
VarType
.
LOD_TENSOR
)
def
_append_optimize_op
(
self
,
block
,
param_and_grad
):
def
_append_optimize_op
(
self
,
block
,
param_and_grad
):
assert
isinstance
(
block
,
framework
.
Block
)
assert
isinstance
(
block
,
framework
.
Block
)
...
...
python/paddle/fluid/tests/unittests/test_variable.py
浏览文件 @
934d9986
...
@@ -206,6 +206,21 @@ class TestVariable(unittest.TestCase):
...
@@ -206,6 +206,21 @@ class TestVariable(unittest.TestCase):
self
.
assertIsNone
(
var
.
dtype
)
self
.
assertIsNone
(
var
.
dtype
)
self
.
assertIsNone
(
var
.
type
)
self
.
assertIsNone
(
var
.
type
)
def
test_create_selected_rows
(
self
):
b
=
default_main_program
().
current_block
()
var
=
b
.
create_var
(
name
=
"var"
,
shape
=
[
1
,
1
],
dtype
=
"float32"
,
type
=
fluid
.
core
.
VarDesc
.
VarType
.
SELECTED_ROWS
,
persistable
=
True
)
def
_test
():
var
.
lod_level
()
self
.
assertRaises
(
Exception
,
_test
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录