1. Learn
  2. /
  3. Courses
  4. /
  5. Scalable AI Models with PyTorch Lightning

Connected

Exercise

Apply pruning to a linear layer

We've trained an image classification model using a fully connected (linear) layer. Now, we're tasked with applying unstructured pruning to this layer to reduce model size without significantly impacting performance. We'll use PyTorch's l1_unstructured method for this task.

Model is pre-loaded as in model variable.

Instructions

100 XP
  • Import the pruning module from torch.nn.utils.
  • Apply l1_unstructured pruning to model[3], the final layer, and prune 30% of the weights.