I am new to pytorch and am trying to reduce the consumption usage of GPUs. What I am trying to do is to update the weights manually. In this sense, I am getting the new gradient values. Then, I update the weights as follows:
grads = torch.autograd.grad(
d_loss, weights.values(), create_graph=True, allow_unused=True
)
weights = OrderedDict(
(name, param - grad) if grad is not None else (name, param)
for ((name, param), grad) in zip(weights.items(), grads)
)
The problem here is that I do need to update the weights without making the gradient to be true, as it increases the GPU consumption usage without a need for it.
When I changed the second line as follows:
with torch.no_grad():
for ((name, param), grad) in zip(weights.items(), grads):
if grad is not None:
param -= grad
However, it gives me the following message:
assert len(optimizer_state["found_inf_per_device"]) > 0, "No inf checks were recorded for this optimizer."
AssertionError: No inf checks were recorded for this optimizer
What I do not understand why this even occurs. I just tried to make the updates inplace without a need for the gradient to be true. Any help?