# Build your own loss function in PyTorch

**URL:** <https://discuss.pytorch.org/t/build-your-own-loss-function-in-pytorch/235>\
**Category:** Uncategorized\
**Created:** [January 28, 2017, 11:07am UTC](https://discuss.pytorch.org/t/build-your-own-loss-function-in-pytorch/235 "2017-01-28T11:07:05Z")\
**Posts on this page:** 1\
**Showing post:** 30

<div class="post-metadata">

**Author:** ![Xin\_Qian](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/xin_qian/32/435_2.png) [@Xin\_Qian](https://discuss.pytorch.org/u/Xin_Qian)\
**Post date:** [April 10, 2017, 4:02pm UTC](https://discuss.pytorch.org/t/build-your-own-loss-function-in-pytorch/235/30 "2017-04-10T16:02:57Z")

</div>

Hi Adam,

If we were to define our own loss function, and during the middle there’s a sort and index\_copy\_ action that requires Tensor instead of Variable. Seems like unpacking data is unavoidable. Do you have any suggestions? Thanks.

---

_[View the full topic](https://discuss.pytorch.org/t/build-your-own-loss-function-in-pytorch/235)._
