How does NoGradGuard works in Cpp?

Hi,

It actually sets a global flag that is checked by the backend whenever an op is done on a variable.
The guard itself saved the current status and set it to false in the constructor. And restore the saved status in it’s destructor. That way it is similar to a with torch.no_grad(): block in python.

4 Likes