Does ctx.save_for_backward() do anything in inference mode?

Hi,
When defining custom Function class, we define static forward()/backward() methods, and in forward() we use ctx.save_for_backward(…) to record the input tensors for backward pass.

I’m wondering, when in inference mode (training = false), will the above ctx.save_for_backward(…) call still record the tensors for the never arriving backward pass?

Thank you!

Based on this response from @albanD it should not save any tensors if it’s executed in a with torch.no_grad() context (and I would also assume the same for with torch.inference_mode()).

1 Like

Thanks! Didn’t realized there was a similar question.