r""" Performs a depth-first search on the given PyTorch model and returns a list of all its child modules. Args: model (torch.nn.Module): The PyTorch model to perform the depth-first search on. Returns: list: A list of all child modules of the given model.
(model: torch.nn.Module)
| 60 | |
| 61 | |
| 62 | def torch_dfs(model: torch.nn.Module): |
| 63 | r""" |
| 64 | Performs a depth-first search on the given PyTorch model and returns a list of all its child modules. |
| 65 | |
| 66 | Args: |
| 67 | model (torch.nn.Module): The PyTorch model to perform the depth-first search on. |
| 68 | |
| 69 | Returns: |
| 70 | list: A list of all child modules of the given model. |
| 71 | """ |
| 72 | result = [model] |
| 73 | for child in model.children(): |
| 74 | result += torch_dfs(child) |
| 75 | return result |
| 76 | |
| 77 | |
| 78 | class StableDiffusionReferencePipeline( |