MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS / _init_weights

Method _init_weights

models/modeling_moss.py:307–321  ·  view source on GitHub ↗

Initialize the weights.

(self, module)

Source from the content-addressed store, hash-verified

305 super().__init__(*inputs, **kwargs)
306
307 def _init_weights(self, module):
308 """Initialize the weights."""
309 if isinstance(module, (nn.Linear,)):
310 # Slightly different from Mesh Transformer JAX which uses truncated_normal for initialization
311 # cf https://github.com/pytorch/pytorch/pull/5617
312 module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
313 if module.bias is not None:
314 module.bias.data.zero_()
315 elif isinstance(module, nn.Embedding):
316 module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
317 if module.padding_idx is not None:
318 module.weight.data[module.padding_idx].zero_()
319 elif isinstance(module, nn.LayerNorm):
320 module.bias.data.zero_()
321 module.weight.data.fill_(1.0)
322
323 def _set_gradient_checkpointing(self, module, value=False):
324 if isinstance(module, MossModel):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected