# Defining my own loss function, I found that the customized loss function only includes the forward function, does the network will do backpropagation automatically? The same condition as activation function

**URL:** <https://discuss.pytorch.org/t/defining-my-own-loss-function-i-found-that-the-customized-loss-function-only-includes-the-forward-function-does-the-network-will-do-backpropagation-automatically-the-same-condition-as-activation-function/31794>\
**Category:** vision\
**Created:** [December 10, 2018, 10:21pm UTC](https://discuss.pytorch.org/t/defining-my-own-loss-function-i-found-that-the-customized-loss-function-only-includes-the-forward-function-does-the-network-will-do-backpropagation-automatically-the-same-condition-as-activation-function/31794 "2018-12-10T22:21:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hdjsjyl](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/h/e47774/32.png) [@hdjsjyl](https://discuss.pytorch.org/u/hdjsjyl)\
**Post date:** [December 10, 2018, 10:21pm UTC](https://discuss.pytorch.org/t/defining-my-own-loss-function-i-found-that-the-customized-loss-function-only-includes-the-forward-function-does-the-network-will-do-backpropagation-automatically-the-same-condition-as-activation-function/31794/1 "2018-12-10T22:21:20Z")

</div>

Defining my own loss function, I found that the customized loss function only includes the forward function, does the network will do backpropagation automatically? The same condition as activation function. Any advice will be appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![varunagrawal](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/varunagrawal/32/384_2.png) [@varunagrawal](https://discuss.pytorch.org/u/varunagrawal)\
**Post date:** [December 10, 2018, 10:55pm UTC](https://discuss.pytorch.org/t/defining-my-own-loss-function-i-found-that-the-customized-loss-function-only-includes-the-forward-function-does-the-network-will-do-backpropagation-automatically-the-same-condition-as-activation-function/31794/2 "2018-12-10T22:55:34Z")

</div>

Yes.  
This is the beauty of automatic differentiation in that as long as you use PyTorch operators and don’t break the computation graph between the previous layer and next layer, the network will perform backprop automatically.

---

<div class="post-metadata">

**Author:** ![hdjsjyl](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/h/e47774/32.png) [@hdjsjyl](https://discuss.pytorch.org/u/hdjsjyl)\
**Post date:** [December 10, 2018, 11:07pm UTC](https://discuss.pytorch.org/t/defining-my-own-loss-function-i-found-that-the-customized-loss-function-only-includes-the-forward-function-does-the-network-will-do-backpropagation-automatically-the-same-condition-as-activation-function/31794/3 "2018-12-10T23:07:15Z")

</div>

Thanks for your reply. It is very useful for me. I am a newer. How to know whether my operation break the computation graph or not.
