# nn.CrossEntropyLoss: - optimizer not updating weights

**URL:** <https://discuss.pytorch.org/t/nn-crossentropyloss-optimizer-not-updating-weights/158620>\
**Category:** vision\
**Created:** [August 8, 2022, 5:21pm UTC](https://discuss.pytorch.org/t/nn-crossentropyloss-optimizer-not-updating-weights/158620 "2022-08-08T17:21:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![blackbirdbarber](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@blackbirdbarber](https://discuss.pytorch.org/u/blackbirdbarber)\
**Post date:** [August 8, 2022, 6:46pm UTC](https://discuss.pytorch.org/t/nn-crossentropyloss-optimizer-not-updating-weights/158620/2 "2022-08-08T18:46:00Z")

</div>

> [@avalon1511](#):
>
> `element 0 of tensors does not require grad and does not have a grad_fn`

[Check this one](https://discuss.pytorch.org/t/runtimeerror-element-0-of-variables-does-not-require-grad-and-does-not-have-a-grad-fn/11074). Your can check `input.requires_grad` and if not `True` this is the problem.

Note: `input.requires_grad=True` all Tensors computed from `input` will have `requires_grad` attribute True. It is like covid-19.

This way you can fool a pretrained network to change its prediction by modifying the input features.

---

_[View the full topic](https://discuss.pytorch.org/t/nn-crossentropyloss-optimizer-not-updating-weights/158620)._
