Skip to content
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

fix RNN and IfElse syntax in Block design #4210

Merged
merged 16 commits into from
Oct 7, 2017

Conversation

Superjomn
Copy link
Contributor

No description provided.

@Superjomn Superjomn changed the title fix block syntax fix RNN and IfElse syntax Sep 20, 2017
# mark the variables that need to be segmented for time steps.
x_ = x.as_step_input()
# mark the varialbe that used as a RNN state.
h_ = h.as_step_memory(init=m)
Copy link
Collaborator

Choose a reason for hiding this comment

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

h is not defined

x = ie.inputs(true, 0)
z = operator.add(x, y)
ie.set_output(true, 0, operator.softmax(z))
x_ = x.as_ifelse_input()
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the framework knows whether x contains instances, user does not indicate x as ifelse_input. The use can directly use x in the block and the framework can automatically do the splitting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

some x that has instances might not need to be split.

such as

# v is some op's output
v = some_op() # shape is [20, 20]
data = var(shape=[20, 20])

with ie.true_block():
    # split x
    x = data.as_ifelse_input() # shape [1, 20]
    # v should not be split
    y = pd.matmul(x.T, v) # shape [1, 20]
   y_T = y.T # [20, 1]
   ie.set_outputs(y_T)

v has the same batch_size, but do not need to be split.

if write as

with ie.true_block():
    y = pd.matmul(x, v) # shape [1, 20] x [1, 20] wrong

the shapes will not match.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If a variable has fixed size, it's not splittable. If a variable's size depends on batchsize, it must be splitted because it means that it contains data for each instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, I see, I will change this latter.

with ie.true_block():
x = ie.inputs(true, 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a replacement here #4313

with rnn.step():
h = rnn.memory(init = m)
hh = rnn.previous_memory(h)
a = layer.fc(W, x)
Copy link
Collaborator

Choose a reason for hiding this comment

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

RNN needs to differentiate static input and sequence input. Static input is same for every step. Sequence input will have to pick the corresponding data for each step. I suggest that static input uses same syntax as if-else, while sequence input needs to explicitly indicate it as step input (e.g., using as_step_input())

@Superjomn Superjomn changed the title fix RNN and IfElse syntax fix RNN and IfElse syntax in Block design Oct 7, 2017
Copy link
Collaborator

@wangkuiyi wangkuiyi left a comment

Choose a reason for hiding this comment

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

LGTM

@wangkuiyi wangkuiyi merged commit bfe6dcb into PaddlePaddle:develop Oct 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants