Can you share that code? I don’t see any call to backward/grad here.
Also you should only set that flag for Tensors for which you want gradients to be computed. If you have to set it on an intermediary results, the backprop will stop there and not go any further.