Skip to content

Adversarial training with lightning #14782

Discussion options

You must be logged in to vote

Answering to myself:
After more digging, it seems that it is the use of torch.inference_mode that is the cause of the issue.
Using torch.no_grad is not enough to get out of inference_mode.
In fact getting out of inference_mode with e.g with torch.inference_mode(mode=False) or a decorator is not enough, I then have a problem
with Inference tensors cannot be saved for backward. To work around you can make a clone to get a normal tensor and use it in autograd.

For now the solution I have is to change the function

@contextmanager
def _evaluation_context(accelerator: Accelerator) -> Generator:
   # inference mode is not supported with gloo backend (#9431),
   # and HPU & TPU accelerators.
   c…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
1 reply
@akihironitta
Comment options

Answer selected by sergedurand
Comment options

You must be logged in to vote
7 replies
@sergedurand
Comment options

@khalooei
Comment options

@khalooei
Comment options

@sergedurand
Comment options

@khalooei
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment