Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
0d8f40d2
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看板
未验证
提交
0d8f40d2
编写于
3月 19, 2020
作者:
Z
Zhang Ting
提交者:
GitHub
3月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove init_on_cpu and force_init_on_cpu APIs, test=develop (#22202)
上级
abee05a8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
9 addition
and
63 deletion
+9
-63
python/paddle/fluid/initializer.py
python/paddle/fluid/initializer.py
+4
-49
python/paddle/fluid/layers/learning_rate_scheduler.py
python/paddle/fluid/layers/learning_rate_scheduler.py
+0
-1
python/paddle/fluid/layers/math_op_patch.py
python/paddle/fluid/layers/math_op_patch.py
+1
-2
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+4
-10
python/paddle/fluid/tests/unittests/seresnext_net.py
python/paddle/fluid/tests/unittests/seresnext_net.py
+0
-1
未找到文件。
python/paddle/fluid/initializer.py
浏览文件 @
0d8f40d2
...
@@ -24,56 +24,11 @@ from . import unique_name
...
@@ -24,56 +24,11 @@ from . import unique_name
__all__
=
[
__all__
=
[
'Constant'
,
'Uniform'
,
'Normal'
,
'TruncatedNormal'
,
'Xavier'
,
'Bilinear'
,
'Constant'
,
'Uniform'
,
'Normal'
,
'TruncatedNormal'
,
'Xavier'
,
'Bilinear'
,
'MSRA'
,
'force_init_on_cpu'
,
'init_on_cpu'
,
'ConstantInitializer'
,
'MSRA'
,
'ConstantInitializer'
,
'UniformInitializer'
,
'NormalInitializer'
,
'UniformInitializer'
,
'NormalInitializer'
,
'TruncatedNormalInitializer'
,
'TruncatedNormalInitializer'
,
'XavierInitializer'
,
'BilinearInitializer'
,
'XavierInitializer'
,
'BilinearInitializer'
,
'MSRAInitializer'
,
'MSRAInitializer'
,
'NumpyArrayInitializer'
'NumpyArrayInitializer'
]
]
_force_init_on_cpu_
=
False
def
force_init_on_cpu
():
"""
The flag of whether force to init variables on CPU.
Returns:
bool: the state if we should force init on CPU.
Examples:
.. code-block:: python
import paddle.fluid as fluid
if fluid.initializer.force_init_on_cpu():
step = fluid.layers.create_global_var(
shape=[2,3], value=1.0, dtype='float32')
"""
return
_force_init_on_cpu_
@
signature_safe_contextmanager
def
init_on_cpu
():
"""
Force the variable to be inited on CPU.
Examples:
.. code-block:: python
import paddle.fluid as fluid
with fluid.initializer.init_on_cpu():
step = fluid.layers.create_global_var(
shape=[2,3], value=1.0, dtype='float32')
"""
global
_force_init_on_cpu_
pre_state
=
force_init_on_cpu
()
_force_init_on_cpu_
=
True
yield
_force_init_on_cpu_
=
pre_state
class
Initializer
(
object
):
class
Initializer
(
object
):
"""Base class for variable initializers
"""Base class for variable initializers
...
@@ -186,7 +141,7 @@ class ConstantInitializer(Initializer):
...
@@ -186,7 +141,7 @@ class ConstantInitializer(Initializer):
"shape"
:
var
.
shape
,
"shape"
:
var
.
shape
,
"dtype"
:
int
(
out_dtype
),
"dtype"
:
int
(
out_dtype
),
"value"
:
float
(
self
.
_value
),
"value"
:
float
(
self
.
_value
),
'force_cpu'
:
self
.
_force_cpu
or
force_init_on_cpu
()
'force_cpu'
:
self
.
_force_cpu
},
},
stop_gradient
=
True
)
stop_gradient
=
True
)
...
...
python/paddle/fluid/layers/learning_rate_scheduler.py
浏览文件 @
0d8f40d2
...
@@ -29,7 +29,6 @@ from . import control_flow
...
@@ -29,7 +29,6 @@ from . import control_flow
from
.
import
nn
from
.
import
nn
from
.
import
ops
from
.
import
ops
from
.
import
tensor
from
.
import
tensor
from
..initializer
import
init_on_cpu
from
..framework
import
default_main_program
,
Parameter
,
unique_name
,
name_scope
from
..framework
import
default_main_program
,
Parameter
,
unique_name
,
name_scope
from
..framework
import
Variable
from
..framework
import
Variable
from
..framework
import
in_dygraph_mode
from
..framework
import
in_dygraph_mode
...
...
python/paddle/fluid/layers/math_op_patch.py
浏览文件 @
0d8f40d2
...
@@ -17,7 +17,6 @@ from __future__ import print_function
...
@@ -17,7 +17,6 @@ from __future__ import print_function
from
..
import
core
from
..
import
core
from
..framework
import
Variable
,
unique_name
from
..framework
import
Variable
,
unique_name
from
.layer_function_generator
import
OpProtoHolder
from
.layer_function_generator
import
OpProtoHolder
from
..initializer
import
force_init_on_cpu
_supported_int_dtype_
=
[
_supported_int_dtype_
=
[
core
.
VarDesc
.
VarType
.
UINT8
,
core
.
VarDesc
.
VarType
.
UINT8
,
...
@@ -58,7 +57,7 @@ def monkey_patch_variable():
...
@@ -58,7 +57,7 @@ def monkey_patch_variable():
'dtype'
:
var
.
dtype
,
'dtype'
:
var
.
dtype
,
'shape'
:
shape
,
'shape'
:
shape
,
'value'
:
value
,
'value'
:
value
,
'force_cpu'
:
force_init_on_cpu
()
'force_cpu'
:
False
},
},
stop_gradient
=
True
)
stop_gradient
=
True
)
var
.
stop_gradient
=
True
var
.
stop_gradient
=
True
...
...
python/paddle/fluid/layers/tensor.py
浏览文件 @
0d8f40d2
...
@@ -18,7 +18,7 @@ from ..layer_helper import LayerHelper
...
@@ -18,7 +18,7 @@ from ..layer_helper import LayerHelper
from
..param_attr
import
ParamAttr
from
..param_attr
import
ParamAttr
from
..framework
import
convert_np_dtype_to_dtype_
,
in_dygraph_mode
,
_varbase_creator
from
..framework
import
convert_np_dtype_to_dtype_
,
in_dygraph_mode
,
_varbase_creator
from
..framework
import
Variable
from
..framework
import
Variable
from
..initializer
import
Constant
,
force_init_on_cpu
from
..initializer
import
Constant
from
..core
import
VarDesc
from
..core
import
VarDesc
from
..
import
core
from
..
import
core
from
.layer_function_generator
import
templatedoc
from
.layer_function_generator
import
templatedoc
...
@@ -569,10 +569,7 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None):
...
@@ -569,10 +569,7 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None):
shape = fluid.layers.fill_constant([1,2], "int32", 2) # shape=[2,2]
shape = fluid.layers.fill_constant([1,2], "int32", 2) # shape=[2,2]
data4 = fluid.layers.fill_constant(shape=shape, dtype='bool', value=True) # data4=[[True,True],[True,True]]
data4 = fluid.layers.fill_constant(shape=shape, dtype='bool', value=True) # data4=[[True,True],[True,True]]
"""
"""
attrs
=
{
attrs
=
{
'value'
:
float
(
value
),
'force_cpu'
:
force_cpu
}
'value'
:
float
(
value
),
'force_cpu'
:
force_cpu
or
force_init_on_cpu
()
}
if
convert_dtype
(
dtype
)
in
[
'int64'
,
'int32'
]:
if
convert_dtype
(
dtype
)
in
[
'int64'
,
'int32'
]:
attrs
[
'str_value'
]
=
str
(
int
(
value
))
attrs
[
'str_value'
]
=
str
(
int
(
value
))
...
@@ -601,10 +598,7 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None):
...
@@ -601,10 +598,7 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None):
'fill_constant'
)
'fill_constant'
)
check_type
(
shape
,
'shape'
,
(
Variable
,
list
,
tuple
),
'fill_constant'
)
check_type
(
shape
,
'shape'
,
(
Variable
,
list
,
tuple
),
'fill_constant'
)
inputs
=
{}
inputs
=
{}
attrs
=
{
attrs
=
{
'value'
:
float
(
value
),
'force_cpu'
:
force_cpu
}
'value'
:
float
(
value
),
'force_cpu'
:
force_cpu
or
force_init_on_cpu
()
}
if
convert_dtype
(
dtype
)
in
[
'int64'
,
'int32'
]:
if
convert_dtype
(
dtype
)
in
[
'int64'
,
'int32'
]:
attrs
[
'str_value'
]
=
str
(
int
(
value
))
attrs
[
'str_value'
]
=
str
(
int
(
value
))
...
@@ -722,7 +716,7 @@ def fill_constant_batch_size_like(input,
...
@@ -722,7 +716,7 @@ def fill_constant_batch_size_like(input,
'value'
:
float
(
value
),
'value'
:
float
(
value
),
'input_dim_idx'
:
input_dim_idx
,
'input_dim_idx'
:
input_dim_idx
,
'output_dim_idx'
:
output_dim_idx
,
'output_dim_idx'
:
output_dim_idx
,
'force_cpu'
:
force_cpu
or
force_init_on_cpu
()
'force_cpu'
:
force_cpu
}
}
if
convert_dtype
(
dtype
)
in
[
'int64'
,
'int32'
]:
if
convert_dtype
(
dtype
)
in
[
'int64'
,
'int32'
]:
attrs
[
'str_value'
]
=
str
(
int
(
value
))
attrs
[
'str_value'
]
=
str
(
int
(
value
))
...
...
python/paddle/fluid/tests/unittests/seresnext_net.py
浏览文件 @
0d8f40d2
...
@@ -17,7 +17,6 @@ import paddle.fluid as fluid
...
@@ -17,7 +17,6 @@ import paddle.fluid as fluid
fluid
.
core
.
_set_eager_deletion_mode
(
-
1
,
-
1
,
False
)
fluid
.
core
.
_set_eager_deletion_mode
(
-
1
,
-
1
,
False
)
import
paddle.fluid.layers.ops
as
ops
import
paddle.fluid.layers.ops
as
ops
from
paddle.fluid.initializer
import
init_on_cpu
from
paddle.fluid.layers.learning_rate_scheduler
import
cosine_decay
from
paddle.fluid.layers.learning_rate_scheduler
import
cosine_decay
from
simple_nets
import
init_data
from
simple_nets
import
init_data
import
math
import
math
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录