MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / torch_dfs

Function torch_dfs

examples/community/stable_diffusion_reference.py:62–75  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

60
61
62def 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
78class StableDiffusionReferencePipeline(

Callers 1

__call__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected