MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / torch_dfs

Function torch_dfs

diffusers/examples/community/stable_diffusion_reference.py:67–80  ·  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

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

Callers 1

__call__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected