MCPcopy Create free account
hub / github.com/LeapLabTHU/DAT / LayerScale

Class LayerScale

models/dat.py:24–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23
24class LayerScale(nn.Module):
25
26 def __init__(self,
27 dim: int,
28 inplace: bool = False,
29 init_values: float = 1e-5):
30 super().__init__()
31 self.inplace = inplace
32 self.weight = nn.Parameter(torch.ones(dim) * init_values)
33
34 def forward(self, x):
35 if self.inplace:
36 return x.mul_(self.weight.view(-1, 1, 1))
37 else:
38 return x * self.weight.view(-1, 1, 1)
39
40class TransformerStage(nn.Module):
41

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected