Grid_sample() returns ZERO gradient with misordered grid

Hi, thanks first for the amazing tools. I am currently trying to use grid_sample() to sample colors from a texture image to be the color of vertices from a 3D .obj model (part of a rendering process), and then the color is used to compute loss and gradients are expected to back-propagate to the texture image. However, in the experiment gradients on the texture image are all zero.

To find out the reason, I replace the grid with an “ordered” one, like those generated by affine_grid(), then the gradients are non-zero. Thus, I am wondering if this is because the original grid is defined by the UV coordinates corresponding to each vertice in the 3D model, and thus there is no regularity in it. I would appreciate if anyone could tell me whether there are certain constraints on defining the grid, or if there may be other reasons that make the grad zero.

Many thanks!!

Hi,
Would you have a small code sample that reproduces this behavior please?

It turns out the gradients are not totally zeros. It’s just updating in a very very low speed. This is a stupid question and I will delete it soon. Thanks and sorry for your time!