开始使用免费开始使用

Finalize pruning by removing the mask

After pruning a model, you need to finalize it before saving or deploying. This means removing the pruning mask so the model no longer tracks which weights were zeroed. You'll use prune.remove() to complete this step.

本练习是课程的一部分

Scalable AI Models with PyTorch Lightning

查看课程

练习说明

  • Finalize the pruning of the weight parameter.
  • Use prune.remove() to remove the mask and store the final weights.
  • Print the model to confirm pruning removal.

交互式实操练习

通过完成这段示例代码来试试这个练习。

import torch.nn.utils.prune as prune
# Before pruning
print(model)
# Finalize pruning by removing the pruning mask
prune.____(model[3], "____")
# Print model structure after pruning
print(____)
编辑并运行代码