Prune a Conv1D or nn.Linear layer (a model parameters) to keep only entries in index. Return the pruned layer as a new layer with requires_grad=True. Used to remove heads.
(layer, index, dim=None)
| 1193 | |
| 1194 | |
| 1195 | def prune_layer(layer, index, dim=None): |
| 1196 | """ Prune a Conv1D or nn.Linear layer (a model parameters) to keep only entries in index. |
| 1197 | Return the pruned layer as a new layer with requires_grad=True. |
| 1198 | Used to remove heads. |
| 1199 | """ |
| 1200 | if isinstance(layer, nn.Linear): |
| 1201 | return prune_linear_layer(layer, index, dim=0 if dim is None else dim) |
| 1202 | elif isinstance(layer, Conv1D): |
| 1203 | return prune_conv1d_layer(layer, index, dim=1 if dim is None else dim) |
| 1204 | else: |
| 1205 | raise ValueError("Can't prune layer of class {}".format(layer.__class__)) |
| 1206 | |
| 1207 | |
| 1208 | def apply_chunking_to_forward( |
nothing calls this directly
no test coverage detected