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的修剪版本。