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

Add broadcasting functionality for Div and Sub ops. #17123

Merged
merged 9 commits into from Apr 12, 2018

Conversation

hovhannesgithub
Copy link
Contributor

Hi,
Added broadcasting functionality for Div and Sub ops following the examples of Add and Mul.
Regards,
Hovhannes

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address on your commit. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot. The email used to register you as an authorized contributor must be the email used for the Git commit.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@hovhannesgithub
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

Copy link
Contributor

@andrehentz andrehentz left a comment

Choose a reason for hiding this comment

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

Thanks for doing this. Very nice, apart from the complications of quantization.

// that handles broadcasting as the base case. The code generator would then
// generate max(D1, D2) nested for loops.
// TODO(benoitjacob): BroadcastDiv is intentionally duplicated from
// reference_ops.h. Once an optimized version is implemented and NdArrayDesc<T>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make sure we are within 80 columns everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked this file and maximum line length is <=80characters. Nevertheless there was lines >80 characters in sub_test.cc and div_test.cc which I have fixed.

}
}

// legacy, for compatibility with old checked-in code
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this function didn't exist before you don' t need to keep a legacy version around.

const int32 unclamped_result =
output_offset +
MultiplyByQuantizedMultiplierSmallerThanOne(
input1_val / input2_val, output_multiplier, output_shift);
Copy link
Contributor

Choose a reason for hiding this comment

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

There's an accuracy issue here as the integer division will truncate a lot of values.

Leaving that aside for a second, the calculation doesn't seem correct either (quantization is hard!). The quantized multiplier is s1s2/sout so the result here is
s1
s2/souti1/i2
but it should be s1/s2
i1/i2/sout, right?

Again, quantization is hard, so I'll be OK if you prefer to leave quantization for a subsequent PR.

One solution is to calculate a quantized multiplier that is always greater than 1:
qm = (s1> s2sout) ? qmul(s1/s2/sout) : qmul(s2sout/s1)
and pass a hint as to whether the numerator or the denominator needs scaling
return denominator_needs_scaling ? q1 / (q2 * qm) : (q1 * qm) / q2;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please can you provide more details or link to docs so I can understand quantized ops better.

Copy link
Contributor

Choose a reason for hiding this comment

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

The quantization scheme used in TF Lite is similar to gemmlowp's: https://github.com/google/gemmlowp/blob/master/doc/quantization.md

Maybe we can leave the quantization for a separate PR? I'd be happy to approve the other changes, and then we can have someone with more quantization experience review the other PR.

}
}

// legacy, for compatibility with old checked-in code
Copy link
Contributor

Choose a reason for hiding this comment

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

here too: no need for legacy versions since this didn't exist before your changes.

}
}

// legacy, for compatibility with old checked-in code
Copy link
Contributor

Choose a reason for hiding this comment

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

same here for legacy (there are more of those in the other file)

@protoget protoget added stat:awaiting response Status - Awaiting response from author tag:awaiting response labels Mar 1, 2018
@andrehentz andrehentz added the kokoro:force-run Tests on submitted change label Mar 9, 2018
@kokoro-team kokoro-team removed kokoro:force-run Tests on submitted change labels Mar 9, 2018
jpienaar pushed a commit to jpienaar/tensorflow that referenced this pull request Mar 16, 2018
sb2nov pushed a commit that referenced this pull request Mar 20, 2018
PiperOrigin-RevId: 189776376
@tensorflowbutler tensorflowbutler added the stale This label marks the issue/pr stale - to be closed automatically if no activity label Mar 25, 2018
@tensorflowbutler
Copy link
Member

It has been 14 days with no activity and the awaiting response label was assigned. Is this PR still valid? Assigning the stalled label. Please comment to reassure me that this is still being worked on.

@hovhannesgithub
Copy link
Contributor Author

I fixed conflicts and committed them, so please remove "stalled" label

@andrehentz andrehentz added kokoro:force-run Tests on submitted change and removed stale This label marks the issue/pr stale - to be closed automatically if no activity labels Mar 28, 2018
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 28, 2018
@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Mar 29, 2018
@hovhannesgithub
Copy link
Contributor Author

Hi,
Is there anything that I should do to make this pull request be merged.
Regards,
Hovhannes

@jhseu
Copy link
Contributor

jhseu commented Apr 12, 2018

Can you look at the test failures?

In file included from tensorflow/contrib/lite/kernels/pooling.cc:26:
./tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h:1415:6: error: redefinition of 'BroadcastDiv'
void BroadcastDiv(const T* input1_data, const Dims<4>& input1_dims,
     ^
./tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h:1347:6: note: previous definition is here
void BroadcastDiv(const T* input1_data, const Dims<4>& input1_dims,

@hovhannesgithub
Copy link
Contributor Author

Thanks jhseu for help.

@andrehentz andrehentz added the kokoro:force-run Tests on submitted change label Apr 12, 2018
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Apr 12, 2018
@andrehentz andrehentz merged commit eaaee5d into tensorflow:master Apr 12, 2018
@hovhannesgithub hovhannesgithub deleted the div-sub-broadcasting branch April 13, 2018 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants