Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Check shape instead of number of elements for some losses#5085

Merged
soumith merged 2 commits into
pytorch:masterfrom
zou3519:loss-size-checks
Feb 7, 2018
Merged

Check shape instead of number of elements for some losses#5085
soumith merged 2 commits into
pytorch:masterfrom
zou3519:loss-size-checks

Conversation

@zou3519
Copy link
Copy Markdown
Contributor

@zou3519 zou3519 commented Feb 6, 2018

Fixes #5007
Fixes #4938

Removes the check that the input, target have the same number of elements and adds a shape check instead for the following:

  • mse_loss
  • l1_loss
  • smooth_l1_loss
  • kl_div

At some point it would be nice to move these to ATen and perhaps enable broadcasting on them, but right now this is just a bugfix.

Test Plan

new unit test

@zou3519 zou3519 changed the title Check shape instead of number of elements Check shape instead of number of elements for some losses Feb 6, 2018
@soumith
Copy link
Copy Markdown
Collaborator

soumith commented Feb 6, 2018

the documentation of MSELoss is clear about this behavior:

x and y arbitrary shapes with a total of n elements each.

If the right "fix" is to remove this behavior, the documentation has to be updated.

@soumith soumith merged commit ccb61e0 into pytorch:master Feb 7, 2018
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
* Check shape instead of number of elements

* Remove arbitrary-shape spec in MSELoss docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nn.L1Loss takes input, target tensors that don't have broadcastable sizes F.mse_loss has strange broadcasting semantics

2 participants