The error means that one of the tensors that require a gradient has been modified in place. It’s the result of an in-place correctness check 17.
If you change label = label.unsqueeze_(dim=0) to label = label.unsqueeze(dim=0), it should work.
unsqueeze_ 1 is an in-place operation and label is used to compute the loss which you call backward() on. Hence, the error.
As a rule, you cannot use in-place operations on tensors required for gradient computation 21.
(As an aside, label = label.unsqueeze_(dim=0) is redundant. Because it’s an in-place operation, label.unsqueeze_(dim=0) would give the same result without the assignment. Also, Variable is deprecated. Tensors can be used on their own now. See the 0.4 update migration guide.)