Hi Adele!
This is telling you that fc2.weight
is the tensor that is being modified inplace.
Note that its ._version
has jumped to 6251
, indicating that it’s been modified
inplace 6250
times before the call to .backward()
that is triggering the error.
You need to think through your training algorithm. As we’ll see below, you compute
a loss
, call a training loop (that presumably calls an opt.step()
multiple times),
and then call loss.backward()
. opt.step()
modifies inplace the parameters that
it is optimizing, causing the error.
Does it really make sense for your algorithm to stick a training loop in between
the computation of loss
and the call to loss.backward()
?
The inplace operation is presumably a call to opt.step()
that isn’t shown in
the code you’ve posted, but is presumably buried somewhere in:
trainer.run(train_dataloader, max_epochs=params.num_epochs)
This creates fc2
with a weight
of shape [1, 128]
. The inplace-modification error
reports the transpose of this shape, namely, [128, 1]
.
Note that this comment in the code you posted warns that some “network
parameters will be changed in place,” tipping you off to the possibility of an
inplace-modification error.
We noted above that the error message tells you that fc2.weight
was
modified inplace 6250
times. This would makes sense if your inner training
loop calls some opt.step()
6250
times as it iterates.
For some examples that illustrate how to debug inplace-modification errors,
see this post:
Good luck!
K. Frank