MCPcopy Create free account
hub / github.com/THUDM/LongWriter / RMSNorm

Class RMSNorm

train/patch/modeling_chatglm.py:157–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155
156
157class RMSNorm(torch.nn.Module):
158 def __init__(self, normalized_shape, eps=1e-5, device=None, dtype=None, **kwargs):
159 super().__init__()
160 self.weight = torch.nn.Parameter(torch.empty(normalized_shape, device=device, dtype=dtype))
161 self.eps = eps
162
163 def forward(self, hidden_states: torch.Tensor):
164 input_dtype = hidden_states.dtype
165 variance = hidden_states.to(torch.float32).pow(2).mean(-1, keepdim=True)
166 hidden_states = hidden_states * torch.rsqrt(variance + self.eps)
167
168 return (self.weight * hidden_states).to(input_dtype)
169
170
171class CoreAttention(torch.nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected