VainF / Torch-Pruning

[CVPR 2023] Towards Any Structural Pruning; LLMs / SAM / Diffusion / Transformers / YOLOv8 / CNNs
https://arxiv.org/abs/2301.12900
MIT License
2.45k stars 309 forks source link

IndexError: index 512 is out of bounds for dimension 0 with size 512 #342

Open TianGao-NJUST opened 4 months ago

TianGao-NJUST commented 4 months ago

imp = tp.importance.MagnitudeImportance(p=1) example_inputs = torch.randn(1, 3, 224, 224) ignored_layers = [] for m in model.modules(): if isinstance(m, torch.nn.Linear) and m.out_features == args.nb_classes: ignored_layers.append(m) # DO NOT prune the final classifier!

iterative_steps = 1 # 
pruner = tp.pruner.MagnitudePruner(
    model,
    example_inputs, # 
    importance=imp, # 
    iterative_steps=iterative_steps, #
    ch_sparsity=0.5, # 
    ignored_layers=ignored_layers, # 
)

4. Pruning-Finetuning的循环

base_macs, base_nparams = tp.utils.count_ops_and_params(model, example_inputs)
for i in range(iterative_steps):
    # pruner.step()
    for group in pruner.step(interactive=True): # Warning: groups must be handled sequentially. Do not keep them as a list.
        print(group.details()) # 
    # 
        group.prune() 
    macs, nparams = tp.utils.count_ops_and_params(model, example_inputs)
VainF commented 4 months ago

Hello @812985728, could you provide the model name in your case?

TianGao-NJUST commented 4 months ago

hello, the model is designed by me, which based on deit , the problem occurs in MLP module。 

812985728 @.***

 

------------------ 原始邮件 ------------------ 发件人: "Rémi @.>; 发送时间: 2024年2月23日(星期五) 下午2:31 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [VainF/Torch-Pruning] IndexError: index 512 is out of bounds for dimension 0 with size 512 (Issue #342)

Hello @812985728, could you provide the model name in your case?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>