Skip to content

Conversation

@PyExtreme
Copy link

Hi @yf225 , Here is the C++ frontend API TripletMarginLoss implementation and tests #27197 . Could you please review it?

Secondly, the tests got skipped. I ran pytest test/test_cpp_api_parity.py -k Loss -v , and the L1Loss test passed but the others were skipped...

Thanks

@pytorchbot pytorchbot added the module: cpp Related to C++ API label Oct 8, 2019
Copy link
Contributor

@yf225 yf225 left a comment

Choose a reason for hiding this comment

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

@PyExtreme Thanks so much for the awesome work! I left some minor comments.

void TripletMarginLossImpl::pretty_print(std::ostream& stream) const {
stream << "torch::nn::TripletMarginLoss(p=" << options.p() <<
", margin=" << options.margin() <<
", weight=" << options.swap() <<
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean to write swap= instead of weight=? (We will need std::boolalpha for printing boolean value in C++.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also it would be awesome to print in margin=..., p=..., eps=..., swap=..., reduction=... order :D

stream << "torch::nn::TripletMarginLoss(p=" << options.p() <<
", margin=" << options.margin() <<
", weight=" << options.swap() <<
", reduction=" << options.reduction() << ")";
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be awesome to add a test for the pretty_print result :D

const Tensor& positive,
const Tensor& negative);


Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can remove one extra line here

const Tensor& anchor,
const Tensor& positive,
const Tensor& negative,
const TripletMarginLossOptions& options) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since all TripletMarginLossOptions's arguments are optional, we can provide an empty default value for options here:

Suggested change
const TripletMarginLossOptions& options) {
const TripletMarginLossOptions& options = {}) {

to support the triplet_margin_loss(anchor, positive, negative) use case. (We should add a test case for that as well.)

@PyExtreme
Copy link
Author

Hi @yf225 , I have faced some branching issue and therefore, opened a new pull request and fixed all the issues. Please have a look.
#27613
Thank you

@PyExtreme PyExtreme closed this Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: cpp Related to C++ API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants