# How can I disable all layers gradient expect the last layer in Pytorch?

**URL:** <https://discuss.pytorch.org/t/how-can-i-disable-all-layers-gradient-expect-the-last-layer-in-pytorch/53043>\
**Category:** Uncategorized\
**Created:** [August 10, 2019, 5:46am UTC](https://discuss.pytorch.org/t/how-can-i-disable-all-layers-gradient-expect-the-last-layer-in-pytorch/53043 "2019-08-10T05:46:18Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Shisho\_Sama](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/shisho_sama/32/6926_2.png) [@Shisho\_Sama](https://discuss.pytorch.org/u/Shisho_Sama)\
**Post date:** [August 11, 2019, 6:05pm UTC](https://discuss.pytorch.org/t/how-can-i-disable-all-layers-gradient-expect-the-last-layer-in-pytorch/53043/5 "2019-08-11T18:05:17Z")

</div>

Its very weird! both your code and also!`fc.parameters()` are now working just fine!!!  
This has got me confused for two days! and now they are just working fine!  
I don’t know what could have caused this! or I may have pretty much made a mistake!  
By the way I am running Pytorch 1.0!  
Any way thanks a gazillion times that was a tremendous help.  
By the way do you mind if I ask you to kindly have a look [here](https://discuss.pytorch.org/t/why-doesnt-pytorch-provide-properties-for-class-names/47220/4) as well?

---

_[View the full topic](https://discuss.pytorch.org/t/how-can-i-disable-all-layers-gradient-expect-the-last-layer-in-pytorch/53043)._
