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)
| 2144 | |
| 2145 | |
| 2146 | def prune_layer(layer, index, dim=None): |
| 2147 | """ Prune a Conv1D or nn.Linear layer (a model parameters) to keep only entries in index. |
| 2148 | Return the pruned layer as a new layer with requires_grad=True. |
| 2149 | Used to remove heads. |
| 2150 | """ |
| 2151 | if isinstance(layer, nn.Linear): |
| 2152 | return prune_linear_layer(layer, index, dim=0 if dim is None else dim) |
| 2153 | elif isinstance(layer, Conv1D): |
| 2154 | return prune_conv1d_layer(layer, index, dim=1 if dim is None else dim) |
| 2155 | else: |
| 2156 | raise ValueError("Can't prune layer of class {}".format(layer.__class__)) |
| 2157 | |
| 2158 | |
| 2159 | def apply_chunking_to_forward( |
nothing calls this directly
no test coverage detected