Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the gradient of pytorch floor() gradient method?

I am looking to use floor() method in one of my models. I would like to understand what pytorch does with its gradient propagation since as such floor is a discontinuous method.

If there is no gradient defined, I could override the backward method to define my own gradient as necessary but I would like to understand what the default behavior is and the corresponding source code if possible.

import torch

x = torch.rand(20, requires_grad=True)
y = 20*x
z = y.floor().sum()
z.backward()

x.grad returns zeros.

z has a grad_fn=

So FloorBackward is the gradient method. But there is no reference to the source code of FloorBackward in pytorch repository.

like image 511
theFakeSheikS Avatar asked Oct 27 '25 08:10

theFakeSheikS


1 Answers

As the floor function is piece wise constant. This means the gradient must be zero almost everywhere.

While the code doesn't say anything about it, I expect that the gradient is set to a constant zero everywhere.

like image 75
flawr Avatar answered Oct 28 '25 23:10

flawr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!