This works fine with me:
import torch
from torch import nn
import torchvision.models as models
import torch.nn.utils.prune as prune
resnet18 = models.resnet18(pretrained=True)
parents = [module for module in resnet18.modules()]
leaves = []
while parents != []:
m =  parents.pop(0)
if list(m.children()) == []:
leaves.append(m)

else:
for x in m.modules():

  if list(x.children()) == []:

    leaves.append(x)

  else:

    parents.append(x)

parameters_to_prune = [(module, ‘weight’) for module in leaves\
                   if (isinstance(module, torch.nn.modules.conv.Conv2d) or isinstance(module, torch.nn.modules.Linear))]

prune.global_unstructured(
    parameters_to_prune,

    pruning_method=prune.L1Unstructured,

    amount=0.2)