Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0b4bb023
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0b4bb023
编写于
9月 25, 2020
作者:
L
Leo Chen
提交者:
GitHub
9月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add static mode check on data() (#27495)
* add static check on data() * follow comments * fix ut
上级
a5b32637
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
31 addition
and
1 deletion
+31
-1
python/paddle/fluid/data.py
python/paddle/fluid/data.py
+2
-0
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+11
-1
python/paddle/fluid/layers/io.py
python/paddle/fluid/layers/io.py
+2
-0
python/paddle/fluid/tests/unittests/test_data.py
python/paddle/fluid/tests/unittests/test_data.py
+12
-0
python/paddle/fluid/tests/unittests/test_deprecated_decorator.py
...paddle/fluid/tests/unittests/test_deprecated_decorator.py
+2
-0
python/paddle/static/input.py
python/paddle/static/input.py
+2
-0
未找到文件。
python/paddle/fluid/data.py
浏览文件 @
0b4bb023
...
@@ -19,10 +19,12 @@ from paddle.fluid import core
...
@@ -19,10 +19,12 @@ from paddle.fluid import core
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.data_feeder
import
check_dtype
,
check_type
from
paddle.fluid.data_feeder
import
check_dtype
,
check_type
from
..utils
import
deprecated
from
..utils
import
deprecated
from
paddle.fluid.framework
import
static_only
__all__
=
[
'data'
]
__all__
=
[
'data'
]
@
static_only
@
deprecated
(
since
=
"2.0.0"
,
update_to
=
"paddle.static.data"
)
@
deprecated
(
since
=
"2.0.0"
,
update_to
=
"paddle.static.data"
)
def
data
(
name
,
shape
,
dtype
=
'float32'
,
lod_level
=
0
):
def
data
(
name
,
shape
,
dtype
=
'float32'
,
lod_level
=
0
):
"""
"""
...
...
python/paddle/fluid/framework.py
浏览文件 @
0b4bb023
...
@@ -217,7 +217,16 @@ def _dygraph_not_support_(func):
...
@@ -217,7 +217,16 @@ def _dygraph_not_support_(func):
def
_dygraph_only_
(
func
):
def
_dygraph_only_
(
func
):
def
__impl__
(
*
args
,
**
kwargs
):
def
__impl__
(
*
args
,
**
kwargs
):
assert
in_dygraph_mode
(
assert
in_dygraph_mode
(
),
"We Only support %s in dynamic mode, please call 'paddle.disable_static()' to enter dynamic mode."
%
func
.
__name__
),
"We only support '%s()' in dynamic graph mode, please call 'paddle.disable_static()' to enter dynamic graph mode."
%
func
.
__name__
return
func
(
*
args
,
**
kwargs
)
return
__impl__
def
_static_only_
(
func
):
def
__impl__
(
*
args
,
**
kwargs
):
assert
not
in_dygraph_mode
(
),
"We only support '%s()' in static graph mode, please call 'paddle.enable_static()' to enter static graph mode."
%
func
.
__name__
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
return
__impl__
return
__impl__
...
@@ -260,6 +269,7 @@ def deprecate_stat_dict(func):
...
@@ -260,6 +269,7 @@ def deprecate_stat_dict(func):
dygraph_not_support
=
wrap_decorator
(
_dygraph_not_support_
)
dygraph_not_support
=
wrap_decorator
(
_dygraph_not_support_
)
dygraph_only
=
wrap_decorator
(
_dygraph_only_
)
dygraph_only
=
wrap_decorator
(
_dygraph_only_
)
static_only
=
wrap_decorator
(
_static_only_
)
fake_interface_only
=
wrap_decorator
(
_fake_interface_only_
)
fake_interface_only
=
wrap_decorator
(
_fake_interface_only_
)
...
...
python/paddle/fluid/layers/io.py
浏览文件 @
0b4bb023
...
@@ -31,6 +31,7 @@ from ..unique_name import generate as unique_name
...
@@ -31,6 +31,7 @@ from ..unique_name import generate as unique_name
import
logging
import
logging
from
..data_feeder
import
check_dtype
,
check_type
from
..data_feeder
import
check_dtype
,
check_type
from
paddle.fluid.framework
import
static_only
__all__
=
[
__all__
=
[
'data'
,
'read_file'
,
'double_buffer'
,
'py_reader'
,
'data'
,
'read_file'
,
'double_buffer'
,
'py_reader'
,
...
@@ -38,6 +39,7 @@ __all__ = [
...
@@ -38,6 +39,7 @@ __all__ = [
]
]
@
static_only
def
data
(
name
,
def
data
(
name
,
shape
,
shape
,
append_batch_size
=
True
,
append_batch_size
=
True
,
...
...
python/paddle/fluid/tests/unittests/test_data.py
浏览文件 @
0b4bb023
...
@@ -99,5 +99,17 @@ class TestApiStaticDataError(unittest.TestCase):
...
@@ -99,5 +99,17 @@ class TestApiStaticDataError(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
test_shape_type
)
self
.
assertRaises
(
TypeError
,
test_shape_type
)
class
TestApiErrorWithDynamicMode
(
unittest
.
TestCase
):
def
test_error
(
self
):
with
program_guard
(
Program
(),
Program
()):
paddle
.
disable_static
()
self
.
assertRaises
(
AssertionError
,
fluid
.
data
,
'a'
,
[
2
,
25
])
self
.
assertRaises
(
AssertionError
,
fluid
.
layers
.
data
,
'b'
,
shape
=
[
2
,
25
])
self
.
assertRaises
(
AssertionError
,
paddle
.
static
.
data
,
'c'
,
shape
=
[
2
,
25
])
paddle
.
enable_static
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_deprecated_decorator.py
浏览文件 @
0b4bb023
...
@@ -72,6 +72,7 @@ class TestDeprecatedDocorator(unittest.TestCase):
...
@@ -72,6 +72,7 @@ class TestDeprecatedDocorator(unittest.TestCase):
test old fluid elementwise_mul api, it should fire Warinng function,
test old fluid elementwise_mul api, it should fire Warinng function,
which insert the Warinng info on top of API's doc string.
which insert the Warinng info on top of API's doc string.
"""
"""
paddle
.
enable_static
()
# Initialization
# Initialization
x
=
fluid
.
data
(
name
=
'x'
,
shape
=
[
3
,
2
,
1
],
dtype
=
'float32'
)
x
=
fluid
.
data
(
name
=
'x'
,
shape
=
[
3
,
2
,
1
],
dtype
=
'float32'
)
...
@@ -80,6 +81,7 @@ class TestDeprecatedDocorator(unittest.TestCase):
...
@@ -80,6 +81,7 @@ class TestDeprecatedDocorator(unittest.TestCase):
# captured
# captured
captured
=
get_warning_index
(
fluid
.
data
)
captured
=
get_warning_index
(
fluid
.
data
)
paddle
.
disable_static
()
# testting
# testting
self
.
assertGreater
(
expected
,
captured
)
self
.
assertGreater
(
expected
,
captured
)
...
...
python/paddle/static/input.py
浏览文件 @
0b4bb023
...
@@ -19,10 +19,12 @@ from paddle.fluid import core, Variable
...
@@ -19,10 +19,12 @@ from paddle.fluid import core, Variable
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.data_feeder
import
check_type
from
paddle.fluid.data_feeder
import
check_type
from
paddle.fluid.framework
import
convert_np_dtype_to_dtype_
from
paddle.fluid.framework
import
convert_np_dtype_to_dtype_
from
paddle.fluid.framework
import
static_only
__all__
=
[
'data'
,
'InputSpec'
]
__all__
=
[
'data'
,
'InputSpec'
]
@
static_only
def
data
(
name
,
shape
,
dtype
=
None
,
lod_level
=
0
):
def
data
(
name
,
shape
,
dtype
=
None
,
lod_level
=
0
):
"""
"""
**Data Layer**
**Data Layer**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录