Identity#
- class torch.nn.utils.prune.Identity[源]#
实用剪枝方法,不剪枝任何单元,但生成一个全为1的掩码的剪枝参数化。
- classmethod apply(module, name)[源]#
Add pruning on the fly and reparametrization of a tensor.
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.
- apply_mask(module)[源]#
Simply handles the multiplication between the parameter being pruned and the generated mask.
Fetches the mask and the original tensor from the module and returns the pruned version of the tensor.
- 参数
module (nn.Module) – module containing the tensor to prune
- 返回
pruned version of the input tensor
- 返回类型
pruned_tensor (torch.Tensor)
- prune(t, default_mask=None, importance_scores=None)[源]#
Compute and returns a pruned version of input tensor
t
.According to the pruning rule specified in
compute_mask()
.- 参数
t (torch.Tensor) – 要剪枝的张量(维度与
default_mask
相同)。importance_scores (torch.Tensor) – 重要性分数张量(与
t
形状相同),用于计算剪枝t
的掩码。此张量中的值指示正在剪枝的t
中相应元素的 গুরুত্ব。如果未指定或为 None,则将使用张量t
本身。default_mask (torch.Tensor, optional) – 前一个剪枝迭代的掩码(如果有)。在确定剪枝应作用于张量的哪个部分时需要考虑。如果为 None,则默认为一个全为 1 的掩码。
- 返回
张量
t
的修剪版本。