MCPcopy Create free account
hub / github.com/PolymathicAI/AstroCLIP / _init_by_depth

Function _init_by_depth

astroclip/modules.py:341–348  ·  view source on GitHub ↗

Initialize the weights of a module based on the depth of the model.

(module: nn.Module, depth: int)

Source from the content-addressed store, hash-verified

339
340
341def _init_by_depth(module: nn.Module, depth: int) -> None:
342 """Initialize the weights of a module based on the depth of the model."""
343 if isinstance(module, nn.Linear):
344 fan_in = module.weight.size(-1)
345 std = 1 / math.sqrt(2 * fan_in * depth)
346 nn.init.trunc_normal_(module.weight, mean=0.0, std=std, a=-3 * std, b=3 * std)
347 if module.bias is not None:
348 nn.init.zeros_(module.bias)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected