(
fn: Callable,
module: nn.Module,
name: str = "",
depth_first: bool = True,
include_root: bool = False,
)
| 51 | |
| 52 | |
| 53 | def named_apply( |
| 54 | fn: Callable, |
| 55 | module: nn.Module, |
| 56 | name: str = "", |
| 57 | depth_first: bool = True, |
| 58 | include_root: bool = False, |
| 59 | ) -> nn.Module: |
| 60 | if not depth_first and include_root: |
| 61 | fn(module=module, name=name) |
| 62 | for child_name, child_module in module.named_children(): |
| 63 | child_name = ".".join((name, child_name)) if name else child_name |
| 64 | named_apply( |
| 65 | fn=fn, |
| 66 | module=child_module, |
| 67 | name=child_name, |
| 68 | depth_first=depth_first, |
| 69 | include_root=True, |
| 70 | ) |
| 71 | if depth_first and include_root: |
| 72 | fn(module=module, name=name) |
| 73 | return module |
| 74 | |
| 75 | |
| 76 | def fix_random_seeds(seed: int = 31): |
no outgoing calls
no test coverage detected