The error might have been raised, if you tried to compute gradients from already updated parameters and thus stale intermediate activations as explained in the linked post.
Did you compare your current code logic to the example I’ve posted in the other topic?