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

[c++] Distance-agnostic triplet margin loss #45377

Closed
wants to merge 7 commits into from

Conversation

ethch18
Copy link

@ethch18 ethch18 commented Sep 26, 2020

Stack from ghstack:

This PR adds a C++ implementation of the TripletMarginWithDistanceLoss, for which the Python implementation was introduced in PR #43680. It's based on PR #44072, but I'm resubmitting this to unlink it from Phabricator.

cc: @mruberry @albanD @glaringlee

Differential Revision: D24003973

@dr-ci
Copy link

dr-ci bot commented Sep 26, 2020

💊 CI failures summary and remediations

As of commit 023aa43 (more details on the Dr. CI page):



1 failure confirmed as flaky and can be ignored:

  • pytorch_xla_linux_bionic_py3_6_clang9_build

🚧 1 fixed upstream failure:

These were probably caused by upstream breakages that were already fixed.

Please rebase on the viable/strict branch (expand for instructions)

Since your merge base is older than viable/strict, run these commands:

git fetch https://github.com/pytorch/pytorch viable/strict
git rebase FETCH_HEAD

Check out the recency history of this "viable master" tracking branch.


ci.pytorch.org: 1 failed


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 28 times.

This PR adds a C++ implementation of the TripletMarginWithDistanceLoss, for which the Python implementation was introduced in PR #43680.  It's based on PR #44072, but I'm resubmitting this to unlink it from Phabricator.

cc: @mruberry @albanD @glaringlee 

[ghstack-poisoned]
ethch18 added a commit that referenced this pull request Sep 26, 2020
ghstack-source-id: 13d5caecceea15fc9c98b8366e15d52c1bd88b83
Pull Request resolved: #45377
@glaringlee
Copy link
Contributor

glaringlee commented Sep 28, 2020

@ethch18
I'll review this soon. Can you do a rebase? It seems the CI tests failed due to a problematic master base.

@gchanan gchanan added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 28, 2020
This PR adds a C++ implementation of the TripletMarginWithDistanceLoss, for which the Python implementation was introduced in PR #43680.  It's based on PR #44072, but I'm resubmitting this to unlink it from Phabricator.

cc: @mruberry @albanD @glaringlee 

[ghstack-poisoned]
ethch18 added a commit that referenced this pull request Sep 28, 2020
ghstack-source-id: 2ff77abfce01455332b5905b7bfb246a022cde13
Pull Request resolved: #45377
test/cpp/api/functional.cpp Outdated Show resolved Hide resolved
test/cpp/api/modules.cpp Outdated Show resolved Hide resolved
test/cpp/api/modules.cpp Outdated Show resolved Hide resolved
test/cpp/api/modules.cpp Show resolved Hide resolved
@@ -180,6 +180,33 @@ Tensor TripletMarginLossImpl::forward(

// ============================================================================

TripletMarginWithDistanceLossImpl::TripletMarginWithDistanceLossImpl(
const TripletMarginWithDistanceLossOptions& options_) // NOLINT(modernize-pass-by-value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will complier complain if removing NOLINT(...)?
I kinda remember c10:optional doesn't work well with std::move. Did you try std::move here?

Copy link
Author

Choose a reason for hiding this comment

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

clint complains about this otherwise; I copied the NOLINT() from elsewhere in the file.

What would std::move look like in this case? Looks like everything else in this file uses the same format, minus NOLINT() if it's not applicable.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can do the following to avoid that lint error.
TripletMarginWithDistanceLossImpl::TripletMarginWithDistanceLossImpl( TripletMarginWithDistanceLossOptions options_) : options(std::move(options_)) {}
But I kinda remember std::move is not working well with c10::optional which is inside options. But if you can try, that would be great.

Copy link
Author

Choose a reason for hiding this comment

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

std::move couldn't build once for me locally, then it started building -- not sure if it's a flaky failure. I've pushed this and if the CI fails, then I'll go back to pass-by-reference

This PR adds a C++ implementation of the TripletMarginWithDistanceLoss, for which the Python implementation was introduced in PR #43680.  It's based on PR #44072, but I'm resubmitting this to unlink it from Phabricator.

cc: @mruberry @albanD @glaringlee 

[ghstack-poisoned]
ethch18 added a commit that referenced this pull request Sep 29, 2020
ghstack-source-id: 6cd50e4f3c80baa39723fcb129366a442bfa26f1
Pull Request resolved: #45377
@codecov
Copy link

codecov bot commented Sep 29, 2020

Codecov Report

Merging #45377 into gh/ethch18/5/base will decrease coverage by 0.40%.
The diff coverage is n/a.

Impacted file tree graph

@@                  Coverage Diff                  @@
##           gh/ethch18/5/base   #45377      +/-   ##
=====================================================
- Coverage              68.56%   68.15%   -0.41%     
=====================================================
  Files                    405      396       -9     
  Lines                  51937    51131     -806     
=====================================================
- Hits                   35610    34849     -761     
+ Misses                 16327    16282      -45     
Impacted Files Coverage Δ
torch/optim/sgd.py 73.91% <0.00%> (-19.57%) ⬇️
torch/optim/rmsprop.py 74.57% <0.00%> (-15.26%) ⬇️
torch/utils/_benchmark/utils/compare.py 89.50% <0.00%> (-7.84%) ⬇️
torch/optim/adamw.py 83.05% <0.00%> (-6.78%) ⬇️
torch/utils/_benchmark/utils/common.py 90.90% <0.00%> (-5.50%) ⬇️
torch/optim/asgd.py 90.24% <0.00%> (-2.44%) ⬇️
torch/optim/adadelta.py 86.04% <0.00%> (-2.33%) ⬇️
torch/testing/_internal/common_nn.py 83.33% <0.00%> (-2.21%) ⬇️
torch/optim/adamax.py 85.10% <0.00%> (-2.13%) ⬇️
torch/onnx/symbolic_opset8.py 28.65% <0.00%> (-1.35%) ⬇️
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7cde662...023aa43. Read the comment docs.

@glaringlee
Copy link
Contributor

@ethch18
All CI builds passed (rocm test failure is fine). I am going to build this on my end locally, will approve this if it passed. Thanks a lot for contributing.

@ethch18
Copy link
Author

ethch18 commented Sep 29, 2020

@glaringlee great! FYI, Mike asked me to incorporate the changes from PR #45378 into this one too, which I'll do shortly

@glaringlee
Copy link
Contributor

@ethch18 sure, go ahead!

This PR adds a C++ implementation of the TripletMarginWithDistanceLoss, for which the Python implementation was introduced in PR #43680.  It's based on PR #44072, but I'm resubmitting this to unlink it from Phabricator.

cc: @mruberry @albanD @glaringlee 

[ghstack-poisoned]
ethch18 added a commit that referenced this pull request Sep 29, 2020
ghstack-source-id: 13b4775af1a0e433ec85310c9d127581b0502277
Pull Request resolved: #45377
@ethch18 ethch18 removed the request for review from apaszke September 29, 2020 15:43
@ethch18
Copy link
Author

ethch18 commented Sep 29, 2020

@glaringlee updated -- let me know if you need anything else from my end!

@glaringlee
Copy link
Contributor

@ethch18
Thanks, can you please rebase your code once? There are several CI test failed, I think that's upstream problems, rebase should solve it.

This PR adds a C++ implementation of the TripletMarginWithDistanceLoss, for which the Python implementation was introduced in PR #43680.  It's based on PR #44072, but I'm resubmitting this to unlink it from Phabricator.

cc: @mruberry @albanD @glaringlee 

[ghstack-poisoned]
ethch18 added a commit that referenced this pull request Sep 29, 2020
ghstack-source-id: f0ea5ff8fa766154cb7bf240bc4620ba0b66443f
Pull Request resolved: #45377
@ethch18
Copy link
Author

ethch18 commented Sep 29, 2020

@glaringlee Just rebased on fbcode/warm

@glaringlee
Copy link
Contributor

@ethch18
Sry, can you rebase again, this code still failed one of our CI test: pytorch_xla_linux_bionic_py3_6_clang9_build.

This PR adds a C++ implementation of the TripletMarginWithDistanceLoss, for which the Python implementation was introduced in PR #43680.  It's based on PR #44072, but I'm resubmitting this to unlink it from Phabricator.

cc: @mruberry @albanD @glaringlee 

[ghstack-poisoned]
@ethch18
Copy link
Author

ethch18 commented Sep 29, 2020

@glaringlee rebased with fbcode/warm again. If this doesn't work, I'll try viable/strict next

ethch18 added a commit that referenced this pull request Sep 29, 2020
ghstack-source-id: 9b60cfa8377a8a4dfa60a3e1955eb710881a7f8a
Pull Request resolved: #45377
@glaringlee
Copy link
Contributor

@ethch18
Thanks, it should work. There is a know issue for our XLA build, it can be solved by rebase.

Copy link
Contributor

@glaringlee glaringlee left a comment

Choose a reason for hiding this comment

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

LGTM now

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in c9bb990.

@facebook-github-bot facebook-github-bot deleted the gh/ethch18/5/head branch October 4, 2020 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merged open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Generic Triplet-Margin Loss
6 participants