MCPcopy Create free account
hub / github.com/MiniMax-AI/VTP / named_apply

Function named_apply

vtp/models/utils/utils.py:53–73  ·  view source on GitHub ↗
(
    fn: Callable,
    module: nn.Module,
    name: str = "",
    depth_first: bool = True,
    include_root: bool = False,
)

Source from the content-addressed store, hash-verified

51
52
53def named_apply(
54 fn: Callable,
55 module: nn.Module,
56 name: str = "",
57 depth_first: bool = True,
58 include_root: bool = False,
59) -> nn.Module:
60 if not depth_first and include_root:
61 fn(module=module, name=name)
62 for child_name, child_module in module.named_children():
63 child_name = ".".join((name, child_name)) if name else child_name
64 named_apply(
65 fn=fn,
66 module=child_module,
67 name=child_name,
68 depth_first=depth_first,
69 include_root=True,
70 )
71 if depth_first and include_root:
72 fn(module=module, name=name)
73 return module
74
75
76def fix_random_seeds(seed: int = 31):

Callers 2

init_weightsMethod · 0.85
init_weightsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected