Set requies_grad for all the networks. Args: nets (nn.Module | list[nn.Module]): A list of networks or a single network. requires_grad (bool): Whether the networks require gradients or not
(nets, requires_grad=False)
| 1 | def set_requires_grad(nets, requires_grad=False): |
| 2 | """Set requies_grad for all the networks. |
| 3 | |
| 4 | Args: |
| 5 | nets (nn.Module | list[nn.Module]): A list of networks or a single |
| 6 | network. |
| 7 | requires_grad (bool): Whether the networks require gradients or not |
| 8 | """ |
| 9 | if not isinstance(nets, list): |
| 10 | nets = [nets] |
| 11 | for net in nets: |
| 12 | if net is not None: |
| 13 | for param in net.parameters(): |
| 14 | param.requires_grad = requires_grad |
| 15 | |
| 16 | |
| 17 | def zero_module(module): |
no outgoing calls
no test coverage detected