Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
49e4e2f9
P
Paddle
项目概览
PaddlePaddle
/
Paddle
接近 2 年 前同步成功
通知
2320
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
49e4e2f9
编写于
4月 04, 2022
作者:
W
Weilong Wu
提交者:
GitHub
4月 04, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Eager] Support rnn_decode switch to eager mode (#41333)
上级
42075ddc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
4 deletion
+34
-4
paddle/fluid/pybind/op_function_generator.h
paddle/fluid/pybind/op_function_generator.h
+1
-0
python/paddle/fluid/layers/sequence_lod.py
python/paddle/fluid/layers/sequence_lod.py
+17
-1
python/paddle/fluid/tests/unittests/test_rnn_decode_api.py
python/paddle/fluid/tests/unittests/test_rnn_decode_api.py
+16
-3
未找到文件。
paddle/fluid/pybind/op_function_generator.h
浏览文件 @
49e4e2f9
...
@@ -106,6 +106,7 @@ std::map<std::string, std::set<std::string>> op_ins_map = {
...
@@ -106,6 +106,7 @@ std::map<std::string, std::set<std::string>> op_ins_map = {
{
"linear_chain_crf"
,
{
"Emission"
,
"Transition"
,
"Label"
,
"Length"
}},
{
"linear_chain_crf"
,
{
"Emission"
,
"Transition"
,
"Label"
,
"Length"
}},
{
"crf_decoding"
,
{
"Emission"
,
"Transition"
,
"Label"
,
"Length"
}},
{
"crf_decoding"
,
{
"Emission"
,
"Transition"
,
"Label"
,
"Length"
}},
{
"chunk_eval"
,
{
"Inference"
,
"Label"
,
"SeqLength"
}},
{
"chunk_eval"
,
{
"Inference"
,
"Label"
,
"SeqLength"
}},
{
"sequence_mask"
,
{
"X"
,
"MaxLenTensor"
}},
{
"graph_reindex"
,
{
"graph_reindex"
,
{
"X"
,
"Neighbors"
,
"Count"
,
"HashTable_Value"
,
"HashTable_Index"
}},
{
"X"
,
"Neighbors"
,
"Count"
,
"HashTable_Value"
,
"HashTable_Index"
}},
{
"graph_sample_neighbors"
,
{
"Row"
,
"Col_Ptr"
,
"X"
,
"Eids"
,
"Perm_Buffer"
}},
{
"graph_sample_neighbors"
,
{
"Row"
,
"Col_Ptr"
,
"X"
,
"Eids"
,
"Perm_Buffer"
}},
...
...
python/paddle/fluid/layers/sequence_lod.py
浏览文件 @
49e4e2f9
...
@@ -15,10 +15,11 @@
...
@@ -15,10 +15,11 @@
from
__future__
import
print_function
from
__future__
import
print_function
from
.layer_function_generator
import
templatedoc
from
.layer_function_generator
import
templatedoc
from
..framework
import
Variable
,
_non_static_mode
from
..framework
import
core
,
Variable
,
_non_static_mode
,
in_dygraph_mode
,
_in_legacy_dygraph
,
convert_np_dtype_to_dtype_
from
..layer_helper
import
LayerHelper
from
..layer_helper
import
LayerHelper
from
..data_feeder
import
check_variable_and_dtype
,
check_type
,
check_dtype
from
..data_feeder
import
check_variable_and_dtype
,
check_type
,
check_dtype
from
..core
import
VarDesc
from
..core
import
VarDesc
from
paddle
import
_C_ops
__all__
=
[
__all__
=
[
'sequence_conv'
,
'sequence_conv'
,
...
@@ -1380,6 +1381,21 @@ def sequence_mask(x, maxlen=None, dtype='int64', name=None):
...
@@ -1380,6 +1381,21 @@ def sequence_mask(x, maxlen=None, dtype='int64', name=None):
# [1 1 1 1 1 1 1 1 0 0]]
# [1 1 1 1 1 1 1 1 0 0]]
"""
"""
if
_non_static_mode
():
if
not
isinstance
(
dtype
,
core
.
VarDesc
.
VarType
):
dtype
=
convert_np_dtype_to_dtype_
(
dtype
)
if
in_dygraph_mode
():
if
maxlen
is
not
None
:
if
isinstance
(
maxlen
,
core
.
eager
.
Tensor
):
attrs
=
(
'out_dtype'
,
dtype
)
out
=
_C_ops
.
sequence_mask
(
x
,
maxlen
,
*
attrs
)
else
:
attrs
=
(
'out_dtype'
,
dtype
,
'maxlen'
,
maxlen
)
out
=
_C_ops
.
sequence_mask
(
x
,
None
,
*
attrs
)
out
.
stop_gradient
=
True
return
out
helper
=
LayerHelper
(
'sequence_mask'
,
**
locals
())
helper
=
LayerHelper
(
'sequence_mask'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
dtype
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
dtype
)
...
...
python/paddle/fluid/tests/unittests/test_rnn_decode_api.py
浏览文件 @
49e4e2f9
...
@@ -31,7 +31,7 @@ import paddle.fluid.core as core
...
@@ -31,7 +31,7 @@ import paddle.fluid.core as core
from
paddle.fluid.executor
import
Executor
from
paddle.fluid.executor
import
Executor
from
paddle.fluid
import
framework
from
paddle.fluid
import
framework
from
paddle.fluid.framework
import
_test_eager_guard
paddle
.
enable_static
()
paddle
.
enable_static
()
...
@@ -554,7 +554,7 @@ class TestDynamicDecode(unittest.TestCase):
...
@@ -554,7 +554,7 @@ class TestDynamicDecode(unittest.TestCase):
},
},
fetch_list
=
[
output
])[
0
]
fetch_list
=
[
output
])[
0
]
def
test
_dynamic_basic_decoder
(
self
):
def
func
_dynamic_basic_decoder
(
self
):
paddle
.
disable_static
()
paddle
.
disable_static
()
src
=
paddle
.
to_tensor
(
np
.
random
.
randint
(
8
,
size
=
(
8
,
4
)))
src
=
paddle
.
to_tensor
(
np
.
random
.
randint
(
8
,
size
=
(
8
,
4
)))
src_length
=
paddle
.
to_tensor
(
np
.
random
.
randint
(
8
,
size
=
(
8
)))
src_length
=
paddle
.
to_tensor
(
np
.
random
.
randint
(
8
,
size
=
(
8
)))
...
@@ -562,6 +562,11 @@ class TestDynamicDecode(unittest.TestCase):
...
@@ -562,6 +562,11 @@ class TestDynamicDecode(unittest.TestCase):
probs
,
samples
,
sample_length
=
model
(
src
,
src_length
)
probs
,
samples
,
sample_length
=
model
(
src
,
src_length
)
paddle
.
enable_static
()
paddle
.
enable_static
()
def
test_dynamic_basic_decoder
(
self
):
with
_test_eager_guard
():
self
.
func_dynamic_basic_decoder
()
self
.
func_dynamic_basic_decoder
()
class
ModuleApiTest
(
unittest
.
TestCase
):
class
ModuleApiTest
(
unittest
.
TestCase
):
@
classmethod
@
classmethod
...
@@ -708,9 +713,17 @@ class TestBeamSearch(ModuleApiTest):
...
@@ -708,9 +713,17 @@ class TestBeamSearch(ModuleApiTest):
]
]
return
inputs
return
inputs
def
test_check_output
(
self
):
def
func_check_output
(
self
):
self
.
setUp
()
self
.
make_inputs
()
self
.
make_inputs
()
self
.
check_output
()
self
.
check_output
()
def
test_check_output
(
self
):
with
_test_eager_guard
():
self
.
func_check_output
()
self
.
func_check_output
()
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录