akcaymert:

directly used Dice_Loss function


You should not do that!
You only need to define forward method and pytorch will take care of backward for you.
I am still insisting on the point that you are having a small typo or something because I can use your first code and everything is just fine!