You have to read the pytorch documentation. The detach()
method is part of the definition of the Tensor class.
It was also discussed in the “Intro to PyTorch” assignment in Week 1 of GANs C1.
Here’s a thread which discusses why we do the detach in some cases and not in others.