# Torch.round() gradient

**URL:** <https://discuss.pytorch.org/t/torch-round-gradient/28628>\
**Category:** autograd\
**Created:** [November 2, 2018, 10:08pm UTC](https://discuss.pytorch.org/t/torch-round-gradient/28628 "2018-11-02T22:08:46Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Zhongzhi\_Yu](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zhongzhi_yu/32/31316_2.png) [@Zhongzhi\_Yu](https://discuss.pytorch.org/u/Zhongzhi_Yu)\
**Post date:** [April 20, 2021, 7:59am UTC](https://discuss.pytorch.org/t/torch-round-gradient/28628/6 "2021-04-20T07:59:11Z")

</div>

One possible approach is to implement your own round function with customized backpropagation.

E.g.

```auto
class my_round_func(InplaceFunction):
    @staticmethod
    def forward(ctx, input):
        ctx.input = input
        return torch.round(input)

    @staticmethod
    def backward(ctx, grad_output):
        grad_input = grad_output.clone()
        return grad_input

```

---

_[View the full topic](https://discuss.pytorch.org/t/torch-round-gradient/28628)._
