xnn.common.models.registry.replace_module#
- xnn.common.models.registry.replace_module(chain, old, new)[source]#
Replace
oldbynewinside a chain of wrappers linked by.model.- Parameters:
chain (torch.nn.Module) – The outermost module (
olditself, or a wrapper around it).old (torch.nn.Module) – The module to replace and its replacement.
new (torch.nn.Module) – The module to replace and its replacement.
- Returns:
newwhenchain is old, otherwisechainwith the replacement made in place.- Return type:
- Raises:
ValueError – If
oldis not in the chain.