How the derivative of round, ceil, and floor function defined in pytorch?

you can write test to determine there evaluation.

Mathematically one would assume that derivative of ceil, round and floor is not determined for integers, but everywhere else the derivative will be zero, since these functions convert any function to a step function of a sort. The torch derivative of these function is just zero for the whole function.

def test(x, f):

\t p = torch.tensor(x).float().requires_grad_();

\t f( p ).backward()

\t return float(p.grad())

Some samples:

test(-1.2, torch.round) = 0.0

test(-1.2, torch.ceil) = 0

1 Like