Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: partially initialized module 'torch_pruning' has no attribute 'DependencyGraph' #383

Closed
nbansal90 opened this issue Jun 3, 2024 · 1 comment

Comments

@nbansal90
Copy link

nbansal90 commented Jun 3, 2024

I am just beginning to setup the repository. Getting this error running the sample code provided in the Readme.

AttributeError: partially initialized module 'torch_pruning' has no attribute 'DependencyGraph'

CODE RUNNING

import torch
from torchvision.models import resnet18
import torch_pruning as tp

model = resnet18(pretrained=True).eval()

# 1. Build dependency graph for resnet18
DG = tp.DependencyGraph().build_dependency(model, example_inputs=torch.randn(1,3,224,224))

# 2. Group coupled layers for model.conv1
group = DG.get_pruning_group( model.conv1, tp.prune_conv_out_channels, idxs=[2, 6, 9] )

# 3. Prune grouped layers altogether
if DG.check_pruning_group(group): # avoid full pruning, i.e., channels=0.
    group.prune()

# 4. Save & Load
model.zero_grad() # clear gradients
torch.save(model, 'model.pth') # We can not use .state_dict as the model structure is changed.
model = torch.load('model.pth') # load the pruned model

Any help/suggestions greatly appreciated!

@janthmueller
Copy link

Do you have another file/module called torch_pruning in your project? This might be the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants