# Query regarding register\_backward\_hook

**URL:** <https://discuss.pytorch.org/t/query-regarding-register-backward-hook/14184>\
**Category:** vision\
**Created:** [March 1, 2018, 7:29am UTC](https://discuss.pytorch.org/t/query-regarding-register-backward-hook/14184 "2018-03-01T07:29:52Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![tom](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tom/32/3162_2.png) [@tom](https://discuss.pytorch.org/u/tom)\
**Post date:** [March 1, 2018, 9:35am UTC](https://discuss.pytorch.org/t/query-regarding-register-backward-hook/14184/3 "2018-03-01T09:35:42Z")

</div>

I don’t think the hook will work as expected (see this recent thread for a discussion of the values of the hook [Exact meaning of grad\_input and grad\_output](https://discuss.pytorch.org/t/exact-meaning-of-grad-input-and-grad-output/14186)).  
If you write the model yourself, you could just use hidden.register\_hook(lambda grad: grad.clamp(min=0)), similar to the [gradient clipping discussed here](https://discuss.pytorch.org/t/implement-cell-gradient-clamp-in-nn-lstm/14135)) on your activations between the layers.

Best regards

Thomas

---

_[View the full topic](https://discuss.pytorch.org/t/query-regarding-register-backward-hook/14184)._
