Open BurgerAndreas opened 7 months ago
Hi Andreas @BurgerAndreas ,
Thanks a lot for your interest! I think a quick fix is to enable self.deq
to be in the train
mode while other components of the model are in eval
mode.
I appreciate the suggestion! I think we can implement such a feature into the lib. Feel free to submit a PR. I'll be back to close this issue soon.
Thanks, Zhengyang
It's a very nieche problem, but tripped me over big time :')
Issue
For
model.eval()
,z_pred
will not have tracked gradients (z_pred.requires_gradient==False
). For custom torch.autograd this will lead to an error:RuntimeError: One of the differentiated Tensors does not require grad
.Minimal example
While
model.train()
it will work perfectly well. Formodel.eval()
we get the error:RuntimeError: One of the differentiated Tensors does not require grad
.Desired behaviour
A flag to set such that
z_pred[-1].requires_grad
is alwaysTrue
, even whenmodel.eval()
.self.deq = get_deq(grad_in_eval=True)