发生异常: RuntimeError
element 0 of tensors does not require grad and does not have a grad_fn
File "/data/wangqianle/zlq/DEALRec/DEALRec-main/code/prune/effort_util.py", line 706, in training_step
self.accelerator.backward(torch.mean(loss), retain_graph=True)
File "/data/wangqianle/zlq/DEALRec/DEALRec-main/code/prune/effort_util.py", line 654, in _inner_training_loop
gradient = self.training_step(model, inputs)
File "/data/wangqianle/zlq/DEALRec/DEALRec-main/code/prune/effort_util.py", line 361, in get_grad
return inner_training_loop(
File "/data/wangqianle/zlq/DEALRec/DEALRec-main/code/prune/effort_score.py", line 199, in get_effort_score
gradients = trainer.get_grad(resume_from_checkpoint=resume_from_checkpoint)
File "/data/wangqianle/zlq/DEALRec/DEALRec-main/code/prune/prune.py", line 15, in
effort = get_effort_score(args)
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
运行prune.py时,计算effort_score时,出现以下错误:
发生异常: RuntimeError element 0 of tensors does not require grad and does not have a grad_fn File "/data/wangqianle/zlq/DEALRec/DEALRec-main/code/prune/effort_util.py", line 706, in training_step self.accelerator.backward(torch.mean(loss), retain_graph=True) File "/data/wangqianle/zlq/DEALRec/DEALRec-main/code/prune/effort_util.py", line 654, in _inner_training_loop gradient = self.training_step(model, inputs) File "/data/wangqianle/zlq/DEALRec/DEALRec-main/code/prune/effort_util.py", line 361, in get_grad return inner_training_loop( File "/data/wangqianle/zlq/DEALRec/DEALRec-main/code/prune/effort_score.py", line 199, in get_effort_score gradients = trainer.get_grad(resume_from_checkpoint=resume_from_checkpoint) File "/data/wangqianle/zlq/DEALRec/DEALRec-main/code/prune/prune.py", line 15, in
effort = get_effort_score(args)
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
transformers版本是4.32.1,按照DEALRec.yaml来配置的。