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

Correctly handling variable with batch dimension for math ops. #8505

Merged
merged 2 commits into from
Feb 28, 2018

Conversation

emailweixu
Copy link
Collaborator

@emailweixu emailweixu commented Feb 23, 2018

We should allow addition like the following where b is a scalar for each instance in a batch, although both a and b has an additional batch dimension. The following code will cause error with the current implementation of math_op_patch.py.

a = fluid.layers.data(name="a", shape=[2])
b = fluid.layers.data(name="b", shape=[1])
c = a + b

To fix this, we need to set the axis to 0 when the second argument contains batch dimension.

Also makes elementwise ops more tolerant at handling tensors with trailing singular dimensions.
Also added Dim<0>. Dim<0> is for scalar (rank-0 tensor). Adding Dim<0> can simplify a lot of code.

xuwei06 added 2 commits February 27, 2018 10:09
Dim<0> is for scalar (rank-0 tensor). Adding Dim<0> can simplify
a lot of code.
When the second argument contains batch dimension, the axis should be 0.

Also makes elementwise ops more tolerant at handling tensors with trailing
singular dimensions.
@JiayiFeng
Copy link
Collaborator

lgtm

@emailweixu emailweixu merged commit eac2c3c into PaddlePaddle:develop Feb 28, 2018
@emailweixu emailweixu deleted the math_op branch March 16, 2018 23:03
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.

2 participants