functorch icon indicating copy to clipboard operation
functorch copied to clipboard

.with_buffers are really work?

Open bwnjnOEI opened this issue 2 years ago • 4 comments

I use torch.nn.utils.prune to pruning model, and it generates a mask buffer. However, when I use make_functional_with_buffers, the error is RuntimeError: Only Tensors created explicitly by the user (graph leaves) support the deepcopy protocol at the moment. Is it because of the use of deepcopy, or am I missing something?

My test code as follows:

import torch
import torch.nn as nn
from torch.nn.utils.prune import l1_unstructured
from functorch import make_functional_with_buffers

m = nn.Linear(100,100)
l1_unstructured(m, 'weight', amount=0.5)
print(m.weight_mask.is_leaf)
func, params, buffers = make_functional_with_buffers(m)

Pls, help!

bwnjnOEI avatar Apr 19 '22 19:04 bwnjnOEI

I remove-register_buffer like this

prune.remove(m, 'weight')
m.register_buffer('weight_mask', mask)

It worked, but I don't understand why?

bwnjnOEI avatar Apr 19 '22 19:04 bwnjnOEI

I'm not sure what is going on here, but we'll take a deeper look

zou3519 avatar Apr 21 '22 16:04 zou3519

I have a basic question: When we use .make_functional_with_buffers or .make_functional to extract func and params, can we also associate and copy the execution of ._forward_pre_hooks in module?

bwnjnOEI avatar Apr 22 '22 02:04 bwnjnOEI

I'm not sure -- does _forward_pre_hooks get copied by deepcopy?

In general functorch doesn't work very well with module hooks at the moment

zou3519 avatar Apr 22 '22 18:04 zou3519