hiyoung123/SoftMaskedBert

loss.backward(retain_graph=True) 报错

mrb957600057 opened this issue · 3 comments

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [768]] is at version 3; expected version 2 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

请问您有遇到这个问题吗?

版本问题,切换到1.4没问题

版本问题,切换到1.4没问题

请教下,如果还是保持1.5的版本,要修改哪里的代码呢?

版本问题,切换到1.4没问题

请教下,如果还是保持1.5的版本,要修改哪里的代码呢?

self.mask_e = self.embedding(mask_token_id)

改成

self.mask_e = self.embedding(mask_token_id).detach()