Recursively set the attribute of a module. Args: model (`torch.nn.Module`) The model to set the attribute in. module_name (`str`) The name of the module to set the attribute in. module (`torch.nn.Module`) The module to set the attr
(model, module_name, module)
| 21 | |
| 22 | |
| 23 | def recursive_setattr(model, module_name, module): |
| 24 | """ |
| 25 | Recursively set the attribute of a module. |
| 26 | Args: |
| 27 | model (`torch.nn.Module`) |
| 28 | The model to set the attribute in. |
| 29 | module_name (`str`) |
| 30 | The name of the module to set the attribute in. |
| 31 | module (`torch.nn.Module`) |
| 32 | The module to set the attribute to. |
| 33 | """ |
| 34 | split_list = module_name.split('.') |
| 35 | output = model |
| 36 | for name in split_list[:-1]: |
| 37 | output = getattr(output, name) |
| 38 | output.__setattr__(split_list[-1], module) |