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

[OpInfo] add reference and error inputs for multi_margin_loss #104850

Closed
wants to merge 4 commits into from

Conversation

@pytorch-bot
Copy link

pytorch-bot bot commented Jul 9, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/104850

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 945cc67:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@nkaretnikov
Copy link
Collaborator Author

Summary:

  • Adds tests for negative margin and reductions to sample inputs.
  • Adds reference and error inputs.
  • Removes redundant tests from other files.
  • No tests for weight because there are added in subsequent PRs (to make it easier to review).

@@ -9297,7 +9297,6 @@ def v(fn):

v(lambda: F.nll_loss(input, target, reduction=reduction))
v(lambda: F.cross_entropy(input, target, reduction=reduction))
v(lambda: F.multi_margin_loss(input, target, reduction=reduction))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Invalid reductions are tested in error inputs now.

def test_multi_margin_loss_errors(self, device):
self.assertRaises(RuntimeError,
lambda: nn.functional.multi_margin_loss(torch.randn(5, device=device),
torch.zeros(3, device=device)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Invalid shapes are tested in error inputs now.

for target in (torch.tensor(0, device=device), torch.tensor([0], device=device)):
self.assertEqual(target.shape, torch.nn.functional.multi_margin_loss(input, target, reduction='none').shape)
self.assertEqual((), torch.nn.functional.multi_margin_loss(input, target, reduction='mean').shape)
self.assertEqual((), torch.nn.functional.multi_margin_loss(input, target, reduction='sum').shape)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Valid shapes/scalars were already tested in sample inputs.

error_regex=(
r'inconsistent target size, expected 5 but got \[5, 4\]'
if torch.device(device).type == 'cuda' else
r'inconsistent target size, got: \[5, 4\]'))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This error-message-divergence is fixed in the next PR in the stack.

@nkaretnikov nkaretnikov requested a review from ezyang July 13, 2023 01:17
@nkaretnikov nkaretnikov marked this pull request as ready for review July 13, 2023 01:17
@facebook-github-bot facebook-github-bot deleted the gh/nkaretnikov/149/head branch July 18, 2023 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged open source topic: not user facing topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants