locuslab / deq

[NeurIPS'19] Deep Equilibrium Models

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RuntimeError: Only Tensors created explicitly by the user (graph leaves) support the deepcopy protocol at the moment

QiyaoWei opened this issue · comments

MWE below, ran from MDEQ-Vision/tools/test.py (with all the usual imports from tools/cls_train.py). I am wondering whether this behavior is to be expected? If so, which part of the model is not "copy-able"?

import copy
model = eval('models.'+config.MODEL.NAME+'.get_cls_net')(config).float()
copy.deepcopy(model)

Hi @QiyaoWei,

I think this is likely the result of the fact that MDEQ uses weight normalization. As you can see, in WN the weight (computed from the _g and the _v parameters) is created by the program and not directly by the user: https://github.com/locuslab/deq/blob/master/lib/optimizations.py#L258.

There are two ways to solve this: 1) use PyTorch's weight normalization. It is slower for training in DEQs (because it recomputes the weight every time, even though we are using a weight-sharing scheme), which is why I modified it. 2) Save the model to disk with torch.save and then do torch.load, rather than copy.deepcopy. I recommend the second option.

(Is there any reason that you need to use deepcopy?)

Also, I believe in the latest PyTorch 1.11 they modified the behavior of deepcopy in PyTorch (see here). I don't think it's directly related to the error here but it's probably worth checking.

Oh I see! I am currently using functorch to operate on DEQ in my research, and deepcopy is just something that they call in their code make_functional_with_buffers. It's not a difficult problem to resolve, I was mainly curious about what was the cause :) Thanks a lot for the quick reply!