Find all modules of a certain class (or union of classes). Returns all matching modules, along with the parent of those moduless and the names they are referenced by.
(
model,
search_class: List[Type[nn.Module]] = [nn.Linear],
)
| 215 | |
| 216 | |
| 217 | def _find_children( |
| 218 | model, |
| 219 | search_class: List[Type[nn.Module]] = [nn.Linear], |
| 220 | ): |
| 221 | """ |
| 222 | Find all modules of a certain class (or union of classes). |
| 223 | |
| 224 | Returns all matching modules, along with the parent of those moduless and the |
| 225 | names they are referenced by. |
| 226 | """ |
| 227 | # For each target find every linear_class module that isn't a child of a LoraInjectedLinear |
| 228 | for parent in model.modules(): |
| 229 | for name, module in parent.named_children(): |
| 230 | if any([isinstance(module, _class) for _class in search_class]): |
| 231 | yield parent, name, module |
| 232 | |
| 233 | |
| 234 | def _find_modules_v2( |
nothing calls this directly
no outgoing calls
no test coverage detected