Change the data type in a tensor without losing the gradient function

Viewed 12

I'm trying to alter the data type in a tensor I have from torch.float32 to torch.uint8 to perform a posterizing effect on the tensor. However, once the data type is changed the tensor loses its grad fn.

y = x.type(torch.uint8)

x has a grad fn, y does not. Is there a way to keep the grad function when changing the data type?

0 Answers
Related