out = self.student(*inputs)
self.last_students_logits = out.new_tensor(out, requires_grad=True)
out = self.student(*inputs)
self.last_students_logits = out.clone()
new_tensor 其默认参数下的操作等同于.clone().detach(),
而requires_grad=True 时的效果相当于.clone().detach().requires_grad_(True)
More
1 对比clone、detach以及copy_等张量复制操作
2 https://blog.csdn.net/qq_40438388/article/details/106860180
本文深入探讨了PyTorch中张量的几种关键操作:clone、detach及copy_,并详细解释了它们之间的差异及应用场景。通过具体代码示例,读者可以更好地理解这些操作如何影响张量的梯度计算和内存分配。
829

被折叠的 条评论
为什么被折叠?



