mirror of https://github.com/hpcaitech/ColossalAI
[hotfix]fixed bugs of assigning grad states to non leaf nodes (#711)
* fixed bugs of assigning grad states to non leaf nodes * use detach()pull/712/head
parent
eda30a058e
commit
140263a394
|
@ -12,7 +12,7 @@ def copy_to_device(obj, device):
|
||||||
if torch.is_tensor(obj):
|
if torch.is_tensor(obj):
|
||||||
# Notice:
|
# Notice:
|
||||||
# When in no_grad context, requires_gard is False after movement
|
# When in no_grad context, requires_gard is False after movement
|
||||||
ret = obj.to(device)
|
ret = obj.to(device).detach()
|
||||||
ret.requires_grad = obj.requires_grad
|
ret.requires_grad = obj.requires_grad
|
||||||
return ret
|
return ret
|
||||||
elif isinstance(obj, list):
|
elif isinstance(obj, list):
|
||||||
|
|
Loading…
Reference in New Issue