Skip to content

Conversation

@CarMiranda
Copy link
Contributor

In accordance with #25883, I added the MultiLabelSoftMarginLoss module and multilabel_soft_margin_loss functional.

It looks like there isn't a C++ ATen implementation of multilabel_soft_margin_loss, so I translated the python version, which does not rely on a C/C++ backend either.

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.

Thanks a lot for the fantastic work @CarMiranda! I left some very minor comments.

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

MultiLabelSoftMarginLossImpl::MultiLabelSoftMarginLossImpl(
const torch::nn::MultiLabelSoftMarginLossOptions& options_)
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-tidy seems to complain about this line, and we can do the following to get around it:

Suggested change
const torch::nn::MultiLabelSoftMarginLossOptions& options_)
const torch::nn::MultiLabelSoftMarginLossOptions& options_) // NOLINT(modernize-pass-by-value)

@yf225
Copy link
Contributor

yf225 commented Oct 11, 2019

@pytorchbot rebase this please

/// Creates a criterion that optimizes a multi-label one-versus-all
/// loss based on max-entropy, between input :math:`x` and target :math:`y` of size
/// :math:`(N, C)`.
struct TORCH_API MultiLabelSoftMarginLossImpl : Module {
Copy link
Contributor

@yf225 yf225 Oct 11, 2019

Choose a reason for hiding this comment

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

My sincere apologies for missing this earlier: for all torch::nn layers we will need to subclass it from Cloneable in the following way:

Suggested change
struct TORCH_API MultiLabelSoftMarginLossImpl : Module {
struct TORCH_API MultiLabelSoftMarginLossImpl : public torch::nn::Cloneable<MultiLabelSoftMarginLossImpl> {

otherwise module->clone() won't work on them. I think for all currently open PRs we should change this, and I will fix the modules that are already in the codebase (e.g. L1Loss).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, no problem! Thanks for the review!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@yf225 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@yf225 merged this pull request in 2cae392.

thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this pull request Feb 4, 2020
Summary:
In accordance with pytorch#25883, I added the `MultiLabelSoftMarginLoss` module and `multilabel_soft_margin_loss` functional.

It looks like there isn't a C++ ATen implementation of `multilabel_soft_margin_loss`, so I translated the python version, which does not rely on a C/C++ backend either.
Pull Request resolved: pytorch#27669

Differential Revision: D17907608

Pulled By: yf225

fbshipit-source-id: ccb02951e009973c2adbe604593ce929f10c39eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: cpp Related to C++ API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants