Can I change volatile = False to torch.set_grad_enabled(True)??(in Pytorch)
I have old python codes, so I need to change some parts.
next_q_values.volatile=False

I have this code, and next_q_values is 'torch.Tensor'
when I run this code:

error occured: &quot;volatile was removed and now has no effect use with
torch no_grad instead&quot;

After search, I know that volatile = True is same as torch.no_grad(),
but I want to use volatile = False, So I can't use torch.no_grad().
Can I change volatile = False to torch.set_grad_enabled(True)?

If you have:
next_q_values.volatile = False

You can change it to:
with torch.no_grad():
    next_q_values
    ...
    # You do something with next_q_values here

Every operation on next_q_values should be within the scope of context manager.
