Skip to content

add layer check for recurrent_group #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 15, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions python/paddle/trainer_config_helpers/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2754,7 +2754,12 @@ def __init__(self, input):


@wrap_name_default("recurrent_group")
def recurrent_group(step, input, reverse=False, name=None, targetInlink=None):
def recurrent_group(step,
input,
reverse=False,
name=None,
targetInlink=None,
is_train=True):
"""
Recurrent layer group is an extremely flexible recurrent unit in
PaddlePaddle. As long as the user defines the calculation done within a
Expand Down Expand Up @@ -2819,6 +2824,12 @@ def step(input):

:type targetInlink: LayerOutput|SubsequenceInput

:param is_train: recurrent_group is used for training (True) or generating (False).
If is training, one of the input type must be LayerOutput; else,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is inaccurate. recurrent_group may have three modes: training, testing and generating. In training and testing mode, inputs must contain LayerOutput, while in generating, must not. Therefore, it is more accurate if the parameter "is_train" is changed to "is_generating".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

none of input type should be LayerOutput.

: type is_train: bool

:return: LayerOutput object.
:rtype: LayerOutput
"""
Expand Down Expand Up @@ -2866,13 +2877,15 @@ def map_in_links(x):
seq_reversed=reverse,
target_inlinkname=targetInlinkName)
in_args = []
has_LayerOutput = True
for each_input in input:
assert is_single_input(each_input)
if isinstance(each_input, LayerOutput):
in_args.append(each_input)
elif isinstance(each_input, SubsequenceInput):
in_args.append(each_input.input)
else:
has_LayerOutput = False
mem_name = "__%s_memory__" % each_input.input.name
mem = memory(
name=mem_name,
Expand All @@ -2886,6 +2899,8 @@ def map_in_links(x):
mix += identity_projection(mem)
in_args.append(mem)

assert (is_train == has_LayerOutput)

layer_outs = step(*in_args)

if isinstance(layer_outs, LayerOutput):
Expand Down Expand Up @@ -3177,7 +3192,11 @@ def __real_step__(*args):
return predict

tmp = recurrent_group(
step=__real_step__, input=real_input, reverse=False, name=name)
step=__real_step__,
input=real_input,
reverse=False,
name=name,
is_train=False)

return tmp

Expand Down