Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
8b611f04
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看板
未验证
提交
8b611f04
编写于
11月 30, 2022
作者:
C
cyber-pioneer
提交者:
GitHub
11月 30, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove fluid.layer.gather_tree (#48480)
上级
f62b3fc8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
10 addition
and
73 deletion
+10
-73
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+0
-65
python/paddle/fluid/layers/rnn.py
python/paddle/fluid/layers/rnn.py
+1
-1
python/paddle/fluid/tests/unittests/dygraph_to_static/seq2seq_dygraph_model.py
...ests/unittests/dygraph_to_static/seq2seq_dygraph_model.py
+3
-1
python/paddle/fluid/tests/unittests/dygraph_to_static/transformer_dygraph_model.py
.../unittests/dygraph_to_static/transformer_dygraph_model.py
+1
-1
python/paddle/fluid/tests/unittests/test_gather_tree_op.py
python/paddle/fluid/tests/unittests/test_gather_tree_op.py
+5
-5
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
8b611f04
...
...
@@ -128,7 +128,6 @@ __all__ = [
'shard_index'
,
'hard_swish'
,
'mish'
,
'gather_tree'
,
'uniform_random'
,
'unbind'
,
]
...
...
@@ -7928,70 +7927,6 @@ def mish(x, threshold=20, name=None):
return
out
def
gather_tree
(
ids
,
parents
):
r
"""
To be used after beam search. After beam search, we get selected ids at
each time step and the corresponding parents in the search tree. Both ids
and parents have the layout :attr:`[max_time, batch_size, beam_size]`. Then
:attr:`gather_tree` is used to backtrace from the last time step and
generate the full sequences by collecting selected ids.
Here is an example:
.. code-block:: text
Given:
ids = [[[2 2]
[6 1]]
[[3 9]
[6 1]]
[[0 1]
[9 0]]]
parents = [[[0 0]
[1 1]]
[[1 0]
[1 0]]
[[0 0]
[0 1]]]
Then:
gather_tree(ids, parents)
= [[[2 2]
[1 6]]
[[3 3]
[6 1]]
[[0 1]
[9 0]]]
Args:
ids(Tensor): A Tensor with shape :attr:`[length, batch_size, beam_size]`
and data type :attr:`int32` or :attr:`int64`. It contains the selected
ids of all time steps.
parents(Tensor): A Tensor with the same shape and data type as :attr:`ids`,
It contains the parents corresponding to selected ids when searching
among beams.
Returns:
A Tensor with the same shape and data type as :attr:`ids`. \
It contains the full sequences. The sequences are collected from \
:attr:`ids` by backtracing according to :attr:`parents`.
Examples:
.. code-block:: python
import paddle
ids = paddle.to_tensor([[[2, 2], [6, 1]], [[3, 9], [6, 1]], [[0, 1], [9, 0]]])
parents = paddle.to_tensor([[[0, 0], [1, 1]], [[1, 0], [1, 0]], [[0, 0], [0, 1]]])
final_sequences = paddle.nn.functional.gather_tree(ids, parents)
# [[[2, 2], [1, 6]], [[3, 3], [6, 1]], [[0, 1], [9, 0]]]
"""
return
paddle
.
nn
.
functional
.
gather_tree
(
ids
,
parents
)
@
deprecated
(
since
=
"2.0.0"
,
update_to
=
"paddle.uniform"
)
@
templatedoc
()
def
uniform_random
(
...
...
python/paddle/fluid/layers/rnn.py
浏览文件 @
8b611f04
...
...
@@ -1427,7 +1427,7 @@ class BeamSearchDecoder(Decoder):
`[time_step, batch_size, beam_size]`. `final_states` is the same \
as the input argument `final_states`.
"""
predicted_ids
=
nn
.
gather_tree
(
predicted_ids
=
paddle
.
nn
.
functional
.
gather_tree
(
outputs
.
predicted_ids
,
outputs
.
parent_ids
)
# TODO: use FinalBeamSearchDecoderOutput as output
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/seq2seq_dygraph_model.py
浏览文件 @
8b611f04
...
...
@@ -502,7 +502,9 @@ class BaseModel(fluid.dygraph.Layer):
predicted_ids
=
paddle
.
stack
(
predicted_ids
)
parent_ids
=
paddle
.
stack
(
parent_ids
)
predicted_ids
=
fluid
.
layers
.
gather_tree
(
predicted_ids
,
parent_ids
)
predicted_ids
=
paddle
.
nn
.
functional
.
gather_tree
(
predicted_ids
,
parent_ids
)
predicted_ids
=
self
.
_transpose_batch_time
(
predicted_ids
)
return
predicted_ids
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/transformer_dygraph_model.py
浏览文件 @
8b611f04
...
...
@@ -884,7 +884,7 @@ class Transformer(Layer):
predict_ids
=
paddle
.
stack
(
predict_ids
,
axis
=
0
)
parent_ids
=
paddle
.
stack
(
parent_ids
,
axis
=
0
)
finished_seq
=
paddle
.
transpose
(
layers
.
gather_tree
(
predict_ids
,
parent_ids
),
[
1
,
2
,
0
]
paddle
.
nn
.
functional
.
gather_tree
(
predict_ids
,
parent_ids
),
[
1
,
2
,
0
]
)
finished_scores
=
topk_scores
...
...
python/paddle/fluid/tests/unittests/test_gather_tree_op.py
浏览文件 @
8b611f04
...
...
@@ -67,7 +67,7 @@ class TestGatherTreeOpAPI(unittest.TestCase):
dtype
=
'int64'
,
append_batch_size
=
False
,
)
final_sequences
=
fluid
.
layers
.
gather_tree
(
ids
,
parents
)
final_sequences
=
paddle
.
nn
.
functional
.
gather_tree
(
ids
,
parents
)
paddle
.
disable_static
()
def
test_case2
(
self
):
...
...
@@ -100,14 +100,14 @@ class TestGatherTreeOpError(unittest.TestCase):
def
test_Variable_ids
():
# the input type must be Variable
np_ids
=
np
.
random
.
random
((
5
,
2
,
2
),
dtype
=
'int64'
)
fluid
.
layers
.
gather_tree
(
np_ids
,
parents
)
paddle
.
nn
.
functional
.
gather_tree
(
np_ids
,
parents
)
self
.
assertRaises
(
TypeError
,
test_Variable_ids
)
def
test_Variable_parents
():
# the input type must be Variable
np_parents
=
np
.
random
.
random
((
5
,
2
,
2
),
dtype
=
'int64'
)
fluid
.
layers
.
gather_tree
(
ids
,
np_parents
)
paddle
.
nn
.
functional
.
gather_tree
(
ids
,
np_parents
)
self
.
assertRaises
(
TypeError
,
test_Variable_parents
)
...
...
@@ -119,7 +119,7 @@ class TestGatherTreeOpError(unittest.TestCase):
dtype
=
'float32'
,
append_batch_size
=
False
,
)
fluid
.
layers
.
gather_tree
(
bad_ids
,
parents
)
paddle
.
nn
.
functional
.
gather_tree
(
bad_ids
,
parents
)
self
.
assertRaises
(
TypeError
,
test_type_ids
)
...
...
@@ -131,7 +131,7 @@ class TestGatherTreeOpError(unittest.TestCase):
dtype
=
'float32'
,
append_batch_size
=
False
,
)
fluid
.
layers
.
gather_tree
(
ids
,
bad_parents
)
paddle
.
nn
.
functional
.
gather_tree
(
ids
,
bad_parents
)
self
.
assertRaises
(
TypeError
,
test_type_parents
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录