Skip to content

Unhelpful CrossEntropyLoss dimension error message #1328

Open

Description

@jsuarez5341

I believe I've stumbled upon a slight whoops in nn.CrossEntropyLoss(). If the criterion is called with (a, y) where a in (N, C) and y in (N) such that some yi > C, I get the internal error message below (took a while to parse)... seems like this could use a wrapper. A simple note following the internal error would suffice--how about: "Ensure the class dimension of the predictions matches the class dimension of the targets" ?

THCudaCheck FAIL file=/py/conda-bld/pytorch_1490903321756/work/torch/lib/THC/generic/THCTensorCopy.c line=65 error=59 : device-side assert triggered

System: Ubuntu 16.06, Python 3.6 (conda install).

cc @ngimel

Activity

  1. apaszke commented on Apr 24, 2017

    @apaszke
    Contributor

    There's no way to do that. CUDA doesn't allow adding error messages to asserts, and it's the least invasive way (perf wise) in which we can catch these errors 😕

  2. jsuarez5341 commented on Apr 26, 2017

    @jsuarez5341
    Author

    That's understandable but also horrifying considering "We hope you never spend hours debugging your code because of bad stack traces or asynchronous and opaque execution engines." Not exactly a stack trace, but even harder to parse. Would it make sense to add an option to turn on more expensive logging? Didn't see something like that already in place in the main documentation.

  3. soumith commented on Apr 26, 2017

    @soumith
    Collaborator

    we've thought about this very hard. there is a hard technical limitation in the cuda api on device asserts. However, it is possible that we can try improve a generic error message when device asserts are triggered that roughly covers all asserts. I'll improve this

  4. marcj commented on Apr 26, 2017

    @marcj

    In software development, one of the most important things are good error messages. UX suffers dramatically when you need to spent hours to find out, you made a relatively stupid user/api error. Also, if performance is more important than UX/DX than Pytorch should introduce a developer/debug mode, where the lib spends a bit more time in generating self explaining and good error messages - if activated. It's really the key to be most efficient and not to waste time.

  5. soumith commented on Apr 26, 2017

    @soumith
    Collaborator

    thanks for your advice. we understand and know what you are saying. as an open source project we are bootstrapped for resources and always have to prioritize things.
    if you have time, feel free to improve error messages in pytorch, we even have a list of known bad error messages that need to be improved in #39

  6. jsuarez5341 commented on Apr 26, 2017

    @jsuarez5341
    Author

    Hey, PyTorch is great already--I recently migrated everything over from TensorFlow in half the code and 1/5 the time. I can certainly help write better error messages, but I am a researcher with little to no experience deving on large frameworks. I realize that priorities have to be set--my hope is just that this thread is kept somewhere for eventual consideration, as there's definitely another 2-3X productivity to be squeezed out of debugging time. Seconded that a developer/debug mode should be introduced at some point

  7. jekbradbury commented on Apr 27, 2017

    @jekbradbury
    Contributor

    I think a generic "device-side assert triggered: perhaps you have an out-of-bounds index? try running on CPU" would be a good first step. Chainer has a full-fledged debug mode that catches OOB and NaNs, but I don't think that provides all that much that running on CPU wouldn't.

  8. 1 remaining item

  9. added
    feature
    and removed on Apr 1, 2019
  10. fmassa commented on Oct 23, 2019

    @fmassa
    Member

    This is being worked on in #26776

  11. added
    module: cuda
    triaged
    and removed on Oct 23, 2019
  12. added
    module: error checking
    module: loss
    and removed
    feature
    on Oct 10, 2020
  13. added a commit that references this issue on Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: cudamodule: error checkingmodule: losstriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions