torch.nn.utils.prune.random_structured
- torch.nn.utils.prune.random_structured(module, name, amount, dim)[源代码]
-
通过在指定维度上随机删除通道来修剪张量。
通过在指定维度
dim
上随机移除指定数量的(当前未被修剪的)通道,来修剪module
中名为name
的参数张量。此操作会就地修改模块,并返回修改后的模块。-
添加一个名为
name+'_mask'
的缓冲区,该缓冲区对应于剪枝方法应用于参数name
的二进制掩码。 -
将参数
name
替换为其修剪后的版本,而原始(未修剪)参数则存储在一个名为name+'_orig'
的新参数中。
- 参数
- 返回值
-
输入模块的修改版(即简化后的版本)
- 返回类型
-
模块(nn.Module)
示例
>>> m = prune.random_structured( ... nn.Linear(5, 3), 'weight', amount=3, dim=1 ... ) >>> columns_pruned = int(sum(torch.sum(m.weight, dim=0) == 0)) >>> print(columns_pruned) 3
-