MrPositron
(Nauryzbay K)
February 9, 2021, 6:13pm
1
I want to clone the model. However, PyTorch fails to detach and clone the model.
temp_enc = model.encoder_net.detach().clone()
Error I get
torch.nn.modules.module.ModuleAttributeError: 'Encoder' object has no attribute 'detach'
When I clone without detaching I receive similar error:
torch.nn.modules.module.ModuleAttributeError: 'Encoder' object has no attribute 'clone'
albanD
(Alban D)
February 9, 2021, 6:23pm
2
Hi,
Both clone and detach are constructs on Tensors, not nn.Modules.
If you want to make an independent copy of a model, you can use the regular python deepcopy.
1 Like
MrPositron
(Nauryzbay K)
February 9, 2021, 6:27pm
3
Thanks! Stupid mistake. My bad.
Unfortunately, deepcopy throws the following error:
“Only Tensors created explicitly by the user (graph leaves) support the deepcopy protocol at the moment”
UPD: Actually deepcopy
on model.state_dict()
works fine! Thanks anyway.
1 Like